Simple CSS text on image layover - html

Hi I am looking to display this text over the image. I want the text to be on the left of the two people, and stay in proportion to the image when moving from a desktop to tablet view in my media queries
here is my HTML
<figure><img src="Sources/USE/colors.png">
<figcaption><h1>Your P<span class="orange">a</span>rtner in<br><br><span class="all"="colorstxt"><span class="green">C</span><span class="yellow">o</span><span class="orange">l</span><span class="red">o</span><span class="pink">r</span><span class="purple">s</span></h1></figcaption>
</figure>
and here is my CSS
#hero_container figure{
position: static;
}
#hero_container figure figcaption{
position: relative;
top: 200px;
left: 100px;
}
I have tried to make it position absolute and relative however it makes the rest of the page jump underneath the image. Any help on a simple question would be appreciated.

You're almost there...
Make the figure position: relative; and the caption absolute positioned.
#hero_container figure{
position: relative;
}
#hero_container figure figcaption{
position: absolute;
bottom: 10%;
left: 10%;
}

Static positioning is the default position for HTML elements. Try using relative positioning on the figure element so your able to absolute position the figure caption relative to the figure element.
#hero_container figure{
position: relative;
}

Static position is default status of position element.
You must use relative position for figure and absolute for caption like so:
#hero_container figure{
position: relative;
}
#hero_container figure figcaption{
position: absolute;
top: 200px;
left: 100px;
}

Here's the modified code -
HTML
<div class="image">
<img src="Sources/USE/colors.png" alt="" />
<h2><span>Your Partner in<span class='spacer'></span><br /><span class='spacer'></span>Colors</span></h2>
</div>
CSS
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
h2 span.spacer {
padding:0 5px;
}

Why not have a div float left with a higher z-index? It seems simpler to me.

Related

Hidden text element within centered absolute div

I'm having trouble getting a h2 header to appaer within an absolutely positioned element. I've ran through the list of possible errors, but still can't seem to find the answer. The h2 element, after inspecting the screen, has a height of 0 for some reason.
Here's a codepen link
HTML:
<div class="gallery">
<img class='gallery-image' src='https://dummyimage.com/200x400/000000/ffffff'>
<img class='gallery-image' src='https://dummyimage.com/200x400/000000/ffffff'>
<img class='gallery-image' src='https://dummyimage.com/200x400/000000/ffffff'>
<img class='gallery-image' src='https://dummyimage.com/200x400/000000/ffffff'>
<a class='call-action' href='#'>
<h2>Shop Now.</h2>
</a>
</div>
CSS:
.gallery {
position: absolute;
z-index: 2;
width: 100%;
display: flex;
flex-wrap: wrap;
font-size: 0;
img {
display: block;
width: 25%;
height: 50%;
#media only screen and (max-width: 500px) {
width: 50%;
height: 100%;
}
}
}
$call-action-width: 150px;
$call-action-height: 50px;
.call-action {
width: $call-action-width;
height: $call-action-height;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 0;
background-color: white;
opacity: 0.5;
border-radius: 5%;
h2 {
position: relative;
color: black;
font-size: 2em;
}
}
Sorry if the answer is obvious - I've just returned to practicing coding and I'm extremely rough.
Thanks for your help!
The problem lies in your font-size. You can't have an em font within a position: absolute <div>, as em is relative to the parent element.
Simply swapping to a fixed-size font (such as px) fixes the problem. I've created a new pen showcasing this here.
Unfortunately this means that your font can't be responsive. If you want responsive font, you'll either have to use a few media queries, or restructure your HTML so that the <h2> element has a position: relative parent (so you can use em).
Hope this helps! :)

Overlay text on image HTML

I have an image on which I want to overlay some white text. I'm trying to achieve the same thing video-sharing sites such as YouTube do with the video duration in the corner of the thumbnail. How can I do this with CSS/HTML?
Like This:
Try This :
.container {
width: 300px;
position: relative;
}
.container img {
width: 100%;
}
.container h3 {
background-color: rgba(0,0,0,0.3);
color: #fff;
position: absolute;
bottom: 0;
right: 2px;
}
<div class="container">
<img src="https://i.imgur.com/0s8kLb7.png">
<h3>Cute Animal</h3>
</div>
.main {
width:400px;
position:relative;
}
.picture {
width:100%;
}
.main p {
position:absolute;
bottom:0px;
right:0px;
color:#fff;
font-size:14px;
background:#999;
padding:3px;
z-index:99;
}
<div class="main">
<p>
Hello
</p>
<img class="picture" src="http://lorempixel.com/400/200/sports/" alt="">
</div>
You can use CSS for it.
There are two ways of doing it ~
position: absolute;
top: 200px;
left 200px;
So this one sets the position of an element to absolute and then you can specify the location in pixels but it would make it something which can't change it's position in response to other elements. It would make your element like a rectangle in Paint which you can move at freely at any place.
The Second one is recommended by me ~
margin-top: -200px;
This one is a dirty way of doing it but it is useful. You can pull thing upwards using this. If your text is on side of the text you can use margin-left as same. It depends on you which method you want to use and how much pixels do you want to specify.
In your case I could give mathematical expression for doing this ~
margin-top: -text_height;
margin-left: video_width - text_width;
Enjoy :D
Here you go :
HTML :
<div class="image">
<img src="http://lorempixel.com/400/400/sports/2" alt="" />
<h2><span>Some Text</span></h2></div><br/>
</div>
CSS :
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 300px;
left: 0;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.4);
padding: 10px;
}
https://jsfiddle.net/emilvr/f03m3Lks/
You can play with top & left to set your desire location
This is very easy to do. I am sure you do not have enough knowledge of CSS. But any way I will tell you on this.
Your structure should be like below:
<div class="relative">
<img src="" />
<span class="absolute">text</span>
</div>
Then add css for this
.relative{float:left; position;relative;}
.absolute{position:absolute; bottom:0px; right:0px;}
Adjust position as needed.

