How can I stop animated divs from moving place - html

I have a line of 8 divs within divs on this page.
http://etreecycle.co.uk/websites/MPW/admin/
As you can see when you hover the expanding effect causes the line of divs to move place. This has only started happening since I added the images to the centre.
EDIT; I added the link at the same time as the images. This may be causing the change.
Note; the divs are made with a PHP loop, so I can't style one differently then another.
This is the basic code;
<div class="option-box">
<a href="<?php echo './?page='.$box['page'][0]; ?>">
<div class="inner">
<div class="content">
<img alt="<?php echo $box['name'][0]; ?>" src="<?php echo $box['image_URL'][0]; ?>"/>
</div>
</div>
</a>
</div>
And this is the CSS;
/*********** Option Boxes ***********/
.option-box-wrap {
position: relative;
width: 1210px;
margin: 0 auto;
}
.option-box {
width: 300px;
margin: 0 auto;
position: relative;
display: inline-block;
}
.option-box .inner {
position: relative;
padding-bottom: 30px;
height: 300px;
text-align: center;
}
.option-box .inner .content:after {
content:'';
display: block;
position: absolute;
left: 12%;
bottom: 0px;
width: 80%;
max-width: 210px;
height: 10px;
background: transparent;
border-radius: 100px/50px;
box-shadow: 0 50px 40px rgba(0,0,0,0.8);
}
.option-box .inner .content {
border: 4px solid #fff;
border-radius: 20px;
background: -webkit-linear-gradient(#8AC007 100%, #8ac007 0%, #a5e116 100%);
width: 240px;
height: 240px;
display: block;
position: relative;
margin: 0 auto;
-webkit-transition: all .2s ease;
-moz-transition: all .2s ease;
-ms-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
}
.option-box .inner .content:hover {
width: 250px;
height: 250px;
}
.option-box .inner .content img {
width: 90%;
height: 90%;
margin: 5%;
}

This is a case where float: left wins over display: inline-block. You're using inline-block in order to make your div's sit next to each other. When you hover the height changes and pushes the other elements down. If you use float: left then the elements are taken out of the flow of the document and can no longer influence each other in such a way.
/*********** Option Boxes ***********/
.option-box-wrap {
position: relative;
width: 1210px;
margin: 0 auto;
}
.option-box {
width: 300px;
margin: 0 auto;
position: relative;
float: left;
}
.option-box .inner {
position: relative;
padding-bottom: 30px;
height: 300px;
text-align: center;
}
.option-box .inner .content:after {
content:'';
display: block;
position: absolute;
left: 12%;
bottom: 0px;
width: 80%;
max-width: 210px;
height: 10px;
background: transparent;
border-radius: 100px/50px;
box-shadow: 0 50px 40px rgba(0,0,0,0.8);
}
.option-box .inner .content {
border: 4px solid #fff;
border-radius: 20px;
background: -webkit-linear-gradient(#8AC007 100%, #8ac007 0%, #a5e116 100%);
width: 240px;
height: 240px;
display: block;
position: relative;
margin: 0 auto;
-webkit-transition: all .2s ease;
-moz-transition: all .2s ease;
-ms-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
}
.option-box .inner .content:hover {
width: 250px;
height: 250px;
}
.option-box .inner .content img {
width: 90%;
height: 90%;
margin: 5%;
}
<div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/city"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/food"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/nightlife"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/sports"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/people"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/transport"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/cats"/>
</div>
</div>
</a>
</div><div class="option-box">
<a href="#">
<div class="inner">
<div class="content">
<img alt="" src="http://lorempixel.com/300/300/abstract"/>
</div>
</div>
</a>
</div>
Simply changing display: block to float: left fixes the issue. This is not the only way to fix it, just one of many. If you use this way you will want to make sure to clear your float. The clearfix method works nicely.

When you animate the height property, the size of the animated container changes, and so the entire "row" of images takes more space, which pushes the next row downwards. Have a look at this illustration (the background was colored red for clarity):
Instead of animating via width and height properties, which affect a layout change in the page, simply use the transform property, which doesn't affect the page flow:
.option-box .inner .content:hover {
-webkit-transform: scale(1.1); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: scale(1.1); /* IE 9 */
transform: scale(1.1); /* Firefox 16+, IE 10+, Opera */
}
The resulting change should look like this:

Related

How to add colored overlay effect for images with HTML and CSS [duplicate]

This question already has answers here:
How to overlay images
(11 answers)
Closed 2 years ago.
I am trying to add an overlay effect for each image on a webpage. Basically when the cursor is moved over the image, it will slightly change color. However the desired effect is not occurring. What is the best way to fix this?
Here is a picture of the webpage for context.
HTML
<div class="service-box">
<div class="single-service">
<img src="images/facials.PNG">
<div class="overlay"></div>
</div>
<div class="single-service">
<img src="images/skin_solutions.PNG">
<div class="overlay"></div>
</div>
<div class="single-service">
<img src="images/lash.PNG">
<div class="overlay"></div>
</div>
<div class="single-service">
<img src="images/microblading.PNG">
<div class="overlay"></div>
</div>
<div class="single-service">
<img src="images/eyebrow_treatment.PNG">
<div class="overlay"></div>
</div>
</div>
CSS
.service-box{
width: 80%;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
margin: auto;
}
.single-service{
flex-basis: 50%; /*get two services in 1 row*/
text-align: center;
border-radius: 7px;
margin-bottom: 20px;
color: #fff;
position: relative;
}
.single-service img{
width: 85%; /*resize image*/
border-radius: 7px;
}
.overlay{
width: 100%
height 100%;
position: absolute;
top: 0;
border-radius: 7px;
cursor: pointer;
background: linear-gradient(rgba(0,0,0,0.5),#93dced);
opacity: 0;
transition: 1s;
}
.single-service:hover .overlay{
opacity: 1;
}
This will make your images 60% transparent when hovered over.
img:hover {
background: linear-gradient(rgba(0,0,0,0.5),#93dced);
opacity: 60%;
transition: 1s;}
Your code works well, but there is a technical error in the css, in the .overlay class. You skipped it ; after width: 100%, and missed : between height: 100%.
It should be like this:
.overlay{
width: 100%;
height: 100%;
position: absolute;
top: 0;
border-radius: 7px;
cursor: pointer;
background: linear-gradient(rgba(0,0,0,0.5),#93dced);
opacity: 0;
transition: 1s;
}

How do I align a div element onto an image in a responsive matter?

I'm working on my portfolio site now. My projects are listed as clickable images, arranged into two columns. I want it that when a user hovers over an image, a solid block of color covers it with the project title in the center. Basically like this: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade.
I had it working perfectly when I used row/column css classes, but since I've found that to not be very responsive (on mobile, the first column gets stacked on top of the other, which makes sense but that's not the order I want), I aligned the images with float and padding instead. Now, the hover effect/link stretches across the entire page, instead of being contained in the image area.
Here's my code for reference:
CSS
.container {
position: relative;
}
.image {
display: block;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
height: 100%;
width: 100%;
transition: .5s ease;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 30px;
font-family: "Lato-Bold";
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
#media screen and (min-width: 1025px) {
.image {
float: left;
width: 45%;
padding-left: 40px;
padding-right: 15px;
padding-bottom: 30px;
}
}
HTML
<div class = "container">
<img src="image name" class = "image">
<div class="overlay" style = "background-color: #color;">
<div class="text">project title</div>
</div>
</div>
How can I fix this? I've tried adding display: block to the .overlay class. I've tried making the .overlay class the same size as the image. I've also tried wrapping the link around the container class instead of the other way around like it is now. Nothing happens at all. I've also tried adjusting the container size, but that shrunk the images and stacked them into 1 column :(
Read about Responsive Images and Flexbox
Try the following code.
Note: I changed the HTML structure slightly.
.container {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.thumb {
position: relative;
width: 50%;
}
.thumb img {
width: 100%;
}
.thumb:hover .overlay {
opacity: 1;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
height: 100%;
width: 100%;
transition: .5s ease;
color: #000;
background: #fff;
}
.overlay .text {
position: absolute;
top: 50%;
transform: translate(-50%);
left: 50%;
text-align: center;
}
<div class="container">
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
</div>

Can't get these rotating cubes to display side by side

I found the code here to rotating cubes, which I wanted to use to display a photo on the front side and text on the other once hovered over.
<div class='box-scene'>
<div class='box'>
<div class='front face'>
<img src='http://placehold.it/180x180/' alt=''>
</div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
<div class='box-scene'>
<div class='box'>
<div class='front face'>
<img src='http://placehold.it/180x180/' alt=''>
</div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
.box-scene {
-webkit-perspective: 700;
width: 400px;
height: 200px;
margin: auto;
z-index: 999;
}
.box-scene:hover .box {
-webkit-transform: rotateY(-90deg);
}
.box {
width: 180px;
height: 180px;
position: relative;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 0.4s ease-out;
-webkit-transform-origin: 90px 90px -90px;
/* float: left; */
margin: 30px auto;
}
.face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: visible;
-webkit-transform-origin: 0 0;
}
.front {
-webkit-transform: rotateY(0deg);
z-index: 2;
background: #d9d9d9;
}
.side {
background: #9dcc78;
-webkit-transform: rotateY(90deg);
z-index: 1;
left: 180px;
}
I've tried using display:inline, have tried putting them in separate columns using bootstrap, yet these two cubes will not line up side by side. Could anyone provide some more details on why they refuse to line up?
.box-scene css add float: left and change width to 49%;

HTML & CSS Auto height not working properly

I have a carousel with images/descriptions in it and my height:auto does not work properly. Height computed is too big
JSBin: JSBin
I can only guess that this is because my .shadow class which is relative with height 150px.
Please take a look on it.
Edit: code as requested
This is result of one item from carousel
<div class="carousel2">
<div class="carousel">
<div class="owl-carousel owl-theme" id="owl-example" style=
"opacity: 1; display: block;">
<div class="owl-wrapper-outer">
<div class="owl-wrapper" style=
"width: 4092px; left: 0px; display: block; -webkit-transform: translate3d(0px, 0px, 0px); -webkit-transition: all 200ms ease; transition: all 200ms ease;">
<div class="owl-item" style="width: 341px;">
<div class="pc">
<div class="c">
<img alt="image" src=
"http://www.ramp-alberta.org/_system/ThumbnailCache/UserFilesImageAug~16~Site~1_004jpg.300.-1.-1108757834.jpg">
<div class="shadow">
<div class="description">
Event1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is my css
.carousel2
{
overflow: hidden;
/* height:400px; */
background-color: #344754;
}
.carousel
{
width: 1364px;
float: left;
height: auto;
}
.shadow
{
position: relative;
bottom: 150px;
left: 0;
right: 0;
background: rgba(222,103,21,0.7);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#B2344855', endColorstr='#B2344855');
height: 150px;
vertical-align: middle;
z-index: 1;
width: 100%;
text-align: center;
}
.pc{
/* border: blue 1px solid; */
width: 1%;
display: table;
margin: auto;
height: auto;
overflow: hidden;
}
.c
{
overflow: hidden;
}
.description
{
padding-top: 15px;
font-family: "FSRufus";
font-size: 30px;
font-weight: bold;
color: white;
}
.owl-item
{
overflow: hidden;
}
You should give class carousel2 a min-height so that CSS will know till what it needs to scale image. Try to use exact size images to save processing time. Also remove height from class Shadow. This should help.

Firefox not displaying header correctly

I have a question regarding my previous post:
Animation stop with css3
The slider works perfect in Chrome. In firefox however it is not working properly. Does anyone here have an idea?
Slider can be found here http://jimmytenbrink.nl/slider/
It looks like there is a problem in firefox with positioning absolute + display: table-cell.
My code is as follows:
<header>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div >
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
<div>
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
</header>
And the css;
header {
margin-top: 10px;
width: 1185px;
display: table;
overflow: hidden;
background-color: #000;
height: 500px;
}
header > div {
background: url('./images/iron_man_bg.jpg');
width: 123.8px;
height: 500px;
position: relative;
-webkit-transition: width .3s;
transition: width .3s;
display: table-cell;
border: 2px solid #fff;
overflow: hidden;
}
header div:first-child {
margin-left: 0px;
}
header div:last-child{
margin-right: 0px;
}
header div:hover span {
left: 50px;
opacity: 1;
}
header > div img {
position: absolute;
left: -240px;
-webkit-transition: all .3s;
transition: all .3s;
-webkit-filter: grayscale(1);
overflow:hidden;
}
header > div span {
-webkit-transition: left .3s;
transition: left .3s;
position: absolute;
bottom: 30px;
color: white;
left: -70px;
opacity: 0;
width: 151px;
font-family: 'Fugaz One', cursive;
text-transform: uppercase;
color: #fff;
font-size: 24px;
text-shadow: 0px 0px 10px #f1f1f1;
filter: dropshadow(color=#f1f1f1, offx=0, offy=0);
}
header > div:hover {
width: 920px;
}
header div:hover img {
left: 0px;
-webkit-filter: grayscale(0);
}
Here is what works:
http://codepen.io/jeremyzahner/full/cAEbv
Basically, i added a new container inside the "div" with class .inside. On that i do width:100%; height:100; position:relative; overflow:hidden;. Plus, i did remove the fixed height on the outer divs, since the header already holds that fixed height, it is not necessary to set it again.
It is a knonw "bug" of firefox that it treats display:table-cell; divs like that. I don't think they will fix it soon. So the best workaround (at least in my experience) is another inner wrapper like here.
CSS Modification:
header > div .inside {
position:relative;
width:100%;
height:100%;
overflow:hidden;
}
header > div {
background: url('./images/iron_man_bg.jpg');
width: 123.8px;
position: relative;
-webkit-transition: width .3s;
transition: width .3s;
display: table-cell;
border: 2px solid #fff;
overflow: hidden;
}
HTML Modification:
<div>
<div class="inside">
<img src="./images/ironman.png">
<span>Ironman</span>
</div>
</div>
This was tested in actual version of Chrome and Firefox (on Ubuntu).
Hope this helps