How to position text in a div with left and right areas
This CSS script give you absolute pixel-exact control of where to place text in a left and right area of a wide div, e.g. a header or footer. I was not able to get it to align automatically, e.g. left/center/right, so you have to know your font size and your text and position things exactly, but at least you have control, checked in Firefox and Explorer.
patryksharks321: nice code
btw relative is according to the last element and absolute is towards the block it's in right?
greetings
This CSS example shows a simple UL/LI menu absolutely positioned top/left and a line-height of 1em and the body pushes the container div down 1em so that you can expand the font (ctrl-+) and the menu stays relatively sized to the content of the site. Ok, I'm starting to see how if you set even the amount of space between screen objects to the same unit (em) as the font then you have a flexible layout that someone with poor eyesite can just zoom in (I wonder if you could have your graphics expand as well). This is also cool because in the body tag you have font-size: 94% and if you change this then everything stays in proportion as well. Here is a live example.
I have always wondered why background images never worked when specified in the CSS file but DID work when specified inline in the HTML tag. The reason is that you have to define the path of the image relative to the position of the CSS file to the image, and inline definitions use the path relative to the position of the HTML file to the image. Nice to know.
SHOW CODESHOW CODE
Patrick Wright: IIRC, this is how
CSS Zen Garden handles its magic--each CSS is in its own location and pulls in its own background images relative to the CSS file, which allows the main XHTML file to remain unchanged. We actually missed that aspect of the CSS spec early on in developing our rendering tool. Cheers!
Edward: Thanks for reminding me to go back to CSS Garden and humble myself, that site is so impressive. When I look at the designs with Firefox and Explorer 7 they look exactly the same, I wonder how they look on Explorer 5.0 for mac and Netscape 4 etc. I wonder if you are allowed to use hacks or if it is a purity contest.
So finally a form without HTML tables, finally got all the floats: left, right, clear both etc. correct. I have this pretty fixed to a certain size just because I don't like my forms being stretched across the page as the browser area grows (would be ok if the font sizes also grew but they don't so it's just a design integrity issue), if you want this ability (better for expanding the size of the font) just change most of the px values (especially for width and margin) to percent values and your form will stretch as needed. VIEW EXAMPLE HERE.
Here is a HTML/CSS site layout with no tables, tested in IE7/Firefox, hover menu without graphics and a modular design so you can add components in the two columns as you wish. VIEW EXAMPLE HERE.
SHOW CODESHOW CODE
Patrick Wright: Hi Ed--when I come across CSS samples like this, I usually want to see them in use immediately--if you had a link to the page itself that I could clck on to see the effect that would be great. Cheers, Patrick
Edward: Excellent idea, for now I put a VIEW EXAMPLE HERE link is above. I have planned to make layout examples automatically have thumbnail examples and links to full examples, just not programmed yet. Thanks.
replyreply
sgt: Thanks for posting great tips and code snippets that can save some effort for beginners.
This layout has two columns with a dividing line in the middle (bug: which only goes down to the bottom if MORE content is on the left side than on the right side) and it is filled with rounded boxes with various colored headers, all done without graphics, which is very nice. This would be good code to get into presentation objects so these things are very easy to make and drag- and droppable.
This was my first fully non-table column-layout in CSS that I am satisfied with, note that if you put the width of the body_wrapper to 100% it will also work but a user can scrunch the whole site back to the left, which isn't really desirable, and min_width can't really be relied upon from my experience but that my be a solution, a solid px width works well though, with this layout you just have to be sure that your graphics are less wide than your column widths or they will hang over into the next column, unlike the nice feature of tables where the column expands to the width of the widest graphic. See the example here.