Here is my code:
#mainwrapper {
font: 10pt normal Arial, sans-serif;
height: auto;
margin: 80px auto 0 auto;
text-align: center;
width: 1000px;
}
/* Image Box Style */
#mainwrapper .box {
border: 2px solid #fff;
cursor: pointer;
height: 200px;
float: left;
margin: 0 auto;
position: relative;
overflow: hidden;
width: 400px;
background-size: cover;
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
}
#mainwrapper .box img {
width: 100%;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
#mainwrapper .box .caption {
background-color: rgba(0, 0, 0, 0.8);
position: absolute;
color: #fff;
z-index: 100;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
left: 0;
}
/** Caption 1: Simple **/
#mainwrapper .box .simple-caption {
height: 30px;
width: 200px;
display: block;
bottom: -30px;
line-height: 10pt;
text-align: center;
}
/** Simple Caption :hover Behaviour **/
#mainwrapper .box:hover .simple-caption {
-moz-transform: translateY(-100%);
-o-transform: translateY(-100%);
-webkit-transform: translateY(-100%);
opacity: 1;
transform: translateY(-100%);
}
<div id="mainwrapper">
<!-- Image Caption 1 -->
<div id="box-1" class="box">
<img id="image-1" src="http://www.sideshowtoy.com/wp-content/uploads/2016/01/marvel-deadpool-sixth-scale-hot-toys-feature-902628.jpg" />
<span class="caption simple-caption">
<p>Pool</p>
</span>
</div>
</div>
What I want to do is to set background image inside parent div to stretch.
I have tried in #mainwrapper .box img like
position:absolute;
margin: auto;
max-width: 100%;
max-height: 100%;
But it doesn't work .
Fiddle Example
a few things:
you can't have p tag inside span
use max-width:100% in your img (or width:100% if the image is smaller than the container)
use max-width over width in your #mainwrapper to avoid scrollbars, with that the container will be "resizable", so easier to work for responsive
remove background:cover, because you don't have a background at all
UPDATE
added object-fit per OP request in comment.
#mainwrapper {
font: 10pt normal Arial, sans-serif;
height: auto;
margin: 80px auto 0;
text-align: center;
max-width: 1000px;
}
/* Image Box Style */
#mainwrapper .box {
border: 2px solid #fff;
cursor: pointer;
height: 200px;
margin: 0 auto;
position: relative;
overflow: hidden;
width: 400px;
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
}
#mainwrapper .box img {
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
object-fit: cover;
height: 100%;
width: 100%
}
#mainwrapper .box .caption {
background-color: rgba(0, 0, 0, 0.8);
position: absolute;
color: #fff;
z-index: 100;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
left: 0;
}
/** Caption 1: Simple **/
#mainwrapper .box .simple-caption {
height: 30px;
width: 100%;
display: block;
bottom: -30px;
line-height: 10pt;
text-align: center;
}
/** Simple Caption :hover Behaviour **/
#mainwrapper .box:hover .simple-caption {
-moz-transform: translateY(-100%);
-o-transform: translateY(-100%);
-webkit-transform: translateY(-100%);
opacity: 1;
transform: translateY(-100%);
}
<div id="mainwrapper">
<!-- Image Caption 1 -->
<div id="box-1" class="box">
<img id="image-1" src="http://www.sideshowtoy.com/wp-content/uploads/2016/01/marvel-deadpool-sixth-scale-hot-toys-feature-902628.jpg" />
<span class="caption simple-caption">Pool</span>
</div>
<hr />
<div id="box-2" class="box">
<img id="image-2" src="//lorempixel.com/100/400" />
<span class="caption simple-caption">Pool</span>
</div>
</div>
Just set the image's width to 100%
#mainwrapper .box img {
width: 100%;
}
Fiddle
or add the background-image in css for the div.
.box {
background-image: url("http://www.sideshowtoy.com/wp-content/uploads/2016/01/marvel-deadpool-sixth-scale-hot-toys-feature-902628.jpg");
background-size:cover;
}
remove the <img> tag in your HTML if you choose this route.
Related
I'm still new in coding, so you'll see some unnecessary codes in the css..
My problem is, I want to make the background stays/static when hovered, I believe my hover style is called "slide".. But when I hover on, the background did hover too. So, I need a help on how to make the background static when hovered.
p/s: please remain the margin for avpb :)
CSS:
#avpb {
background: rgba(0, 0, 0, 0.6);
width: 160px;
height: 220px;
border: 1px solid #000000;
padding: 19.5px;
margin-top: -10px;
margin-left: 555px;
position: absolute;
}
#avp {
position: absolute;
width: 160px;
height: 220px;
}
#avp img {
position: absolute;
z-index: 0;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
-webkit-transition:all .3s ease-out;
-moz-transition:all .3s ease-out;
-ms-transition:all .3s ease-out;
-o-transition:all .3s ease-out;
transition:all .3s ease-out;
}
#avp:hover > .overlay {
opacity: 1;
width: 160px;
height: 220px
height:auto;
background: rgba(0, 0, 0, 0.6);
-webkit-transform:translate(0px,10px);
-moz-transform:translate(0px,10px);
-ms-transform:translate(0px,10px);
-o-transform:translate(0px,10px);
transform:translate(0px,10px);
}
.button {
width: 160px;
height: 220px;
position: absolute;
}
.button a {
font-family: Lato;
font-size: 10px;
letter-spacing: 1px;
width: 80px;
height: 25px;
line-height: 25px;
margin-left: auto;
margin-right: auto;
background: rgba(0, 0, 0, 0.6);
border: 1px solid #000000;
text-align: center;
text-decoration: none;
padding: 5px;
color: #ffffff !important;
display: block;
transition: 0.5s ease;
-webkit-transition: 0.5s ease;
-o-transition: 0.5s ease;
-ms-transition: 0.5s ease;
}
.button a:hover {
background: rgba(0, 0, 0, 0.6);
border: 1px solid #4cd1db;
color: #4cd1db !important;
text-decoration: none;
letter-spacing: 2px;
transition: 0.5s ease;
-webkit-transition: 0.5s ease;
-o-transition: 0.5s ease;
-ms-transition: 0.5s ease;
}
HTML:
<div id="avpb">
<div id="avp">
<img src="http://www.imvu.com/catalog/web_av_pic.php?u=87116145">
<div class="overlay">
<div class="button">
<br>
<br>
add
<br>
message
</div>
</div>
</div>
</div>
Here's a JSFiddle
You should just let the .button transform then. I added some styles to your css file, hard to explain, just try and compare it with your original code :).
#avpb {
background: rgba(0, 0, 0, 0.6);
width: 160px;
height: 220px;
border: 1px solid #000000;
padding: 19.5px;
margin-top: -10px;
margin-left: 555px;
position: absolute;
}
#avp {
position: absolute;
width: 160px;
height: 220px;
}
#avp img {
position: absolute;
z-index: 0;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-ms-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
}
.button{
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-ms-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
}
#avp:hover>.overlay {
opacity: 1;
width: 160px;
height: 220px height:auto;
background: rgba(0, 0, 0, 0.6);
}
#avp:hover>.overlay>.button {
opacity: 1;
width: 160px;
height: 220px height:auto;
-webkit-transform: translate(0px, 10px);
-moz-transform: translate(0px, 10px);
-ms-transform: translate(0px, 10px);
-o-transform: translate(0px, 10px);
transform: translate(0px, 10px);
}
.button {
width: 160px;
height: 220px;
position: absolute;
}
.button a {
font-family: Lato;
font-size: 10px;
letter-spacing: 1px;
width: 80px;
height: 25px;
line-height: 25px;
margin-left: auto;
margin-right: auto;
background: rgba(0, 0, 0, 0.6);
border: 1px solid #000000;
text-align: center;
text-decoration: none;
padding: 5px;
color: #ffffff !important;
display: block;
transition: 0.5s ease;
-webkit-transition: 0.5s ease;
-o-transition: 0.5s ease;
-ms-transition: 0.5s ease;
}
.button a:hover {
background: rgba(0, 0, 0, 0.6);
border: 1px solid #4cd1db;
color: #4cd1db !important;
text-decoration: none;
letter-spacing: 2px;
transition: 0.5s ease;
-webkit-transition: 0.5s ease;
-o-transition: 0.5s ease;
-ms-transition: 0.5s ease;
}
<div id="avpb">
<div id="avp">
<img src="http://www.imvu.com/catalog/web_av_pic.php?u=87116145">
<div class="overlay">
<div class="button">
<br>
<br>
add
<br>
message
</div>
</div>
</div>
</div>
You are transforming/translating the div to be 10 pixels down:
-webkit-transform:translate(0px,10px);
-moz-transform:translate(0px,10px);
-ms-transform:translate(0px,10px);
-o-transform:translate(0px,10px);
transform:translate(0px,10px);
Delete these and it should work fine.
i try to use zoom image(scale CSS3) animation when mouse hover the image, but i have a problem with overflow during the animation, i want use tag <img> because i want put background color besides the image(have background transparency)
this is my problem:
HTML:
<div class="thumbnail">
<div class="divIMG">
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/14182-200.png" alt="">
</div>
</div>
CSS:
.thumbnail {
margin-top: 20px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
}
.thumbnail div.divIMG {
border-radius: 50%;
border: 4px solid #08456f;
width:200px;
height:200px;
overflow:hidden;
margin: 0 auto;
}
.thumbnail img {
background-color: #c3d3de;
width: 100%;
-webkit-transition: all .7s ease-in-out;
-moz-transition: all .7s ease-in-out;
-o-transition: all .7s ease-in-out;
-ms-transition: all .7s ease-in-out;
transition: all .7s ease-in-out;
}
.thumbnail div.divIMG:hover img {
-webkit-transform:scale(1.1);
transform:scale(1.1);
}
https://jsfiddle.net/j1rdv968/
anyone know a solution?
ps. sorry my english.
You can keep the transforming image inside of the .divIMG div by giving it a position: relative;, and a higher z-index than its child image.
CSS
.thumbnail div.divIMG {
z-index: 3;
position: relative;
}
.thumbnail img {
z-index: 2;
}
.thumbnail {
margin-top: 20px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
}
.thumbnail div.divIMG {
border-radius: 50%;
border: 4px solid #08456f;
width:200px;
height:200px;
overflow:hidden;
margin: 0 auto;
z-index: 3;
position: relative;
}
.thumbnail img {
background-color: #c3d3de;
width: 100%;
-webkit-transition: all .7s ease-in-out;
-moz-transition: all .7s ease-in-out;
-o-transition: all .7s ease-in-out;
-ms-transition: all .7s ease-in-out;
transition: all .7s ease-in-out;
z-index: 2;
}
.thumbnail div.divIMG:hover img {
-webkit-transform:scale(1.1);
transform:scale(1.1);
}
<div class="thumbnail">
<div class="divIMG">
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/14182-200.png" alt="">
</div>
</div>
JSFiddle
I'm trying to put these 4 cells together and it's not working on Chrome (it used to work before, haven't changed it), but it's working on Firefox. There is space between the cells in a row when I'm using Chrome. This shouldn't happen. This is the page I'm talking about: http://pablotv.me/chetochine/novosite/pt/marketing-research/
(Unfortunately, I can't post images because of my reputation on StackOverflow, I've just signed up and I'm an amateur yet)
Here's the HTML:
<div id="mktwrapper">
<div class="row">
<div id="box-1" class="box">
<img id="image-1" src="1.png"/>
<span class="caption full-caption">
<p>Content1</p>
</span>
</div>
<div id="box-2" class="box">
<img id="image-2" src="2.png"/>
<span class="caption full-caption">
<p>Content2</p>
</span>
</div>
</div>
<div class="row">
<div id="box-3" class="box">
<img id="image-3" src="3.png"/>
<span class="caption full-caption">
<p>Content3</p>
</span>
</div>
<div id="box-4" class="box">
<img id="image-4" src="4.png"/>
<span class="caption full-caption">
<p>Content4</p>
</span>
</div>
</div>
</div>
And here's the CSS
#mktwrapper {
font: 24pt normal Arial, sans-serif;
height: auto;
margin: 0;
text-align: center;
display: table;
width: 100%;
}
#mktwrapper .row {
display: table-row;
}
#mktwrapper .box {
border: 0;
cursor: pointer;
height: 350px;
display: table-cell;
margin: 0 auto;
position: relative;
overflow: hidden;
width: 350px;
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
}
#media screen and (min-width: 0px) and (max-width: 767px) {
#mktwrapper .box {
display: block;
}
}
#mktwrapper .box img {
position: absolute;
left: 0;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
#mktwrapper .box .caption {
background-color: rgba(252,252,252,0.92);
position: absolute;
color: #111;
z-index: 100;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
left: 0;
}
#mktwrapper .box .full-caption {
width: 350px;
height: 350px;
top: -350px;
text-align: left;
padding: 15px;
}
#mktwrapper .box:hover .full-caption {
-moz-transform: translateY(100%);
-o-transform: translateY(100%);
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
Thanks in advance. :)
Not sure but it might work:
CSS : Update these code lines to your CSS.
.row {
display: inline-block;
width: 100%;
text-align: center;
margin: 0px auto;
}
.box
{
display: inline-block;
}
NOTE : If you have multiple div's with class 'row' than use inline CSS or else would effect all div containing class 'row'.
i have a slide in over an image as you can see here
http://jsfiddle.net/xt94eah2/4/
when you hover over the example image you get a caption. But, how do i put a link in it?
So only when you hover and you see the grey part with says with some more info that you can then click the image and it goes to a link for example w3schools.
i have the code here
<div class="image revealUpFull">
<img src="http://cssdeck.com/uploads/media/items/8/8NNM3Tc.png" width="150px" height="150px" />
<span class="title">Caption <br / ><br / > with some more info</span>
</div>
</div>
and the CSS
div.container {
margin: 50px auto;
width: 675px;
}
div.image {
position: relative;
overflow: hidden;
width: 260px;
height: 195px;
display: inline-block;
margin-right: 15px;
margin-bottom: 15px;
box-shadow: 0px 0px 5px 3px rgba(0,0,0,0.3);
}
img {
position: absolute;
left: 0;
top: 0;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-ms-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
}
span.title {
width: 260px;
height: 20px;
position: absolute;
background: rgba(30,30,30,0.9);
text-align: center;
padding: 5px 0 4px;
font-size: 14px;
color: white;
font-family: "Lucida Sans", "Trebuchet MS", Arial, sans-serif;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-ms-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
}
div.image.revealUpFull span {
height: 195px;
width: 260px;
bottom: -150px;
}
div.image.revealUpFull:hover img {
top: -150px;
}
div.image.revealUpFull:hover span {
bottom: 0px;
}
This is what you can do if I got it right for your question (You would like the whole slide in area to be clickable?). So you can make both span and a with full width and height of the area.
DEMO: http://jsfiddle.net/xt94eah2/7/
div.image.revealUpFull span {
height: 141px;
width: 150px;
bottom: -120px;
display: block;
}
div.image.revealUpFull span a {
display: block;
height: 100%;
width: 100%;
color: white;
}
There are a few corrections for the markup.
The last </div> is mis-matched.
The inline <img src="" width="150px" height="150px" /> is wrong, it should be width="150" height="150" without px.
I'm trying to make a simple square rotate slightly to the left when the user hovers over the element. I am rotating the element about the Y axis. When I hover over the element it looks like the left half of the element is correctly raising the hover. When you attempt to hover the right side is quirky. I know it's definitely related to something within my transform. Hoping someone with more experience will be able to spot it.
Update:
I found a similar question here, but don't know what they mean in the answer. If I remove the height/width from the container element it works. But why?
:hover works only on lower part of rotateX transformed div
HTML:
<div class='container'>
<div class='tile'>
Tile
</div>
</div>
CSS:
.tile
{
border: 1px solid black;
width: 100px;
height: 100px;
box-shadow: 2px 2px 5px #888888;
border-radius: 12px;
-moz-transition: all .5s linear;
-o-transition: all .5s linear;
-webkit-transition: all .5s linear;
transition: all .5s linear;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
position: absolute;
}
.tile:hover
{
-webkit-transform: rotateY(25deg);
transform: rotateY(25deg);
box-shadow: 10px 10px 5px #888888;
}
.container
{
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
}
http://codepen.io/cgatian/pen/lDejJ?editors=110
Change the hover from the .title to the .container. As the .title moves, the hover area change shape/location and causes the hover out.
http://jsbin.com/ripicesu/1/edit
CSS
.tile
{
border: 1px solid black;
width: 100px;
height: 100px;
box-shadow: 2px 2px 5px #888888;
border-radius: 12px;
-moz-transition: all .5s linear;
-o-transition: all .5s linear;
-webkit-transition: all .5s linear;
transition: all .5s linear;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
position: absolute;
}
li:hover .tile
{
-webkit-transform: rotateY(25deg);
transform: rotateY(25deg);
box-shadow: 10px 10px 5px #888888;
}
.container
{
position: relative;
margin: 10px auto;
width: 100px;
height: 100px;
}
li {
list-style-type: none;
display: block;
width: 100px;
height: 100px;
}
HTML
<div class='container'>
<ul>
<li><div class='tile'>Tile</div></li>
<li><div class='tile'>Tile</div></li>
<li><div class='tile'>Tile</div></li>
<li><div class='tile'>Tile</div></li>
</ul>
</div>
You can remove container, than it's working. Change .tile position to relative and float:left and you can have as many as you like.
CSS
.tile
{
position: relative;
float: left;
text-align: center;
line-height: 100px;
border: 1px solid black;
width: 100px;
height: 100px;
box-shadow: 2px 2px 5px #888888;
border-radius: 12px;
-moz-transition: all .5s linear;
-o-transition: all .5s linear;
-webkit-transition: all .5s linear;
transition: all .5s linear;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}