Links not working inside div

I think this question is related to Link not working inside floated div but I still can't figure it out.
I have a div as follows:
.fullwidthimage {
width: 100%;
position: relative;
z-index: -1;
}
.imageoverlay {
left: 0;
text-align: center;
position: absolute;
z-index: 1;
top: 15px;
width: 100%;
}
#homepagebutton {
position: absolute;
text-align: center;
z-index: 100;
bottom: 50px;
width: 200px;
height: 60px;
left: 50%;
margin-left: -100px;
font-size: 25px;
border: 1px solid black;
border-radius: 5px;
background-color: orange;
color: black;
text-decoration: none;
}
<div class="fullwidthimage">
<img class="noround imageundertext smallimg" src="http://placehold.it/600x800">
<img class="noround imageundertext midimg" src="http://placehold.it/1000x1000">
<img class="noround imageundertext bigimg" src="http://placehold.it/3200x1300">
<img class="noround imageundertext xlimg" src="http://placehold.it/5000x1500">
<h1 class="imageoverlay">Title Here</h1>
Get Started
</div>
The different images are using a CSS media query to display/hide at different sizes. The whole thing is a full width image with a text title and 'button' (that's actually just a link styled to look like a button) over the top of the image.
Whatever links I put inside that div won't work - the text shows on the page, but nothing happens if you mouse over.
Why?!
Links placed immediately outside of the div on the same page work just fine, so I don't think it's anything to do with other containing divs there.
I'm assuming from that previous question asked that it's something to do with the positioning, but I can't make it work.
Thanks!
If you give a -1 in z-index, it goes behind body. So the whole div.fullwidthimage becomes unclickable or unaccessible. So, give z-index: 1 as the starting point.
.fullwidthimage {
width: 100%;
position: relative;
z-index: 1; /* Change this! */
}
.imageoverlay {
left: 0;
text-align: center;
position: absolute;
z-index: 2; /* Increase this! */
top: 15px;
width: 100%;
}

Div over image without absolute positioning

I'm stuck with this... My goal is this page:
I want to place text over an image, for example "STALDEN". I know how to do this, but when i use absolute positioning and insert a new entry the text is on the same position like to one before. How can I solve this better?
Any help much appreciated!
This is what i have:
<div class="karte">
<img src="img/home/stalden.png" alt="">
<h1>STALDEN</h1>
</div>
CSS
.karte img {
width: 100vw;
}
.karte h1 {
position: absolute;
top: 50px;
left: 50px;
color: white;
font-family: "Teko", sans-serif;
font-size: 15vw;
}
You can use image as background of your section
.karte {
background: url('img/home/stalden.png');
}
<div class="karte">
<h1>STALDEN</h1>
</div>
Try this:
.karte{
position: relative;
}
.karte img{
position: absolute;
top: 0;
left: 0;
}
.karte h1{
position: absolute;
top: 50px;
left: 50px;
}
It's exactly that you ask. But it's better to use background-image here because of better semantic and other reasons... Just use background-image. It's better solution.

Vertically center text inside an absolutely-positioned div

I'm trying to vertically center text inside a div that is positioned absolutely.
I have tried table-cell approach with no luck. This is a responsive layout, so I'm trying to avoid setting fixed heights and prefer not to use Javascript either.
Thanks
Link to jsbin demo
HTML & CSS:
<div class="page-banner" style="background: url(http://www.bimga.com.php53-3.ord1-1.websitetestlink.com//wp-content/uploads/BIMGA_Website_InteriorPage_Banners_About.jpg) no-repeat scroll 0 0 / cover transparent">
<img style="visibility:hidden" src="http://www.bimga.com.php53-3.ord1-1.websitetestlink.com//wp-content/uploads/BIMGA_Website_InteriorPage_Banners_About.jpg">
<div class="left">
<div class="page-banner-text">this text needs to be verticall centered</div>
</div>
</div>
<style type="text/css">
.page-banner {
margin-bottom: 35px;
list-style: none;
width: 100%;
padding-left: 0;
position: relative;
}
.page-banner img {
width: 100%;
height: auto;
}
.page-banner .left {
background-color: rgba(10, 65, 142, .75);
position: absolute;
z-index: 1;
left: 0;
top: 0;
height: 100%;
text-align: center;
width: 50%;
}
</style>
We could use a transform like so:
Have a jsBin!
CSS
.page-banner-text {
top: 50%;
transform: translateY(-50%);
position: absolute;
}
More information on this technique.
What you can do is, set the text position to absolute.
Then give it a top: 50%; and give it a top margin of minus half its height.
I would not prefer using position absolute and top: 50% for better multi browser support (espesially on older IE versions) so I would prefer adding line-height: x em; in your .page banner class. Em because you have defined the height by % so it needs to always be on the center no matter the actual pixel height.
.page-banner .left:after {
content: "Background text";
position: absolute;
top: 40%;
left: 35%;
z-index: -1;
}