Image overlapping text and logo not centering on top of image - html

My header image is overlapping my text and it is very much annoying me. Another thing that is buggy is how my logo text leans right of the center of the image. If someone could help me with both that would be awesome.
Here is my code:
https://jsfiddle.net/c2bom0cc/1/
Here are my tags that are probably the most relevant to 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 a few assumptions on your code:
First, by the full height and width of the image, I figured that you want the image as a stretched background image. So I replaced the <img> with background-image (background shorthand) in CSS Backgrounds.
From your question I see that you want the title in the center of the bakery background.
I did not get what text is overlapped by the image.
If you want text below the image, please put it in an element after <div id="index_header">...</div>, as the background is all over that <div>.
I had to add display:inline-block to .background_title class, so that the vertical-align:middle; would take effect.
I removed all the absolute positioning to handle better with all the alignments.
Absolute positioning make you manually set all the top and left, and it's really difficult to do when your code gets bigger.
Here's you 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> // this text will not be overlapped by
// #index_header as long as #index_header
// isn't absolutely positioned
</div>
Here's your new CSS:
html, body{ // this is instead of having top:0 and 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%; // this does the stretching
}
.background_title {
display:inline-block; // this is to apply the vertical-align of parent
font-family: 'Montserrat', sans-serif;
color: #FFF;
font-size: 64px;
}
Here's a JSFiddle
Hope this helps.

If you want your text to be under your image and centered, remove the following code:
.background_title {
position: absolute;
}
Just removing the position will move your text under your image and centered.

Related

Center text on middle of a banner?

How do I create a banner and center text on the middle of it?
I have tried to use relative position on Wrapper and absolute on the image div but couldn't position.
#banner {
position: relative;
width: auto;
}
#banner_wrap img {
position: absolute;
top: 150px;
left: 50px;
}
<div id="banner">
<div id="banner_wrap">
<img src="fe_bg_login_.png" />
<div id="rockstar">
<h1>I am a Rock Star Dude!</h1>
</div>
</div>
</div>
You can use text-align: center; to do that.
JSFiddle to see it.
I think this is what you're looking for:
h1 {
text-align: center;
}
text-align: center; property could let you do that.
#banner {
position: relative;
width: auto;
background: #333; color: #fff;
text-align :center;
}
The image in absolute position will not be centered if you use text-align: center in the banner, that's why I removed that absolute position and put it after the heading to get the same behavior.
Fiddle
Source :
https://developer.mozilla.org/en-US/docs/Web/CSS/text-align

Centering div inside another div and on image

I am trying to create a one page website. The idea is to have a div for each image (using bootstrap). This will create the back ground image for the div. Then I want to place another div on where I can place text and other images in. I managed to get it to work using the position from the top but I want to use dimensions relative to the divs so that when it is displayed on a smaller screen the content in the center div is still center and set to the appropriate size.
Here is the div:
<div class="row" id="homeRow">
<img id="homeImage" src="imageSource" alt="Example">
<div class="col-md-8 col-md-offset-2" id="homeTitle">
<img src="headingSource" alt="Handwriting Fonts">
<h3>Some content</h3>
</div>
</div>
There are three of these in on the page. My css at the moment looks like this:
#homeRow{
height: 800px;
width: 100%;
color: white;
overflow:hidden;
}
#homeImage{
width: 100%;
position: relative;
-webkit-filter:brightness(60%);
-moz-filter:brightness(60%);
filter: url(#brightness);
filter:brightness(60%);
}
#homeTitle{
position: absolute;
top: 300px;
width: 50%;
font-family: Verdana, Geneva, sans-serif;
}
So I am looking for a solution that where I will be able to position everything inside of the row div relative to the row div.
#homeRow{
height: 800px;
width: 100%;
color: white;
overflow:hidden;
position: relative;
}
#homeImage{
width: 100%;
position: relative;
-webkit-filter:brightness(60%);
-moz-filter:brightness(60%);
filter: url(#brightness);
filter:brightness(60%);
}
#homeTitle{
position: absolute;
top: 50%;
width: 50%;
left: 50%;
font-family: Verdana, Geneva, sans-serif;
}
Try using this CSS. You can use position relative for outer div and for inside position absolute.
#homerow{
...
position: relative; // add this
}
#homeTitle{
...
//width:50% - remove this
left:25%; // add this
right:25%; // add this
// those left and right will make width 50% and centered
}
Example: https://jsbin.com/savaqoputo/edit?html,output

Place text centrally over image

