Displaying text over an imageVertically align text next to an image?How do I give text or an image a transparent background using CSS?How to disable text selection highlightingHow do I vertically align text in a div?How to overlay one div over another divHow do I auto-resize an image to fit a 'div' container?Make the cursor a hand when a user hovers over a list itemTransitions on the display: propertyHow do I vertically center text with CSS?Cannot display HTML string
Compelling story with the world as a villain
Why in most German places is the church the tallest building?
Why doesn't 'd /= d' throw a division by zero exception?
How do proponents of Sola Scriptura address the ministry of those Apostles who authored no parts of Scripture?
Very slow boot time and poor perfomance
Why is 1. d4 Nf6 2. c4 e6 3. Bg5 almost never played?
How do thermal tapes transfer heat despite their low thermal conductivity?
Obtaining the intermediate solutions in AMPL
Why are non-collision-resistant hash functions considered insecure for signing self-generated information
Transposing from C to Cm?
Was it ever possible to target a zone?
How can I unambiguously ask for a new user's "Display Name"?
Uri tokenizer as a simple state machine
Rent contract say that pets are not allowed. Possible repercussions if bringing the pet anyway?
Who was president of the USA?
Is "The life is beautiful" incorrect or just very non-idiomatic?
Where can/should I, as a high schooler, publish a paper regarding the derivation of a formula?
Does an atom recoil when photon radiate?
Numbers Decrease while Letters Increase
Why do banks “park” their money at the European Central Bank?
Does Norwegian overbook flights?
Can I get temporary health insurance while moving to the US?
How long do you think advanced cybernetic implants would plausibly last?
Are the players on the same team as the DM?
Displaying text over an image
Vertically align text next to an image?How do I give text or an image a transparent background using CSS?How to disable text selection highlightingHow do I vertically align text in a div?How to overlay one div over another divHow do I auto-resize an image to fit a 'div' container?Make the cursor a hand when a user hovers over a list itemTransitions on the display: propertyHow do I vertically center text with CSS?Cannot display HTML string
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to display a text over an image when hovering. I was trying to follow this guide, but I didnt manage to convert that to my project.
I could make an overlay, but that would have to be a fixed overlay, I would like to have it so it changes when the resolution changes. I wanted the overlay to be same size as thumbmail.
HTML:
<div class="col-md-6 col-sm-2">
% for phone in phones %
<div class="llol col-md-8 col-md-2">
<a href=" url_for('phones.phone', id=phone.id) " class="thumbnail">
<img src=" url_for('static', filename='phone_pics/' + phone.image) " alt="" class="cus-img">
% if phone.stock == 0 %
<div class="overlayOUT">
<div class="textOUT">OUT OF STOCK!</div>
</div>
</a>
% else %
</a>
% endif %
<p style="text-align: center;"><b>phone.brand.name</b> <span style="color: #006666;">phone.model</span><span class="badge">phone.stock</span></p>
</div>
% endfor %
</div>
CSS:
.thumbnail img
height:240px;
width:100%;
.overlayOUT
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-left: 15px;
height: 250px;
width: 183px;
opacity: 0.8;
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
html css
add a comment |
I am trying to display a text over an image when hovering. I was trying to follow this guide, but I didnt manage to convert that to my project.
I could make an overlay, but that would have to be a fixed overlay, I would like to have it so it changes when the resolution changes. I wanted the overlay to be same size as thumbmail.
HTML:
<div class="col-md-6 col-sm-2">
% for phone in phones %
<div class="llol col-md-8 col-md-2">
<a href=" url_for('phones.phone', id=phone.id) " class="thumbnail">
<img src=" url_for('static', filename='phone_pics/' + phone.image) " alt="" class="cus-img">
% if phone.stock == 0 %
<div class="overlayOUT">
<div class="textOUT">OUT OF STOCK!</div>
</div>
</a>
% else %
</a>
% endif %
<p style="text-align: center;"><b>phone.brand.name</b> <span style="color: #006666;">phone.model</span><span class="badge">phone.stock</span></p>
</div>
% endfor %
</div>
CSS:
.thumbnail img
height:240px;
width:100%;
.overlayOUT
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-left: 15px;
height: 250px;
width: 183px;
opacity: 0.8;
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
html css
add a comment |
I am trying to display a text over an image when hovering. I was trying to follow this guide, but I didnt manage to convert that to my project.
I could make an overlay, but that would have to be a fixed overlay, I would like to have it so it changes when the resolution changes. I wanted the overlay to be same size as thumbmail.
HTML:
<div class="col-md-6 col-sm-2">
% for phone in phones %
<div class="llol col-md-8 col-md-2">
<a href=" url_for('phones.phone', id=phone.id) " class="thumbnail">
<img src=" url_for('static', filename='phone_pics/' + phone.image) " alt="" class="cus-img">
% if phone.stock == 0 %
<div class="overlayOUT">
<div class="textOUT">OUT OF STOCK!</div>
</div>
</a>
% else %
</a>
% endif %
<p style="text-align: center;"><b>phone.brand.name</b> <span style="color: #006666;">phone.model</span><span class="badge">phone.stock</span></p>
</div>
% endfor %
</div>
CSS:
.thumbnail img
height:240px;
width:100%;
.overlayOUT
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-left: 15px;
height: 250px;
width: 183px;
opacity: 0.8;
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
html css
I am trying to display a text over an image when hovering. I was trying to follow this guide, but I didnt manage to convert that to my project.
I could make an overlay, but that would have to be a fixed overlay, I would like to have it so it changes when the resolution changes. I wanted the overlay to be same size as thumbmail.
HTML:
<div class="col-md-6 col-sm-2">
% for phone in phones %
<div class="llol col-md-8 col-md-2">
<a href=" url_for('phones.phone', id=phone.id) " class="thumbnail">
<img src=" url_for('static', filename='phone_pics/' + phone.image) " alt="" class="cus-img">
% if phone.stock == 0 %
<div class="overlayOUT">
<div class="textOUT">OUT OF STOCK!</div>
</div>
</a>
% else %
</a>
% endif %
<p style="text-align: center;"><b>phone.brand.name</b> <span style="color: #006666;">phone.model</span><span class="badge">phone.stock</span></p>
</div>
% endfor %
</div>
CSS:
.thumbnail img
height:240px;
width:100%;
.overlayOUT
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin-left: 15px;
height: 250px;
width: 183px;
opacity: 0.8;
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
html css
html css
asked Mar 27 at 18:32
MenorMenor
177 bronze badges
177 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Just add display: none;
prop in .textOUT
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
display: none;
And add hover CSS
, i hope it'll help you out. Thanks
.thumbnail:hover .textOUT
display: block;
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
add a comment |
The easiest way to do it is by simply creating a container for the text, setting its opacity to 0, and changing the opacity to 1 on the hover event. You're not using vanilla HTML, and I don't have access to your variables, so I made a sample that can be implemented the same way.
The .container
class is setting the positioning of both the image and the hidden text container. Then, just set the .text-container
class to be positioned on top of the image, and set a hover event on this class to change it from 0 opacity to 1.
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
You can read about many different ways to hover things in over images here.
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55384281%2fdisplaying-text-over-an-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just add display: none;
prop in .textOUT
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
display: none;
And add hover CSS
, i hope it'll help you out. Thanks
.thumbnail:hover .textOUT
display: block;
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
add a comment |
Just add display: none;
prop in .textOUT
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
display: none;
And add hover CSS
, i hope it'll help you out. Thanks
.thumbnail:hover .textOUT
display: block;
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
add a comment |
Just add display: none;
prop in .textOUT
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
display: none;
And add hover CSS
, i hope it'll help you out. Thanks
.thumbnail:hover .textOUT
display: block;
Just add display: none;
prop in .textOUT
.textOUT
color: white;
padding: auto;
font-size: 20px;
position: absolute;
top: 48%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
background-color: #FA8072;
display: none;
And add hover CSS
, i hope it'll help you out. Thanks
.thumbnail:hover .textOUT
display: block;
answered Mar 27 at 19:27
Hassan SiddiquiHassan Siddiqui
2,0421 gold badge7 silver badges15 bronze badges
2,0421 gold badge7 silver badges15 bronze badges
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
add a comment |
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
Thanks, that works for me, but do you have any idea why the text isn't in the middle of the thumbnail? It is like 10% down, even when I have top:50% and left:50% in the css
– Menor
Mar 28 at 1:05
add a comment |
The easiest way to do it is by simply creating a container for the text, setting its opacity to 0, and changing the opacity to 1 on the hover event. You're not using vanilla HTML, and I don't have access to your variables, so I made a sample that can be implemented the same way.
The .container
class is setting the positioning of both the image and the hidden text container. Then, just set the .text-container
class to be positioned on top of the image, and set a hover event on this class to change it from 0 opacity to 1.
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
You can read about many different ways to hover things in over images here.
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
add a comment |
The easiest way to do it is by simply creating a container for the text, setting its opacity to 0, and changing the opacity to 1 on the hover event. You're not using vanilla HTML, and I don't have access to your variables, so I made a sample that can be implemented the same way.
The .container
class is setting the positioning of both the image and the hidden text container. Then, just set the .text-container
class to be positioned on top of the image, and set a hover event on this class to change it from 0 opacity to 1.
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
You can read about many different ways to hover things in over images here.
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
add a comment |
The easiest way to do it is by simply creating a container for the text, setting its opacity to 0, and changing the opacity to 1 on the hover event. You're not using vanilla HTML, and I don't have access to your variables, so I made a sample that can be implemented the same way.
The .container
class is setting the positioning of both the image and the hidden text container. Then, just set the .text-container
class to be positioned on top of the image, and set a hover event on this class to change it from 0 opacity to 1.
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
You can read about many different ways to hover things in over images here.
The easiest way to do it is by simply creating a container for the text, setting its opacity to 0, and changing the opacity to 1 on the hover event. You're not using vanilla HTML, and I don't have access to your variables, so I made a sample that can be implemented the same way.
The .container
class is setting the positioning of both the image and the hidden text container. Then, just set the .text-container
class to be positioned on top of the image, and set a hover event on this class to change it from 0 opacity to 1.
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
You can read about many different ways to hover things in over images here.
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
.container
box-sizing: border-box;
position: relative;
display: inline-block;
overflow: hidden;
width: 400px;
height: 300px;
img
width: 100%;
height: 100%;
.text-container
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: #fff;
transition: all 0.4s ease-in-out 0s;
.text-container:hover
opacity: 1;
.text
text-align: center;
position: relative;
top: 50%;
<div class="container">
<img src="https://www.romanticasheville.com/sites/default/files/images/basic_page/Asheville_Waterfalls.jpg">
<div class="text-container">
<div class="text">Beautiful Waterfall</div>
</div>
</div>
edited Mar 27 at 19:18
answered Mar 27 at 19:05
NickNick
1,1991 gold badge9 silver badges18 bronze badges
1,1991 gold badge9 silver badges18 bronze badges
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
add a comment |
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
When I am trying to do it your way, then the overlay is a size of whole div md-2, not not the size of the thumbnail
– Menor
Mar 28 at 1:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55384281%2fdisplaying-text-over-an-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown