html - Image overlapping text and logo not centering on top of image -
my header image overlapping text , annoying me. thing buggy how logo text leans right of center of image. if me both awesome.
here code: https://jsfiddle.net/c2bom0cc/1/
here tags relevant this:
#index_header { position: block; z-index: 0; left: 0; top: 0; height: 100%; width: 100%; text-align: center; vertical-align: middle; } #index_header img { position: block; float: left; width: 100%; height: 100%; } .background_title { position: absolute; font-family: 'montserrat', sans-serif; color: #fff; font-size: 64px; left: 50%; top: 50%; }
<div class="page_container"> <div id="index_header"> <a href="#"> <img alt="slider" id="index_headerimg" src="http://www.bakeryandsnacks.com/var/plain_site/storage/images/publications/food-beverage-nutrition/bakeryandsnacks.com/regulation-safety/coles-freshly-baked-claims-false-rules-federal-court-australia/9101085-1-eng-gb/coles-freshly-baked-claims-false-rules-federal-court-australia.jpg" /> <p class="background_title">g.f. bakery</p> </a> </div> </div>
i let myself hold few assumptions on code:
first, full height , width of image, figured want image stretched background image. replaced <img>
background-image
(background
shorthand) in css backgrounds.
from question see want title in center of bakery background.
i did not text overlapped image. if want text below image, please put in element after <div id="index_header">...</div>
, background on <div>
.
i had add display:inline-block
.background_title
class, vertical-align:middle;
take effect.
i removed absolute positioning handle better alignments. absolute positioning make manually set top
, left
, , it's difficult when code gets bigger.
here's new html:
<div class="page_container"> <div id="index_header"> <a href="#"> <p class="background_title">g.f. bakery</p> </a> </div> <p>some other content...</p> // text not overlapped // #index_header long #index_header // isn't absolutely positioned </div>
here's new css:
html, body{ // instead of having top:0 , left:0 in #index_header padding: 0; margin: 0; } .page_container { height: 100%; width: 100%; } #index_header { height: 200px; width: 100%; text-align: center; vertical-align: middle; background: url('http://www.bakeryandsnacks.com/var/plain_site/storage/images/publications/food-beverage-nutrition/bakeryandsnacks.com/regulation-safety/coles-freshly-baked-claims-false-rules-federal-court-australia/9101085-1-eng-gb/coles-freshly-baked-claims-false-rules-federal-court-australia.jpg') no-repeat center center; background-size: 100% 100%; // stretching } .background_title { display:inline-block; // apply vertical-align of parent font-family: 'montserrat', sans-serif; color: #fff; font-size: 64px; }
here's jsfiddle
hope helps.
Comments
Post a Comment