Overlay appear on Hover - Pure CSS
As you can see in the following snippet, I have a category-box
and on the hover
event of that box I want appear a overlay.
Here is the CODEPEN
The problem here is, I want the overlay to start from the middle of the category-box
and appear. But here as you can see it start from somewhere in the middle.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
html css animation css-animations
add a comment |
As you can see in the following snippet, I have a category-box
and on the hover
event of that box I want appear a overlay.
Here is the CODEPEN
The problem here is, I want the overlay to start from the middle of the category-box
and appear. But here as you can see it start from somewhere in the middle.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
html css animation css-animations
2
The issue is that you are having a transition on transform and left/top which create the issue ...removing translate as explained below will fix this
– Temani Afif
Nov 21 at 9:19
add a comment |
As you can see in the following snippet, I have a category-box
and on the hover
event of that box I want appear a overlay.
Here is the CODEPEN
The problem here is, I want the overlay to start from the middle of the category-box
and appear. But here as you can see it start from somewhere in the middle.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
html css animation css-animations
As you can see in the following snippet, I have a category-box
and on the hover
event of that box I want appear a overlay.
Here is the CODEPEN
The problem here is, I want the overlay to start from the middle of the category-box
and appear. But here as you can see it start from somewhere in the middle.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
html css animation css-animations
html css animation css-animations
edited Nov 21 at 8:12
asked Nov 21 at 7:55
Ramesh
1,230319
1,230319
2
The issue is that you are having a transition on transform and left/top which create the issue ...removing translate as explained below will fix this
– Temani Afif
Nov 21 at 9:19
add a comment |
2
The issue is that you are having a transition on transform and left/top which create the issue ...removing translate as explained below will fix this
– Temani Afif
Nov 21 at 9:19
2
2
The issue is that you are having a transition on transform and left/top which create the issue ...removing translate as explained below will fix this
– Temani Afif
Nov 21 at 9:19
The issue is that you are having a transition on transform and left/top which create the issue ...removing translate as explained below will fix this
– Temani Afif
Nov 21 at 9:19
add a comment |
2 Answers
2
active
oldest
votes
You can just remove transform: translate(-50%, -50%);
on .category-overlay
:
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
If you want to be 100% sure that an absolute positioned element is centered, you can use these properties:
/* Center horizontally */
right: 0;
left: 0;
margin: auto;
/* Center vertically */
top: 50%;
transform: translateY(-50%);
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
add a comment |
in .category-overlay
use this
top: calc(50% + 88px);
left: calc(50% + 155px);
The 88px
and 155px
are half of the box size so it should be the middle of your content.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
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%2f53407456%2foverlay-appear-on-hover-pure-css%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
You can just remove transform: translate(-50%, -50%);
on .category-overlay
:
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
If you want to be 100% sure that an absolute positioned element is centered, you can use these properties:
/* Center horizontally */
right: 0;
left: 0;
margin: auto;
/* Center vertically */
top: 50%;
transform: translateY(-50%);
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
add a comment |
You can just remove transform: translate(-50%, -50%);
on .category-overlay
:
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
If you want to be 100% sure that an absolute positioned element is centered, you can use these properties:
/* Center horizontally */
right: 0;
left: 0;
margin: auto;
/* Center vertically */
top: 50%;
transform: translateY(-50%);
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
add a comment |
You can just remove transform: translate(-50%, -50%);
on .category-overlay
:
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
If you want to be 100% sure that an absolute positioned element is centered, you can use these properties:
/* Center horizontally */
right: 0;
left: 0;
margin: auto;
/* Center vertically */
top: 50%;
transform: translateY(-50%);
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
You can just remove transform: translate(-50%, -50%);
on .category-overlay
:
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
If you want to be 100% sure that an absolute positioned element is centered, you can use these properties:
/* Center horizontally */
right: 0;
left: 0;
margin: auto;
/* Center vertically */
top: 50%;
transform: translateY(-50%);
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: 50%;
left: 50%;
/*-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 30px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
#container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#child {
width: 30px;
height: 30px;
background: yellow;
position: absolute;
right: 0;
left: 0;
margin: auto;
top: 50%;
transform: translateY(-50%)
}
<div id="container">
<div id="child"></div>
</div>
edited Nov 21 at 8:58
answered Nov 21 at 8:51
Arkellys
81116
81116
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
add a comment |
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
Excellent answer. Thank you sir
– Ramesh
Nov 21 at 9:22
add a comment |
in .category-overlay
use this
top: calc(50% + 88px);
left: calc(50% + 155px);
The 88px
and 155px
are half of the box size so it should be the middle of your content.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
add a comment |
in .category-overlay
use this
top: calc(50% + 88px);
left: calc(50% + 155px);
The 88px
and 155px
are half of the box size so it should be the middle of your content.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
add a comment |
in .category-overlay
use this
top: calc(50% + 88px);
left: calc(50% + 155px);
The 88px
and 155px
are half of the box size so it should be the middle of your content.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
in .category-overlay
use this
top: calc(50% + 88px);
left: calc(50% + 155px);
The 88px
and 155px
are half of the box size so it should be the middle of your content.
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
.category-box {
padding: 15px 0;
position: relative;
}
.category-img {
overflow: hidden;
}
.category-img img {
width: 100%;
object-fit: cover;
object-position: center;
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box .category-img img {
height: 500px;
}
.category-content {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #000000;
color: white;
padding: 25px;
text-align: center;
min-width: 260px;
min-height: 125px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 1;
}
.category-overlay {
position: absolute;
left: 0;
height: 0;
width: 0;
background-color: rgba(0, 0, 0, 0.45);
top: calc(50% + 88px);
left: calc(50% + 155px);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: ease 0.4s all;
-moz-transition: ease 0.4s all;
-ms-transition: ease 0.4s all;
transition: ease 0.4s all;
}
.category-big-box:hover .category-overlay {
top: 15px;
transform: none;
left: 0;
}
.category-box:hover .category-overlay {
height: calc(100% - 45px);
width: 100%;
}
.category-box:hover .category-img img {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="category-box category-big-box">
<div class="category-img">
<img src="https://timeless-dubai.com/wp-content/uploads/2018/07/i3.jpg" alt="Category Image">
</div>
<div class="category-content">
some content
</div>
<div class="category-overlay"></div>
</div>
answered Nov 21 at 8:18
Itay Gal
7,44352559
7,44352559
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
add a comment |
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
Nice approach sir, but when it comes to responsive it's not going to work properly sir. So it will be a remaining problem now.
– Ramesh
Nov 21 at 8:21
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
As well as it won't placed in exact center when we add + values to the top and left values according to the way I have done this.
– Ramesh
Nov 21 at 8:23
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53407456%2foverlay-appear-on-hover-pure-css%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
2
The issue is that you are having a transition on transform and left/top which create the issue ...removing translate as explained below will fix this
– Temani Afif
Nov 21 at 9:19