I'd like to place my H2 text vertically & horizontally center over my image.
Can someone explain how I do this?
https://jsfiddle.net/q3odxfmb/
<div class="content">
<img src="http://placehold.it/940x510">
<h2>
TEXT WILL GO HERE
</h2>
</div>
fiddlehttps://jsfiddle.net/q3odxfmb/1/
img {
max-width: 100%;
vertical-align: middle;
}
#container {
position: relative;
}
#text-outer {
height: 100%;
margin-left: 12.5%;
position: absolute;
top: 0;
width: 75%;
}
#text-inner {
color: #fff;
position: absolute;
text-align: center;
top: 50%;
transform: translateY(-50%);
width: 100%;
}
this question already asked so many times please refer this link
thank you all
Text Above Image CSS Z-Index Not Working
It's quite easy. Simply set css to:
.h2 {
line-height:/*height of your image*/
}
Then set the margin in the div to auto:
div {
background-url: <image-link>;
margin:auto
}
This should center it perfectly.
You would have to have a small margin set for this method.
Here is a JSBin with an easy method, too:
https://jsbin.com/vawowebolu/edit?html,css,js,output
set the text as a background over a div, and center the text over the div.
HTML:
<div class="content">
<h2 id="mytext">
TEXT WILL GO HERE
</h2>
</div>
CSS:
div {
background: url("<image-link>")
}
#mytext {
line-height: 510px;
vertical-align:middle;
text-align: center;
}

Why won't my text align over the centre of the image?

I'm trying to align my header text in the middle of the page, over the image. The image is aligned in the centre, but the text is to the left of the page.
I tried to copy this solution, but I'm obviously not doing something right. Any help would be really appreciated.
HTML:
<header>
<div class="tag">
<h1>Some text here</h1>
<h3>And more text here</h3>
</div>
<img src="http://www.placehold.it/900x300">
</header>
CSS:
header {
height: 200px;
line-height: 50px;
text-align: center;
background: #303e49;
position: relative;
}
.tag {
text-align: center;
background: #303e49;
position: absolute;
}
1st you shouldn't tagged jquery cause its css
2nd add left 0 and right 0 to your absolute element to get the full width of the contain div
.tag {
text-align: center;
background: #303e49;
position: absolute;
left: 0;
right: 0;
z-index : 1;
}

how do I align an image between text?

So I've been working on a page with text and an image. However, I can't find a way to put the image between the text. either it stays on the top left, or it only centers horizontally. here is the code that is of importance:
<style>
body {
margin: 0;
background-image: url("rainbowbg.png");
}
div #hype {
margin-left: auto;
margin-right: auto;
display: block;
positon: relative;
}
#hypetop {
position: fixed;
top: 0;
width: 100%;
}
#hypebot {
position: fixed;
bottom: 0;
width: 100%;
}
.hypetext {
font-family: Impact, Charcoal, sans-serif;
font-size: 64px;
text-align: center;
}
</style>
<body>
<div>
<h1 class="hypetext" id="hypetop">DIRE</h1>
<img id="hype" src="DIREHYPE.png" width="224" height="224">
<h1 class="hypetext" id="hypebot">HYPPPPPPPPPPPE</h1>
</div>
</body>
If anyone knows how I could get the image centered between the text, that would be great.
You can use this responsive css code. It may be help for you. Try it.I can change only position:fixed to position:relative.
Live Working Demo
HTML Code:
<div>
<h1 class="hypetext" id="hypetop">DIRE</h1>
<img id="hype" src="http://s30.postimg.org/qnju89rkx/banner.png" width="224" height="224"/>
<h1 class="hypetext" id="hypebot">HYPPPPPPPPPPPE</h1>
</div>
CSS Code:
body {
margin: 0;
background-image: url("rainbowbg.png");
}
div #hype {
margin:auto;
display: block;
position: relative;
margin-top:50px;
}
#hypetop {
position: relative;
top: 0;
width: 100%;
}
#hypebot {
position:relative;
bottom: 0;
width: 100%;
}
.hypetext {
font-family: Impact, Charcoal, sans-serif;
font-size: 64px;
text-align: center;
}
Result:
Remove position:fixed; from hypetop and hypebot. This caused these elements to have fixed positions and not relative to the image.
you have to imagine them as blocks first. From what I get .. you need 3 blocks in the horizontal order: paragraph | image | paragraph , which gives us the following structure:
<p></p><img></img><p></p>
what you are missing is.. that you need to use the span tag instead fo a tag to make them not break. Which is opposite of making the page responsive (using )
simply put them like this:
<span>
<span id="test"><h1></h1></span>
<img src="" width="200px" height="200px" />
<span id="test"><h1></h1></span>
</span>
#test {
position: relative;
height: 200px;
width: 200px;
text-align: center;
display: block;
}
giving the above css rules... puts the text into a invisible/transparent block.. because we are not declaring any backround-color value. thus all 3 blocks become equal size.. 200px by 200px .. side-by-side in one line..