Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does background-color have no effect on this DIV?

Tags:

html

css

<div style="background-color:black" onmouseover="this.bgColor='white'">     <div style="float:left">hello</div>     <div style="float:right">world</div> </div> 

Why does the background color not show as black? I cannot set the width and float, is it possible without them?

like image 767
Alec Smart Avatar asked Jun 03 '09 13:06

Alec Smart


People also ask

Why my background color in HTML is not working?

Check the network tab to make sure Stylesheets/main. css is getting loaded. Check the style inspector to make sure background-color is not being overridden. You might want to include your stylesheet after bootstrap.

Why background image is not working in div?

You need to make sure that it is showing up first. You may have an error in your code where you do not have the same amount of opening div tags as you do closing div tags, thus it won't actually display your centerBar2 div. Are you sure your image is in the right directory, properly named, etc.?

Can a div have a background color?

The default background color of a div is transparent . So if you do not specify the background-color of a div, it will display that of its parent element.


1 Answers

Since the outer div only contains floated divs, it renders with 0 height. Either give it a height or set its overflow to hidden.

like image 58
Lobstrosity Avatar answered Oct 10 '22 02:10

Lobstrosity