When I hover my mouse on the background of the image, the 3D effect triggers, but when I move over the girl image area, it doesn't trigger anymore. The transparent image is overlaying the background. How do I make it triggers when the mouse is over the girl image?
See what I did on JSFIDDLE
HTML -
<div class="test-imgplace">
<img src="https://christianluneborg.com/imgs/test-woman.png" class="imgtest">
<div class="card-hover">
<div class="card">
<div class="card-content">
<div class="image" style="background-image: url(https://christianluneborg.com/imgs/test-woman-bg.png);"></div>
</div>
</div>
</div>
</div>
CSS -
.card .image{
height: 275px;
width: 183px;
background-size: cover;
background-position: center center;
}
.imgtest {
position: absolute;
z-index: 1;
text-align: center;
top: 0;
left: 100px;
border: solid 1px;
}
.test-imgplace {
margin: 0 auto;
position: relative;
overflow: hidden;
}
.card .text{
height: 20%;
margin: 0;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
font-size: 50px;
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 0;
}
.card{
width: 183px;
height: 275px;
margin: auto auto;
background: #383030;
border-radius: 5px;
overflow: hidden;
text-align: center;
}
.card-content{
transform-style: preserve-3d;
}
body{
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.hover-in{
transition: .3s ease-out;
}
.hover-out{
transition: .3s ease-in;
}
.card-hover{
margin:0;
}
When the mouse hovers over the semi-transparent image, it causes mouse events to go there instead of the script that is applying the 3D effect.
This is easy to fix - just add pointer-events: none; to .imgtest. JSFiddle of the fix
Related
I'm learning from a project which uses cards with border-radius 50px. However, on wider screen, the border is not working. It's a quite simple code, bud I don't understand why this is happening
Can you help me?
<div class="panel panel1" style="background-image: url('https://images.unsplash.com/photo-1448375240586-882707db888b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8Zm9yZXN0fGVufDB8fDB8fA%3D%3D&w=1000&q=80')">
<h3>Explore the world</h3>
</div>
body {
font-family: 'Muli', sans-serif;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
.container {
display: flex;
width: 90vw;
overflow: hidden;
}
.panel {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: white;
cursor: pointer;
flex: 0.2;
margin: 15px;
position: relative;
transition: flex 0.7s ease-in;
overflow: hidden;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 60px;
left: 200px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 2;
overflow: hidden;
}
Border radius not working
looking at the print screen it looks like the border radius is working, but the div is being cut, maybe you can solve this by adding a width to the panel
I'm noticing some lag from some of my images, and I was curious on what the most efficient way of loading a zoomable background image would be: Img tag vs a pseudo element with a background image.
My goal is to not have lag on a high quality image.
Which of these would be best from a performance perspective for zoomable background image?
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.card-list {
display: flex;
justify-content: center;
gap: 20px;
padding: 20px;
}
.card {
height: 300px;
width: 250px;
position: relative;
box-shadow: 0 0 5px grey;
overflow: hidden;
border-radius: 20px;
background-color: #0004;
}
.card-text {
display: flex;
align-items: flex-end;
color: white;
font-size: 24px;
font-family: Arial;
padding: 20px;
height: 100%;
width: 100%;
}
.background-image {
position: absolute;
object-fit: cover;
object-position: center;
height: 100%;
width: 100%;
transition: transform .4s ease;
z-index: -1;
}
.card:hover .background-image,
.psuedo-bg-img:hover::before {
transform: scale(1.1);
}
.psuedo-bg-img {
position: relative;
}
.psuedo-bg-img::before {
content: '';
background-image: url('https://source.unsplash.com/random');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
position: absolute;
height: 100%;
width: 100%;
z-index: -1;
transition: transform .4s ease;
}
<div class="card-list">
<div class="card">
<img class="background-image" src="https://source.unsplash.com/random">
<div class="card-text">
<h3><img> as Background</h3>
</div>
</div>
<div class="card psuedo-bg-img">
<div class="card-text">
<h3>Pseudo Elem w/ Background Image</h3>
</div>
</div>
</div>
I am very new to the whole of CSS and web development. I have been learning by looking at the examples on W3 and Codepen. I have prepared a flexbox inside swipeable slides. I want each card to be zoomed in and show a description. I am also putting the links here.. can someone please explain where I went wrong?
Here's is my code
I want a translazeZ transform on each tab in my flexbox. I want each tab to be expanded as a larger section.
This is an example
.card{
display: flex;
flex-wrap: wrap;
flex-grow: 4;
font-size: 22px;
padding: 25px;
margin: 15px;
color: white;
border-radius: 5px;
background: blue;
transform-style: preserve-3d;
transition: transform 0.5s;
justify-content: center;
align-content: center;
}
.card div {
position: absolute;
width: 100%;
height: 100%;
border-radius: 6px;
background: blue;
display: flex;
justify-content: center;
transform-style: preserve-3d;
align-items: center;
transition: 1s;
color: white;
}
.card .des {
display: none;
}
.card.flipped {
transform: translateZ(100px);
}
I think this is what you want, but you have to wrap the description in an element (for example 'span') and that again in an container (for example 'div') for centering with flex, since toggle() does display: block;.
$('.container').on('click', function() {
$('.card').toggleClass('flipped');
$('.des').toggle();
});
.container {
position: relative;
width: 300px;
height: 200px;
perspective: 800px;
}
.card {
display: flex;
flex-wrap: wrap;
flex-grow: 4;
justify-content: center;
align-content: center;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.5s;
padding: 25px;
margin: 15px;
border-radius: 5px;
font-size: 22px;
background: blue;
color: white;
}
.card div {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: transform 1s;
border-radius: 6px;
background: blue;
color: white;
}
.card .des {
display: none;
}
.card.flipped {
transform: translateZ(100px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="card">
<div>
<h5>Integration</h5><br>
<div class="des">
<div>
<span>Description, Yo, what up?</span>
</div>
</div>
</div>
</div>
</div>
You should take a look at the transform: scale property. I think this is what you need ;)
https://developer.mozilla.org/fr/docs/Web/CSS/transform-function/scale()
transform: scale(2); /* --> Gives you the double resized of normal item*/
I am trying to draw a number of CSS generated circles that have images as background. In my current code, the background image is set as a fixed image in the CSS code.
.container {
text-align: center;
}
.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
overflow: hidden;
text-decoration: none;
border: 0;
margin: 10px;
}
.circle:after {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: url("http://deepchains.com/images/team.png") center / cover no-repeat;
opacity: .25;
transition: .25s;
}
.circle:hover:after {
opacity: 1;
color: transparent;
}
.circle:hover {
color: transparent;
}
.ccont {
display: inline-block;
margin: 10px;
}
.ccont:hover {
color: transparent;
}
<div class="container">
<a class="circle" href="http://www.url1.html">
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text1</div>
</a>
<a class="circle" href="http://www.url2.html">
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text2</div>
</a>
</div>
Here is a sample result that I see in Chrome Browser:
My question is how to change the background images of each circle separately in the HTML code? I will have a number of these circles that I like them to be aligned and in the same line, and I want to set their background images in the HTML code and remove the background image from the CSS. How can I do that?
An easy solution is to transform your peudo element to an element and use background-image as inline style so you can easily change the image for each element and apply all the same properties as the pseudo element:
.container {
text-align: center;
}
.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
overflow: hidden;
text-decoration: none;
border: 0;
margin: 10px;
}
.circle .image {
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-position:center;
background-size:cover;
background-repeat:no-repeat;
opacity: .25;
transition: .25s;
}
.circle:hover .image {
opacity: 1;
color: transparent;
}
.circle:hover .ccont{
color: transparent;
}
.ccont {
display: inline-block;
margin: 10px;
}
<div class="container">
<a class="circle" href="http://www.url1.html">
<span class="image" style="background-image: url(http://lorempixel.com/400/300/)"></span>
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text1</div>
</a>
<a class="circle" href="http://www.url2.html">
<span class="image" style="background-image:url(https://lorempixel.com/400/200/)"></span>
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text2</div>
</a>
</div>
Simply set up the background image on the pseudo to be inherited from parent, set the size on parent to 0 to hide it there, and finally, set style="background-image: url(...)" in the markup.
Updated
You can even drop the inner div and still achieve the same effect
Stack snippet
.container {
text-align: center;
}
.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
justify-content: center;
align-items: center;
overflow: hidden;
font-weight: bold;
text-decoration: none;
border: 0;
margin: 10px;
background-size: 0; /* hide image by set its size to 0 */
}
.circle:after {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: inherit; /* inherit from parent */
background-position: center;
background-size: cover;
background-repeat: no-repeat;
opacity: .25;
transition: .25s;
}
.circle:hover:after {
opacity: 1;
}
.circle:hover {
color: transparent;
}
<div class="container">
<a class="circle" href="http://www.url1.html" style="background-image: url(https://picsum.photos/300/300?image=1070);">
This is <br>Text1
</a>
<a class="circle" href="http://www.url2.html" style="background-image: url(https://picsum.photos/300/300?image=1072);">
This is <br>Text2
</a>
</div>
Using http://jsfiddle.net/4UNuB/5/ as an example, the image has been set as background
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);
background-position: center;
background-repeat: no-repeat;
}
But, if I can't use a background image, and instead have an img src within the div itself like this
<div class="box1">
<img src="http://placehold.it/180x250">
</div>
The mask no longer covers the image, instead sitting below it.
See this fiddle http://jsfiddle.net/4UNuB/6/
But the mask is still being applied to the same place as before, so why does it move, and how to stop it moving?
Add Position Absolute and relative css for boxes.
Check The Fiddle here
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
/*background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);*/
background-position: center;
background-repeat: no-repeat;
position: relative;
}
.black-box {
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00,00,00,0.8);
width: 100%;
height: 100%;
opacity: 1.0;
transition: all 0.5s ease-in-out;
position: absolute;
top: 0;
}
You can put both in the same anchor and use positioning + z-index:
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
/*background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);
background-position: center;
background-repeat: no-repeat;*/
}
img {
position: absolute;
z-index: 0;
}
.black-box {
position: relative;
z-index: 1;
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00,00,00,0.8);
width: 100%;
height: 100%;
opacity: 1.0;
transition: all 0.5s ease-in-out;
}
.black-box:hover {
opacity: 0.0;
transition: all 0.5s ease-in-out;
}
h2 {
padding-top: 110px;
margin: 0px;
}
<div class="box1">
<a href="http://placehold.it">
<img src="http://placehold.it/180x250">
<div class="black-box">
<h2>View Details</h2>
</div>
</a>
</div>
Also, I had to remove the h2's margin.