Revealing overlay div based on height?
I have an image with a text overlay with a title describing the image. On hover, I want the title text to push up, revealing the description text underneath the title. But, my code doesn't work if the divs that contain the text change in height. For example, when the description text is short, the title text moves up too much, resulting in a gap between the two divs.
So, the title text should move up based on the height of the description div. How do I do that?
https://codepen.io/tayanderson/pen/qJrmXE
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Caramel Walnut Apple Pie
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Butter Cake
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Chocolate Pecan Ice Cream
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
padding: 0 20px;
font-size: 35px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
}
&:hover .title {
bottom: 30%;
}
&:hover .desc {
transform: translateY(0%);
}
}
html css
add a comment |
I have an image with a text overlay with a title describing the image. On hover, I want the title text to push up, revealing the description text underneath the title. But, my code doesn't work if the divs that contain the text change in height. For example, when the description text is short, the title text moves up too much, resulting in a gap between the two divs.
So, the title text should move up based on the height of the description div. How do I do that?
https://codepen.io/tayanderson/pen/qJrmXE
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Caramel Walnut Apple Pie
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Butter Cake
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Chocolate Pecan Ice Cream
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
padding: 0 20px;
font-size: 35px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
}
&:hover .title {
bottom: 30%;
}
&:hover .desc {
transform: translateY(0%);
}
}
html css
I would put the.title
in the.desc
div as ah4
- for example. This would solve your problem.
– enxaneta
Nov 14 '18 at 18:15
add a comment |
I have an image with a text overlay with a title describing the image. On hover, I want the title text to push up, revealing the description text underneath the title. But, my code doesn't work if the divs that contain the text change in height. For example, when the description text is short, the title text moves up too much, resulting in a gap between the two divs.
So, the title text should move up based on the height of the description div. How do I do that?
https://codepen.io/tayanderson/pen/qJrmXE
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Caramel Walnut Apple Pie
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Butter Cake
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Chocolate Pecan Ice Cream
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
padding: 0 20px;
font-size: 35px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
}
&:hover .title {
bottom: 30%;
}
&:hover .desc {
transform: translateY(0%);
}
}
html css
I have an image with a text overlay with a title describing the image. On hover, I want the title text to push up, revealing the description text underneath the title. But, my code doesn't work if the divs that contain the text change in height. For example, when the description text is short, the title text moves up too much, resulting in a gap between the two divs.
So, the title text should move up based on the height of the description div. How do I do that?
https://codepen.io/tayanderson/pen/qJrmXE
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Caramel Walnut Apple Pie
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Butter Cake
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Chocolate Pecan Ice Cream
</div>
<div class="desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
padding: 0 20px;
font-size: 35px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
}
&:hover .title {
bottom: 30%;
}
&:hover .desc {
transform: translateY(0%);
}
}
html css
html css
asked Nov 14 '18 at 17:28
taylor018taylor018
254
254
I would put the.title
in the.desc
div as ah4
- for example. This would solve your problem.
– enxaneta
Nov 14 '18 at 18:15
add a comment |
I would put the.title
in the.desc
div as ah4
- for example. This would solve your problem.
– enxaneta
Nov 14 '18 at 18:15
I would put the
.title
in the .desc
div as a h4
- for example. This would solve your problem.– enxaneta
Nov 14 '18 at 18:15
I would put the
.title
in the .desc
div as a h4
- for example. This would solve your problem.– enxaneta
Nov 14 '18 at 18:15
add a comment |
3 Answers
3
active
oldest
votes
I came up with this, first I changed your markup a little bit
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
<h1>Test</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam eius perspiciatis similique, unde impedit esse, temporibus quo.</p>
</div>
</div>
Now you have the title and text in the same div, and then you need to change your css a little bit, I translated the div 100% less the height of the title, transform: translateY(calc(100% - 40px));
and then added a transition
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
padding: 10px;
.title h1 {
font-size: 35px;
margin: 0;
height: 40px;
}
.title p {
margin: 0;
left: 0;
right: 0;
width: 90%;
}
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
transform: translateY(calc(100% - 40px));
transition: all .4s ease-out;
padding: 0 20px;
}
&:hover .title {
transform: translateY(0%);
}
}
Let me know if that what you are looking for! Here you have a codepen.
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
add a comment |
As I've told you in my comment I would put the .title
in the .desc
div as a h4
- for example. This would solve your problem. Next come a demo:
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
add a comment |
hmm, or maybe could you place title at the top?
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Short text
</div>
<div class="desc">
ectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
style:
.title {
position: absolute;
left: 0;
top: 0;
width: 100%;
padding: 0 20px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
word-break: break-all;
}
&:hover .title {
position: relative;
}
&:hover .desc {
transform: translateY(0%);
position: relative;
word-break: break-all;
}
in that case everything looks more correctly, without jumping the title
Like here : https://codepen.io/anon/pen/XyMQjO
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%2f53305749%2frevealing-overlay-div-based-on-height%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I came up with this, first I changed your markup a little bit
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
<h1>Test</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam eius perspiciatis similique, unde impedit esse, temporibus quo.</p>
</div>
</div>
Now you have the title and text in the same div, and then you need to change your css a little bit, I translated the div 100% less the height of the title, transform: translateY(calc(100% - 40px));
and then added a transition
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
padding: 10px;
.title h1 {
font-size: 35px;
margin: 0;
height: 40px;
}
.title p {
margin: 0;
left: 0;
right: 0;
width: 90%;
}
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
transform: translateY(calc(100% - 40px));
transition: all .4s ease-out;
padding: 0 20px;
}
&:hover .title {
transform: translateY(0%);
}
}
Let me know if that what you are looking for! Here you have a codepen.
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
add a comment |
I came up with this, first I changed your markup a little bit
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
<h1>Test</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam eius perspiciatis similique, unde impedit esse, temporibus quo.</p>
</div>
</div>
Now you have the title and text in the same div, and then you need to change your css a little bit, I translated the div 100% less the height of the title, transform: translateY(calc(100% - 40px));
and then added a transition
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
padding: 10px;
.title h1 {
font-size: 35px;
margin: 0;
height: 40px;
}
.title p {
margin: 0;
left: 0;
right: 0;
width: 90%;
}
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
transform: translateY(calc(100% - 40px));
transition: all .4s ease-out;
padding: 0 20px;
}
&:hover .title {
transform: translateY(0%);
}
}
Let me know if that what you are looking for! Here you have a codepen.
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
add a comment |
I came up with this, first I changed your markup a little bit
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
<h1>Test</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam eius perspiciatis similique, unde impedit esse, temporibus quo.</p>
</div>
</div>
Now you have the title and text in the same div, and then you need to change your css a little bit, I translated the div 100% less the height of the title, transform: translateY(calc(100% - 40px));
and then added a transition
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
padding: 10px;
.title h1 {
font-size: 35px;
margin: 0;
height: 40px;
}
.title p {
margin: 0;
left: 0;
right: 0;
width: 90%;
}
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
transform: translateY(calc(100% - 40px));
transition: all .4s ease-out;
padding: 0 20px;
}
&:hover .title {
transform: translateY(0%);
}
}
Let me know if that what you are looking for! Here you have a codepen.
I came up with this, first I changed your markup a little bit
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
<h1>Test</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam eius perspiciatis similique, unde impedit esse, temporibus quo.</p>
</div>
</div>
Now you have the title and text in the same div, and then you need to change your css a little bit, I translated the div 100% less the height of the title, transform: translateY(calc(100% - 40px));
and then added a transition
.grid-item {
display: inline-block;
height:300px;
background-size: cover;
width:300px;
position: relative;
overflow: hidden;
color: #fff;
padding: 10px;
.title h1 {
font-size: 35px;
margin: 0;
height: 40px;
}
.title p {
margin: 0;
left: 0;
right: 0;
width: 90%;
}
.title {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
transform: translateY(calc(100% - 40px));
transition: all .4s ease-out;
padding: 0 20px;
}
&:hover .title {
transform: translateY(0%);
}
}
Let me know if that what you are looking for! Here you have a codepen.
answered Nov 14 '18 at 18:08
MartinBAMartinBA
7161213
7161213
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
add a comment |
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
This is perfect! Thanks alot!
– taylor018
Nov 14 '18 at 18:27
add a comment |
As I've told you in my comment I would put the .title
in the .desc
div as a h4
- for example. This would solve your problem. Next come a demo:
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
add a comment |
As I've told you in my comment I would put the .title
in the .desc
div as a h4
- for example. This would solve your problem. Next come a demo:
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
add a comment |
As I've told you in my comment I would put the .title
in the .desc
div as a h4
- for example. This would solve your problem. Next come a demo:
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
As I've told you in my comment I would put the .title
in the .desc
div as a h4
- for example. This would solve your problem. Next come a demo:
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
.grid-item {
height: 250px;
background-size: cover;
width: 250px;
position: relative;
overflow: hidden;
color: #fff;
display:inline-block;
margin:1em;
}
.grid-item .desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
transition: transform 1.5s;
}
.grid-item:hover .desc {
transform: translateY(0%);
}
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet Lorem ipsum dolor sit amet
</div>
</div>
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="desc">
<h4>Title</h4>
Lorem ipsum dolor sit amet Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
</div>
</div>
answered Nov 14 '18 at 18:22
enxanetaenxaneta
7,8842518
7,8842518
add a comment |
add a comment |
hmm, or maybe could you place title at the top?
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Short text
</div>
<div class="desc">
ectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
style:
.title {
position: absolute;
left: 0;
top: 0;
width: 100%;
padding: 0 20px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
word-break: break-all;
}
&:hover .title {
position: relative;
}
&:hover .desc {
transform: translateY(0%);
position: relative;
word-break: break-all;
}
in that case everything looks more correctly, without jumping the title
Like here : https://codepen.io/anon/pen/XyMQjO
add a comment |
hmm, or maybe could you place title at the top?
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Short text
</div>
<div class="desc">
ectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
style:
.title {
position: absolute;
left: 0;
top: 0;
width: 100%;
padding: 0 20px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
word-break: break-all;
}
&:hover .title {
position: relative;
}
&:hover .desc {
transform: translateY(0%);
position: relative;
word-break: break-all;
}
in that case everything looks more correctly, without jumping the title
Like here : https://codepen.io/anon/pen/XyMQjO
add a comment |
hmm, or maybe could you place title at the top?
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Short text
</div>
<div class="desc">
ectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
style:
.title {
position: absolute;
left: 0;
top: 0;
width: 100%;
padding: 0 20px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
word-break: break-all;
}
&:hover .title {
position: relative;
}
&:hover .desc {
transform: translateY(0%);
position: relative;
word-break: break-all;
}
in that case everything looks more correctly, without jumping the title
Like here : https://codepen.io/anon/pen/XyMQjO
hmm, or maybe could you place title at the top?
<div class="grid-item" style="background-image: url(https://source.unsplash.com/WLUHO9A_xik/1600x900);">
<div class="title">
Short text
</div>
<div class="desc">
ectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
style:
.title {
position: absolute;
left: 0;
top: 0;
width: 100%;
padding: 0 20px;
}
.desc {
position: absolute;
bottom: 0;
transform: translateY(100%);
padding: 5px 20px;
word-break: break-all;
}
&:hover .title {
position: relative;
}
&:hover .desc {
transform: translateY(0%);
position: relative;
word-break: break-all;
}
in that case everything looks more correctly, without jumping the title
Like here : https://codepen.io/anon/pen/XyMQjO
answered Nov 14 '18 at 17:49
BartoszTermenaBartoszTermena
7381311
7381311
add a comment |
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%2f53305749%2frevealing-overlay-div-based-on-height%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
I would put the
.title
in the.desc
div as ah4
- for example. This would solve your problem.– enxaneta
Nov 14 '18 at 18:15