0

Following HTML, displays a picture in the background and text nhs subscription written over it. Now when I give class="nhs_head" margin-top text along with image moves down. Why is it so ?

How can I just give text the margin ?

<body>
<div class="image_holder"> 
    <div class="nhs_head"> NHS SUBSCRIPTION </div>       
</div>
</body>

CSS:

    .image_holder {
       position:relative;
       background-image:url(bg2.jpg);
       height:768px;
       width:1366px;
    }

.nhs_head {
    display:block;
    width:60%;
    margin:0 auto;
    border:2px solid white;
    font-family:Calibri;
    font-weight:800;
    font-size:30px;
    color:white;
}
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

1 Answers1

0

Demo

If you want to apply margin-top to text you can position absolute the text in relatively positioned image div.

css

body, html {
    margin:0;
}
.image_holder {
    position: relative;
    background-image:url('http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg');
    height:768px;
    width:1366px;
}
.nhs_head {
    width:60%;
    margin:0 auto;
    border:2px solid white;
    font-family:Calibri;
    font-weight:800;
    font-size:30px;
    margin-top: 30px;
    color:white;
    position: absolute;
    left:0;
    right:0;
    margin-top: 30px;
}
4dgaurav
  • 11,360
  • 4
  • 32
  • 59