473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CSS background-color inheritance not working on child DIV

132 100+
Hi guys,

I have an issue with a webpage which is not displaying as it should eventhough I don't see any mistake.

I have a series of divs which are all children from one parent div. The first div gets the backgroundcolor from the parent which it should, however, the second div doesn't get the backgroundcolor and I don't understand why?

Can someone explain what the problem is?

You can see the isolated html and css on http://jsfiddle.net/ucu8j6u6/

I removed any content which isn't readable to most of you and just replaced it with bla bla bla. You'll see the second line of blablabla... has a white background instead of the pink one I used to demonstrate what I wanted to do.

If someone can explain me what the problem is, that would be great.
Oct 13 '14 #1

✓ answered by Exequiel

put this html tag after the </div>(close) for your 2nd itemDetail and before the closing tag for the parent div itemHeader color1 class.
Expand|Select|Wrap|Line Numbers
  1. <div class="continue"></div>
  2.  
then copy paste this css
Expand|Select|Wrap|Line Numbers
  1. .continue{clear:both;}
we used that code for continue for us to see the entire parent element. because the floating elements affects the parent and the parent's height does not automatically viewed, so we used continue{clear:both;} to automatically set the height for the parent element or div.

by the way no need to remove the float: left;.

3 6557
iam_clint
1,208 Expert 1GB
Floated elements do not inherit from the parent. Remove all the float: left; and you will see it inheriting properly. You will have to specify the color on each one if float is needed.

you can inherit the background in each itemclass
background-color: inherit;
Oct 13 '14 #2
Cainnech
132 100+
Ah, I see.
Is there a specific explanation why floated elements can't inherit from their parent? Because they do have a parent?

And one thing I don't fully understand yet. How come the first subdiv does take the background color but the second one doesn't? They are both floated?
Oct 13 '14 #3
Exequiel
288 256MB
put this html tag after the </div>(close) for your 2nd itemDetail and before the closing tag for the parent div itemHeader color1 class.
Expand|Select|Wrap|Line Numbers
  1. <div class="continue"></div>
  2.  
then copy paste this css
Expand|Select|Wrap|Line Numbers
  1. .continue{clear:both;}
we used that code for continue for us to see the entire parent element. because the floating elements affects the parent and the parent's height does not automatically viewed, so we used continue{clear:both;} to automatically set the height for the parent element or div.

by the way no need to remove the float: left;.
Oct 14 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
4
by: Peter Hamilton | last post by:
I am trying to implement inheritance but I am having a difficult time with some concepts. What I am trying to do is have a Child object inherit from the Parent, and when you set a property value...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
10
by: John | last post by:
Hi, How can I achieve that a childs constructor is only callable from it's parent? Must I declare the class Private within A? Thanks in Advance Public MustInherit Class A Protected Sub...
3
by: Saumitra | last post by:
Hi I am new to VB.NET and I am trying to figure out how to exchange data between 2 forms based on parent-child relationship between 2 forms. Form2 is child of form1. In form1.vb, I am doing Dim t...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
9
by: julian_m | last post by:
Incredibly, this function works as expected in IE (changing the div_id's color after every click) , whereas it only changes div_id's color once function colorDiv(div_id) { if...
3
by: rlueneberg | last post by:
I want to change the color of an "a" child element inside a table cell via javascript. Is there any way to do that? Ps: there is no id assigned to child elements. I would like to discover the child...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.