I am having a tricky(at least for me) problem with a div which is a flip card done purely in css. The front of the card shows an image and the back has a different image and a button. The problem is due to the fluid design I had to set the padding. Which places all of the text below the div
.card {
margin: 0 auto;
position: relative;
float: left;
padding-bottom: 25%;
width: 100%;
max-width: 600px;
}
.card__front,
.card__back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.card__front,
.card__back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transition: -webkit-transform 0.7s;
transition: transform 0.7s;
}
.card__front {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
padding-top: 56.25%;
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card__back {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
padding-top: 56.25%;
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card.effect__hover:hover .card__front {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card.effect__hover:hover .card__back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
.card__text {
width: auto;
text-align: center;
height: 100%;
margin-top: -32%;
}
.button {
background-color: #000000;
text-indent: 0;
border: 1px solid #000000;
display: inline-block;
color: #ffffff;
font-family: Arial;
font-size: 21px;
font-weight: normal;
font-style: normal;
height: 69px;
line-height: 69px;
width: 200px;
text-decoration: none;
text-align: center;
opacity: 0.8;
}
.button:hover {
background: -webkit-gradient(linear, left top, left bottom, color- stop(0.05, #000000), color-stop(1, #000000));
background: -moz-linear-gradient(center top, #000000 5%, #000000 100%);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#000000');
background-color: #000000;
}
.button:active {
position: relative;
top: 1px;
}
<div class="card effect__hover">
<div class="card__front">
<div class="card__text"></div>
</div>
<div class="card__back">
<div class="card__text"> see more
</div>
</div>
</div>
<!-- /card -->
Here is the preview of the code: http://jsfiddle.net/j29mvoLm/
All I am trying to get is to center the same button in every card like div.
Is it possible to do it without using negative margin?
This should do you justice:
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
or
display: table-cell;
vertical-align: middle;
It is possible. See snippet. This answer uses nested relative and absolute positioned elements and also utilized box-sizing:border-box; and padding to maintain aspect ratio.
If you need to to set a max-width, add another wrapper element around your card and set the max-width on that element.
.card-wrapper {
margin: auto;
max-width: 600px;
}
.card {
box-sizing: border-box;
margin: auto;
padding: 28.125% 50%; /* 16:9 aspect ratio */
position: relative;
width: 100%;
}
.card__front, .card__back {
bottom: 0;
height: 100%;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
.card__front, .card__back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transition: -webkit-transform 0.7s;
transition: transform 0.7s;
}
.card__front {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card__back {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card.effect__hover:hover .card__front {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card.effect__hover:hover .card__back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
.card__text {
height: 100%;
position: relative;
text-align: center;
width: 100%;
}
.button {
background-color: #000000;
border: 1px solid #000000;
bottom: 0;
color: #ffffff;
display: block;
font-family: Arial;
font-size: 21px;
font-style: normal;
font-weight: normal;
height: 69px;
left: 0;
line-height: 69px;
margin: auto;
opacity: 0.8;
position: absolute;
right: 0;
text-align: center;
text-decoration: none;
text-indent: 0;
top: 0;
width: 200px;
}
.button:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #000000), color-stop(1, #000000) );
background:-moz-linear-gradient( center top, #000000 5%, #000000 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#000000');
background-color:#000000;
}
.button:active {
position:relative;
top:1px;
}
<div class="card-wrapper">
<div class="card effect__hover">
<div class="card__front">
<div class="card__text"></div>
</div>
<div class="card__back">
<div class="card__text"> see more </div>
</div>
</div><!-- /card -->
</div>
Related
I currently doing an Image galery, but I don't like the current design.
I'm looking to use a Modern-Card to show the image and when hover, shows the text linked to that image (either transparent or on a dark background).
Each methode I tried, the image just take the place of the darkbackground and the hover doesn't work anymore.
or disalign to it.
css :
.card {
-background: linear-gradient(to left, #f7ba2b 0%, #ea5358 100%);
width: 190px;
height: 254px;
padding: 5px;
border-radius: 1rem;
overflow: visible;
background: #f7ba2b;
background: var(--background);
position: relative;
z-index: 1;
}
.card::after {
position: absolute;
content: "";
top: 30px;
left: 0;
right: 0;
z-index: -1;
height: 100%;
width: 100%;
transform: scale(0.8);
filter: blur(25px);
background: #f7ba2b;
background: var(--background);
transition: opacity .5s;
}
.card-info {
\--color: #181818;
background: var(--color);
color: var(--color);
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
overflow: visible;
border-radius: .7rem;
}
.card .title {
font-weight: bold;
letter-spacing: .1em;
}
/*Hover*/
.card:hover::after {
opacity: 0;
}
.card:hover .card-info {
color: #f7ba2b;
transition: color 1s;
}
Html :
<div class="card">
<div class="card-info">
<p class="title">Magic Card</p>
</div>
</div>
from this website : https://uiverse.io/alexruix/heavy-elephant-39
Adding a in between the div and adjusting some css
I want to insert the image with a border that isn't overlapping the image since I want to see 100% of it. While being able to hover and see the customize text of each one.
I think this is what you mean.
#edit
I change from background-size: 190px 254px; to background-size: 180px 244px;
.card {
--background: linear-gradient(to left, #f7ba2b 0%, #ea5358 100%);
width: 190px;
height: 254px;
padding: 5px;
border-radius: 1rem;
overflow: visible;
background: #f7ba2b;
background: var(--background);
position: relative;
z-index: 1;
}
.card::after {
position: absolute;
content: "";
top: 30px;
left: 0;
right: 0;
z-index: -1;
height: 100%;
width: 100%;
transform: scale(0.8);
filter: blur(25px);
background: #f7ba2b;
background: var(--background);
transition: opacity .5s;
}
.card-info {
--color: #181818;
background: var(--color);
background-image: url('https://images.pexels.com/photos/337909/pexels-photo-337909.jpeg?auto=compress&cs=tinysrgb&w=1600');
background-size: 180px 244px;
background-repeat: no-repeat;
background-position-x: center;
background-position-y: center;
color: var(--color);
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
overflow: visible;
border-radius: .7rem;
}
.card .title {
font-weight: bold;
letter-spacing: .1em;
opacity:0;
}
/*Hover*/
.card:hover::after {
opacity: 0;
}
.card:hover .title {
color: #f7ba2b;
transition: color 1s, opacity 1s;
opacity:1;
}
<div class="card">
<div class="card-info">
<p class="title">Magic Card</p>
</div>
</div>
I'm trying to make a dropdown menu with mouse hover effects, using the label element.
When tag arrow shape slides on the menu image, it has an unexpected gap.
.mask {
width: 100%;
height: 100%;
position: absolute;
transform: translateX(-120%);
top: 0;
background-color: rgba(255,255,255,0.8);
-webkit-transition: all 0.6s ease;
transition: all 0.6s ease;
display: flex;
justify-content: flex-end;
align-items: center;
}
.mask:before {
content: "";
position: absolute;
top: 0%;
left: 100%;
margin-top: 0px;
width: 20%;
height: 100%;
background:
linear-gradient(to bottom left, transparent 50%, rgba(255,255,255,0.8) 51%) no-repeat top left/30% 50%,
linear-gradient(to top left, transparent 50%, rgba(255,255,255,0.8) 51%) no-repeat bottom left/30% 50%;
}
jsfiddle
I hope this helps someone.
Do it differently using clip-path
.testmenu {
max-width: 100%;
margin-bottom: 2vh;
}
.testmenu a {
display: block;
text-decoration: none;
color: transparent;
padding-top: calc(100%*168/1218);
}
label {
display: block;
margin: 0;
line-height: 1;
color: #fff0;
cursor: pointer;
width: 100%;
padding-top: calc(100%*200/1218);
background-position: left top;
background-repeat: no-repeat;
background-size: 100% auto;
}
label[for="testmenu_bar01"] {
background-image: url(https://placehold.jp/1218x218.png);
}
input {
display: none;
}
.testmenu ul {
margin: 0;
padding: 0;
background: #f4f4f4;
list-style: none;
}
.testmenu li {
height: 0;
overflow: hidden;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
background-size: contain;
}
.testmenu li.testmenu01-li-01 {
background-image: url("https://placehold.jp/1218x168.png");
background-position: left top;
background-repeat: no-repeat;
background-size: 100% auto;
}
.testmenu li.testmenu01-li-02 {
background-image: url("https://placehold.jp/1218x168.png");
background-position: left top;
background-repeat: no-repeat;
background-size: 100% auto;
}
#testmenu_bar01:checked~#links01 li {
height: 0;
padding-bottom: calc(100%*168/1218);
opacity: 1;
}
#testmenu_bar01:checked+#links01 li.testmenu01-li-01 {
margin-top: 2vh;
}
.sizing-mask {
position: relative;
overflow: hidden;
}
.mask {
width: 100%;
height: 100%;
position: absolute;
transform: translateX(-120%);
top: 0;
background-color: rgba(255, 255, 255, 0.8);
transition: all 0.6s ease;
display: flex;
justify-content: flex-end;
align-items: center;
clip-path:polygon(0 0,90% 0%, 100% 50%, 90% 100%,0% 100%);
}
.mask:after {
content: "";
width: 10%;
height: 100%;
}
.testmenu:hover .mask {
transform: translateX(-61%);
border-right: hidden;
}
<div id="onlineshop" class="testmenu">
<div class="sizing-mask">
<div class="mask">
<div class="test-caption">
<p style="color: rgba(0,0,0,1);font-size: 1vw;text-transform: inherit;letter-spacing: 1px;" class="eihe-title">text<span class="break"></span>text</p>
</div>
</div>
<label for="testmenu_bar01"></label>
</div>
<input type="checkbox" id="testmenu_bar01" class="accordion">
<ul id="links01">
<li class="testmenu01-li-01">
</li>
<li class="testmenu01-li-02">
</li>
</ul>
</div>
I have a div with a background image, what I would like to do, is when I hover over it, the hidden part of background-image to display like in the example below:
My jsfiddle example:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
}
body {
text-align: center;
}
<div class="test">
</div>
As you can see, in my example the image is just getting larger, instead I want to display another 20px of the image (without compromising border-radius).
Example with one html element:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
background-size: 140px;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
transform-origin: center center;
}
.test:hover{
width: 90px;
height: 90px;
margin-left: -10px;
margin-top: -10px;
}
body {
text-align: center;
}
<div class="test">
</div>
Example with clip-path and shape-inside:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
background-size: cover;
shape-inside: circle(30% at 50% 50%);
clip-path: circle(30% at 50% 50%);
-webkit-clip-path: circle(30% at 50% 50%);
width: 70px;
height: 70px;
background-position: center;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
transform-origin: center center;
}
.test:hover{
shape-inside: circle(50% at 50% 50%);
clip-path: circle(50% at 50% 50%);
-webkit-clip-path: circle(50% at 50% 50%);
}
body {
text-align: center;
}
<div class="test">
</div>
you might oversize a bit the background image
(background-size:auto 90px;) and add some padding and reset position on hover (.test:hover{padding:10px; margin:-10px;})
those rules are suppose to be understood by most of actual browsers if not all.
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size:auto 90px;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
padding:10px;
margin:-10px;;
}
body {
text-align: center;
}
<div class="test">
</div>
another possibility is to use an inset shadow
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: auto 90px;
width: 90px;
height: 90px;
/* hide buggy ff render */
background-clip: content-box;
padding: 1px;
/* end fix ff */
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 90px;
box-shadow: inset 0 0 0 10px white;
}
.test:hover {
box-shadow: inset 0 0 0 0px white;
}
body {
text-align: center;
}
<div class="test">
</div>
There is also : padding, box-sizing and background-clip
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) ;
background-size: auto 90px;
width: 90px;
height: 90px;
padding: 10px;
background-clip:content-box;
box-sizing:border-box;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 90px;
}
.test:hover {
padding:0px;
}
/* show transparency */
html {
min-height:100%;
text-align: center;
background:linear-gradient(45deg, gray, yellow,purple,lime,pink,turquoise, gray, yellow,purple,lime,pink,turquoise);
}
<div class="test"></div>
You are missing to remove border-radius property on the hover event:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
border-radius: 0px;
}
body {
text-align: center;
}
<div class="test">
</div>
How to set text and background on this div straight? The transform property is making it curved.
#paralelogram {
margin-left: 190px;
width: 200px;
height: 80px;
transform: skew(-30deg);
background-image: url('http://lorempixel.com/200/80/animals/8/');
position: relative;
overflow: hidden;
}
#cena {
font-size: 20px;
font-family: monospace;
font-weight: bold;
text-align: center;
vertical-align: middle;
position: absolute;
margin-left: 35px;
margin-top: 25px;
}
<div class="col-xs-12 volks">
<div id="paralelogram">
<p id="cena">136,380 Kn</p>
</div>
</div>
Use a pseudo for the image and then reverse the skew on it and the p with transform: skew(30deg);
#paralelogram {
margin-left: 190px;
width: 200px;
height: 80px;
transform: skew(-30deg);
position: relative;
overflow: hidden;
background: gray;
}
#paralelogram:before {
content: '';
width: 240px;
height: 100%;
top: 0;
left: -20px;
transform: skew(30deg);
background-image: url('http://lorempixel.com/240/80/animals/8/');
background-repeat: no-repeat;
position: absolute;
}
#cena {
font-size: 20px;
font-family: monospace;
font-weight: bold;
text-align: center;
vertical-align: middle;
position: absolute;
margin-left: 35px;
margin-top: 25px;
transform: skew(30deg);
}
<div class="col-xs-12 volks">
<div id="paralelogram">
<p id="cena">136,380 Kn</p>
</div>
</div>
An alternative idea is to use clip-path to mask out the parallelogram shape rather than transform:skew. One current caveat is limited browser compatibility.
My example is based on Harry's answer to "Shape with a slanted side (responsive)":
#parallelogram {
position: relative;
width: 240px;
height: 80px;
line-height: 80px;
text-align: center;
color: red;
background-color: grey;
background-image: url(http://lorempixel.com/g/240/80/);
-webkit-clip-path: polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%);
clip-path: polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%);
}
<div id="parallelogram">136,380 Kn</div>
I have one issue in current project. I am applying background image in one div and also set opacity over it using :after.. Inside it, I have taken one another div which has border & content but I need to highlight middle section without opacity using same background image.
Sample Screenshot
.first_resorts_list_right { float: left; width: 434px; overflow: hidden; height: 477px; background-size: cover!important; background: no-repeat; padding: 70px; position: relative; background-image: url(http://s17.postimg.org/fa4ru3hm7/test.jpg); }
.resort-info { border: 10px solid #fff; padding: 20px; text-align: center; color: #000; font-size: 40px; }
.bannerimage2 { display: none; }
.expose { position: relative; z-index: 99999; }
.overlay-img { background: rgba(255,255,255,0.3); width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 99998; }
<div class="first_resorts_list_right">
<div class="resort-info expose">Content</div>
<div class="overlay-img"></div>
</div>
I made an alternative version, with divs wraping divs (plus sharing the same background values) instead of use :after
body {
width:100%;
height: 100vh;
margin: 0px;
font-family: arial, sans-serif;
}
#container {
width:100%;
height:100%;
position: relative;
}
#big {
top:0;
left:0;
width:100%;
height: 100%;
background-image: url("http://i.imgur.com/wvIxNg1.jpg");
background-size: 100vw 100vh;
background-repeat: no-repeat;
background-position: center;
position: relative;
-webkit-filter: blur(5px); /* Chrome, Safari, Opera */
filter: blur(5px);
}
#small {
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
width: 70%;
height: 70%;
outline: 4px solid white;
left: 0;
right: 0;
margin: auto;
background-image: url("http://i.imgur.com/wvIxNg1.jpg");
background-size: 100vw 100vh;
background-position: center;
background-repeat: no-repeat;
text-align: center;
color: white;
-webkit-filter: contrast(120%); /* Chrome, Safari, Opera */
filter: contrast(120%);
}
#white {
width:100%;
height: 100%;
background-color: white;
opacity: 0.1;
}
h1 {
font-weight: 100;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
left: 0;
right: 0;
margin: auto;
letter-spacing:8px;
}
<div id=container>
<div id=big>
<div id=white></div>
</div>
<div id=small><h1>FOCUS</h1></div>
</div>