0

There are my codes. (jsfiddle) Why this part of my codes isn't running?

header{background-color: #2bd5ec;}

I want to add background color to header tag. What i need to do?

4

5 に答える 5

1

ヘッダーの高さを設定できます。例えば ​​:

header{background-color: red; height:100px;}

そして、あなたはこのように「クリア」を使うことができます:

 <header>
     <div id="info">
         <h1>Oyunn.in</h1>
     </div>
     <div id="categories">
         <p>Barbie - Benten - Senten</p>
     </div>
     <br clear="all"/>
</header>​

およびcss:

header{background-color: #2bd5ec;}
#info{float: left;}
#info h1{font-size: 100%;margin: 0;}
#categories{float: right;}
#categories p{margin:0;}​
于 2012-09-05T10:25:31.953 に答える
1

The issue here is that since the elements inside your header are floated, they're considered in a different flow than your header, and thus it doesn't resize to fit them.

One way to fix this is to append <div style = "clear: both;"></div> to your header; little demo: little link.

You can also just add overflow: hidden; to your header: another little link, or float it as well: yet another little link.

于 2012-09-05T10:22:42.723 に答える
0

追加

header{background-color: #2bd5ec;width:100%; height:30px;}

背景属性には通常、divのディメンションが必要です

于 2012-09-05T10:21:46.980 に答える
0

use overflow:hidden

header{background-color: #2bd5ec; overflow:hidden;}

The overflow CSS property specifies whether to clip content, render scroll bars or display overflow content of a block-level element.

Using the overflow property with a value different than visible, its default, will create a new block formatting context. This is technically necessary as if a float would intersect with the scrolling element it would force to rewrap the content of the scrollable element around intruding floats. The rewrap would happen after each scroll step and would be lead to a far too slow scrolling experience. Note that, by programmatically setting scrollTop to the relevant HTML element, even when overflow has the hidden value an element may need to scroll.

The overflow declaration tells the browser what to do with content that doesn't fit in a box. This assumes the box has a height: if it doesn't, it becomes as high as necessary to contain its contents, and the overflow declaration is useless.

SEE DEMO

于 2012-09-05T10:23:22.153 に答える
0

actually you didn't clear your child floats so whenever we are using float so we should clear the floats and we can give overflow: hidden; in our parent div to clearing the child floated div's.

header {
    background-color: #2BD5EC;
    overflow: hidden;
}

see the demo:- http://jsfiddle.net/vE8rd/17/

于 2012-09-05T10:26:57.667 に答える