I have two divs which have background images and I would like to add margin to the the 2nd div but it is creating white space.
How can I add a top margin while keeping the div inside the other div?
<div class="background">
<div class="logo">
</div>
</div>
.logo {
background-image: url(image/logo2.png);
height:40px;
width:400px;
margin-left:100px;
display:block;
margin-top:20px;
}
.background {
background-image: url(image/empback.png);
width:100%;
height:94px;
min-width:1345px;
}
To move the inner div container to the centre of the parent div we have to use the margin property of style attribute. We can adjust the space around any HTML element by this margin property just by providing desired values to it.
div s are used to create what used to be known as layers, and can be used as a replacement for tabled layout. We get down to that fully in CSS Layout. Default margins, borders and padding are all 0, so when you wrap a div around some text, there is no space between its edges and the text.
In order an element to appear in front of another you have to give higher z-index to the front element, and lower z-index to the back element, also you should indicate position: absolute/fixed... Save this answer.
The <span> tag is a inline element, it fits into the flow of the content and can be distributed over multiple lines. We can not specify a height or width or surround it with a margin.
You can use overflow: auto
on the parent element
.background{
background: #f00;
width:100%;
height:94px;
min-width:1345px;
overflow: auto;
}
Demo
Just got a link to share which is related to this issue.
Also, a better approach towards this is instead of using position: absolute;
you should use position: relative;
with top
, left
, right
and bottom
properties, which will not only keep the element in float, it will also save you from positioning other elements in the same block.
Demo 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With