Numpty CSS question
Jan. 24th, 2011 09:44 pmApologies for any stupidity of question... me and CSS still don't get on.
I have defined myself two nice <div>elephants elements, each of which will take up about half the screen.
Now I just need to persuade my stylesheet to help me put them next to each other rather than one below the other.
The ideal answer will not involve tables :) Does anyone know what I should be looking at doing?
I have defined myself two nice <div>
Now I just need to persuade my stylesheet to help me put them next to each other rather than one below the other.
The ideal answer will not involve tables :) Does anyone know what I should be looking at doing?
no subject
Date: 2011-01-24 09:59 pm (UTC)(Possibly not helpful, but it does work. I stopped understanding HTML about the time style sheets got really cool. There's probably some whizzo style sheet element that will do what you want, but I have no idea how to do it.)
no subject
Date: 2011-01-24 10:08 pm (UTC)no subject
Date: 2011-01-24 10:18 pm (UTC)Short answer: use float.
Long answer: if you want to do something more cunning (having both columns the same height regardless of their content, for example), you could do worse than look at these CSS layout templates.
no subject
Date: 2011-01-24 10:23 pm (UTC)Thanks very much - it seems to be Just Working surprisingly nicely!
no subject
Date: 2011-01-24 11:36 pm (UTC)no subject
Date: 2011-01-24 11:53 pm (UTC)It initially did not (I had totally forgotten to check until you reminded me, thank you) but that turned out to be valid behaviour on IE's part. FF was being a lot more tolerant of a missing > and doing what I meant; IE did what I said (unusually).
no subject
Date: 2011-01-24 10:22 pm (UTC)display: inline; width: 50%;, I think.Don't use tables unless it's tabular data.
One day, maybe, I will understand how
floatworks.no subject
Date: 2011-01-24 10:59 pm (UTC)I know of two ways to use float, based on having had to re-learn it (or more accurately at first re-cargo-cult it) about once every 2-3 years.
In the first you only float a single div; everything else "flows" past, on the right if you used float:left and on the left if you used float:right. Once the everything-else has got past the float it'll use the full width. To guarantee an element sits below the float make it clear:left (or clear:right).
In the second, you make div.left be float:left and div.right be float:right. Provided their combined width does not exceed the width of their container they will sit next to other (otherwise they will sit on top of one another).
You need to set clear:both on the element after them to ensure it stays below them both rather than trying to fit between them.
In both cases, if a floated element can take up the full width of the parent it will do so, voiding your attempts at formatting. So you need to set width explicitly. This is a nasty trap which has caught me more than once: if you take what you see in a tutorial and try and isolate down to the bits that look important - float and clear - it all stops working.
http://www.greenend.org.uk/rjk/2011/float.html what I did while confirming my understanding, in reverse order of the above.
no subject
Date: 2011-01-24 11:39 pm (UTC)Having solved my original problem, I've now moved onto something where I suspect I actually genuinely do want a damn table :)
no subject
Date: 2011-01-25 09:53 pm (UTC)I spent several days trying to achieve an incredibly simple effect on my web site (text vertically centred in a box). Once I had reached a page and a half of complicated CSS and it still didn't work on some browsers, I Gave Up And Used Tables, and then it actually worked.
no subject
Date: 2011-01-24 11:35 pm (UTC)The thing I am floating is, as it happens, a box repeating the last n tweets from a particular twitter account. Accordingly it will change size depending on how verbose[*] I have been of late, so absolute positioning might well not help me here.
[*] In so far as one can do verbosity on twitter.
no subject
Date: 2011-01-25 12:19 pm (UTC)no subject
Date: 2011-01-26 10:25 am (UTC)Unless they should have used doubles.
Or a decimal type.
no subject
Date: 2011-01-25 08:49 am (UTC)Position absolute would be great if all users' windows were the same size, but sadly they aren't -- even less so in this modern age of smartphones and the like. You can end up with a real mess of overlapping content. Sticking to floats means that you can always make sure container sizes fall back to percentages.