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

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;
}

Related

Get an Graphic to Stay in Same Place Relative to H1 Text

I'm trying to get a small yellow swoosh to underline a word in some text and stay where it is as the page resizes. Right now I can get the swoosh in the right spot under the text, but when the screen resizes it all goes to hell.
Here is an image of what I'm going for
<div>
<span>
<h1>How are you doing? Hello World.</h1>
<img src="imageurl here">
</span>
</div>
div {
right: 0;
left: 0;
margin-right: auto;
margin-left: auto;
width: 40%;
position: absolute;
}
h1{
text-align: center;
}
span {
margin-left: 140px;
top: 40px;
position: absolute;
z-index: -1;
}
(I didn't want to share the image URL as it is proprietary)
Any ideas on how to achieve this type of effect responsively?
Put your image inside of the h1 tag and give your h1 tag a position property. Also make sure you are setting h1 to be a inline-block element and center it somehow.
<h1>How are you doing? Hello World.<img src="imageurl here"></h1>
h1{
text-align: center;
position: relative;
display: inline-block;
margin: 0 auto;
}
img{
left: 0;
top: 0;
position: absolute;
z-index: -1;
}
There are many different ways to achieve what you're after.

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

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;
}

Image overlapping text and logo not centering on top of image

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.

Div to stretch to fit contents. Overflow: auto; does not work

I've created a long scrolling website composed of different sections which fill up the whole screen. One Section contains some pretty lengthy text but the top and bottom parts of the text are cut off. Basically my div won't stretch all the way to accommodate the text. I would like my div to be able to stretch to at least 200% down.
fiddle
I've tried
overflow:auto;
min-height:100%;
This is what it looks like, as you can see at the bottom...the text is cut off.
If I remove Position: absolute; The whole text moves to the left and the bottom text is still cut off.
This is part of my html:
<section id="slide-15" class="homeSlide">
<div class="bcg">
<div class="hsContainer">
<h1>CV GUIDE</h1>
<br>
<h2>
//lengthy text goes here
//lengthy text goes here
//lengthy text goes here
</h2>
</div>
</div>
</section>
and part of style.css
#slide-15 .bcg {
/*position: relative;*/
background-color: #1C1C1C;
min-height: 100%;
overflow: auto;
/*padding:150px;*/
}
slide-15 .hsContent {
position: relative;
}
slide-15 .hscontainer {
width-100%
min-height: 100%;
overflow: auto;
/* position:relative;*/
}
#slide-15 h1 {
margin: 70px;
color: #ffffff;
font-size: 30px;
line-height: 20px;
position: relative;
text-shadow: 2px 4px 3px rgba(0,0,0,0.3);
}
#slide-15 h2 {
color: #ffffff;
font-size: 14px;
line-height: 150%;
position: absolute;
line-spacing: 1px;
text-align: justify;
width: 700px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
with position:absolute it gets cut out of the workflow ,so you need to remove it with you want the parent div to adjust to height;
also set it to display:inline-block ,
check fiddle
You've got a lot of syntax errors in CSS,
I cleaned it up a little here's an updated fiddle
Try creating a class in css like this:
.test {
white-space: nowrap;
}
and apply it to your h2:
<h2 class="test">
//lengthy text goes here
//lengthy text goes here
//lengthy text goes here
</h2>