Reputation: 73
Hey guys I am trying to set a background color in a div tag, however nothing is happening. I feel like it is I have a floating element in my div, however I do not of have any way to solve it.
HTML
<div id='footer'>
<h5>©Krish International Inc.
</h5>
</div>
CSS
#footer {
background-color: deepskyblue;
}
h5 {
font-weight: normal;
position: absolute;
width: 100%;
text-align: center;
font-size: 30px;
font-family: 'hind';
@font-face {
font-family: 'hind';
src: url('C:/Users/lakes/Desktop/hind2.ttf')
}
Upvotes: 2
Views: 1001
Reputation: 4192
Why you are using position:absolute;
when you simply get it by following approach.
If you need to use position
that parent div did't get height by default until you not give. because when we use the position: absolute
div or tag come out of the flow.
#footer {
background-color: deepskyblue;
width: 100%;
}
h5 {
font-weight: normal;
/* position: absolute; */
width: 100%;
display: block;
text-align: center;
font-size: 30px;
font-family: 'hind';
@font-face {
font-family: 'hind';
src: url('C:/Users/lakes/Desktop/hind2.ttf')
}
<div id='footer'>
<h5>©Krish International Inc.
</h5>
</div>
Upvotes: 1
Reputation: 12951
about position:absolute
:
When set to absolute or fixed, the element is removed completely from the normal flow of the document.
cause:
h2
have positionabsolute
so removed completely from the normal flow of the document and#footer
getheight:0
Fix:
You must define
height
ormin-height
for#footer
.
#footer {
background-color: deepskyblue;
height: 100px;<------------Added
//Or min-height:100px;
}
#footer {
background-color: deepskyblue;;
height: 100px;
}
h5 {
font-weight: normal;
position: absolute;
width: 100%;
text-align: center;
font-size: 30px;
font-family: 'hind';
}
@font-face {
font-family: 'hind';
src: url('C:/Users/lakes/Desktop/hind2.ttf')
}
<div id="footer">
<h5>©Krish International Inc.
</h5>
</div>
Upvotes: 0