mr_tuition — 2011-06-18T09:58:39-04:00 — #1
I'm not sure why, but my inner divs arent inheriting the background colour of my wrapper divs
The basic design of the site is
<div class="centerbody"> // my wrapper div
/// rest of site
I have css for the body and for the wrapper:
background:none repeat scroll 0 0 #EFEFEF;
background:none repeat scroll 0 0 #BFBFBF;
border: 0px none; margin-left: auto; margin-right: auto;
I've also tried using an id of centerbody, and defining #centerbody in the css, this didnt work
I've also tried using background-color: #BFBFBF; (for centerbody) and this didnt work
I just cant figure out why the child divs are only inheriting the body background, but not the parent div centerbody background, any ideas?
- and if I delete the body class, the child divs dont inherit any background colour at all
(example here: rightsfortenants.co.uk)
ralphm — 2011-06-18T10:46:29-04:00 — #2
Add the line in red to your CSS, and be amazed:
background: none repeat scroll 0 0 #BFBFBF;
border: 0 none;
<font color='"Red"'>overflow: hidden;</font>
By default, a container does not wrap around floated contents. So your #centrebody div has zero height. One of the ways to make it wrap around its contents is with overflow: hidden, which forces it to look at what's inside it and then enclose it. In a few circumesatances (such as when you purposely want something hanging out of the container) a different method is needed, but this solution works in most cases.
mr_tuition — 2011-06-18T11:20:26-04:00 — #3
I would never have thought that would have worked, but you are indeed right.
Since it's a wrapper, I really couldnt define a height (the size of all of the child elements can differ). Also, most of the child elements are floated, but I didnt think this would prevent inheritance...
Thanks Ralph (I think I'll be reading your webdesign tips)
ralphm — 2011-06-18T11:28:20-04:00 — #4
Glad that helped.
I didn't pick you up on this before, but be careful of the word 'inheritance', as it really has a specific meaning in CSS that I don't think you mean. Background color is not inherited by child elements. The wrapper has a background color, and that's it. If the children are transparent, then you'll see the background color behind them, but if the children have their own (solid) background color, the wrapper's background color will be hidden.
In CSS, 'inheritance' means that if a container has a style set on it, that style is also transferred to the children. Here's a link that will explain it way better than I can:
You won't find much on my site, as I haven't had time to add to it for so long. Must get around to that.
paulob — 2011-06-18T11:29:46-04:00 — #5
Backgrounds aren't inherited anyway You see a background because the default value for a background is transparent and that's why you see the background underneath the element you just placed.
If background was inherited you would then define an image on the body and then every single image on the page would have a background. That wouldn't be much use lol
Only certain properties are inherited like font-size, font-family, color etc. You can find out which are inherited by default and which aren't via the reference here.
As Ralph said the wrapper simply had no height because it only had floated children and therefore nothing would show.
system — 2011-06-18T14:47:18-04:00 — #6
1) As Paul said, Div's don't inherit backgrounds by default.
2) None also means no color, which you then declare -- that doesn't even make sense.
3) yeah, that looks like a lack of float clearing.
... though looking at the overblown over the top number of pointless DIV and classes in the markup (as I've come to call it, borrowing from Carlin "not every ejaculation deserves a name"), useless "gee ain't it neat" scripting, non-semantic markup with nonsensical heading orders, accessibility train wreck of absurdly undersized fixed metric fonts, endless IE conditional hacks for NOTHING (If you have to target EVERY version of IE individually... there's something HORRIBLY wrong with how the site is built!)... I mean, 12k of markup for 1.5k of plaintext and four content images -- somethings gone awry.
I would advise throwing away that mess entirely... building with actual semantic markup with meaningful heading orders, (every h# becoming h1 in HTML 5 only applies if you use section/article! -- you've got 4 tranny with a 5 slapped on it), accessible forms, and in general trading all the "gee ain't it neat" animated nonsense for general accessibility improvements and simplification of the page.
That 134k total page size basically doing 40k's job...
mr_tuition — 2011-06-18T21:25:47-04:00 — #7
Mummy... he kicked my sand castle over
... yeah, not really worth changing everything, 90K is not very much in the grand scheme of things (its still in dev, so a lot of this is old css, script that I no longer need).
Divs are just easier to go back and re-use, I'm sure it could be done with a lot less, but I really dont have that much life to waste (today )
I'm redesigning it, but not throwing it all away (that green slidy thing its quite tacky though, I have to agree with that... its gone)
Thanks people for your input
paulob — 2011-06-19T04:42:34-04:00 — #8
lol - It happens to us all
richardbrown360 — 2011-07-13T04:54:57-04:00 — #9
Hi I have read a fair few of these types of posts but have the same problem with my site.
I've tried to add overflow;hidden ect.
I'll just show my CSS:
(just so you know this is my first attempt at writting any CSS)
border: 3px solid #a30d0d;
font-family:Calibri, Verdana, sans-serif;
margin: 0 auto;
ralphm — 2011-07-13T05:01:55-04:00 — #10
Hi richardbrown360. You haven't really explained what your problem is. It might be best to start a new thread with a clear explanation of what you are attempting,preferably with a link to your site.
system — 2014-10-07T21:16:39-04:00 — #11
This topic is now closed. New replies are no longer allowed.