Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > CSS Inline/Block Positioning

CSS Inline/Block Positioning
Thread Tools
macgyvr64
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Sep 7, 2006, 12:08 AM
 
I've got what might be a simple question about positioning elements using CSS...

Is it possible to position an element somewhere relative to it's parent (in markup) and not have the space or hole left where the element "started out"? And does the solution work when inline and block items are beside each other?

Essentially, I'm putting an <img> right next to some text, and would like to move the image to the far left of the containing <div> (a table header with a sortable ascending/descending triangle image). I can move it there, but the text still acts as though the element is right beside it, and moves down.

Am I doing something wrong by putting the two different elements beside each other, or is there some dont-actually-occupy-space CSS attribute I'm unaware of? ;-)
     
Obi Wan's Ghost
Baninated
Join Date: Apr 2005
Location: An asteroid remanent of Tatooine.
Status: Offline
Reply With Quote
Sep 7, 2006, 12:21 AM
 
You show example. Me fix.
     
registered_user
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Sep 7, 2006, 07:10 AM
 
There are two common CSS properties that remove an element from the document flow: position: absolute; and float: left;

If you choose position: absolute; make sure that the element's parent is position: something; Absolutely positioned elements are positioned according to their first parent that has its position specifically declared. position: relative is popular for use in parents like this.

float: left; will let text flow around the right side of your image, it might do what you're asking.

That all having been said, you may be just having trouble with vertical-align on your div. That's worth playing with too.
     
Obi Wan's Ghost
Baninated
Join Date: Apr 2005
Location: An asteroid remanent of Tatooine.
Status: Offline
Reply With Quote
Sep 7, 2006, 07:31 AM
 
Originally Posted by registered_user
float: left; will let text flow around the right side of your image, it might do what you're asking.
It is the best way to do it without messing around with position elements.

Try this in your stylesheet

.imgalignleft {display:block; float:left; margin:5px}
.imgalignright {display:block; float:right; margin:5px}

Simply apply the correct class to the image you want to align left or right.
     
registered_user
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Sep 7, 2006, 08:51 PM
 
Originally Posted by Obi Wan's Ghost
It is the best way to do it without messing around with position elements.
Why?
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:57 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,