Multiple Hover Links in CSS - html

got a row of 4 social media buttons, they all hover when I move over them. However, I cannot get the tumblr pic to work. As it stands, on the preview, it goes twitter 'linkedin - linkedin - facebook
any help? Here's the CSS code I'm using
.social a:link {
float: center;
background-image: url(../img/tumbler.png);
width: 30px;
height: 30px;
background-position: 0 -30px;
-webkit-transition: background-position .3s ease;
-moz-transition: background-position .3s ease;
-o-transition: background-position .3s ease;
transition: background-position .3s ease;
margin-left: 2px;
}
.social a:link {
float: right;
background-image: url(../img/linkedin.png);
width: 30px;
height: 30px;
background-position: 0 -30px;
-webkit-transition: background-position .3s ease;
-moz-transition: background-position .3s ease;
-o-transition: background-position .3s ease;
transition: background-position .3s ease;
margin-left: 2px;
}
.social a:first-child {
float: right;
background-image: url(../img/facebook.png);
width: 30px;
height: 30px;
background-position: 0 -30px;
-webkit-transition: background-position .3s ease;
-moz-transition: background-position .3s ease;
-o-transition: background-position .3s ease;
transition: background-position .3s ease;
margin-left: 2px;
}
.social a:last-child {
float: right;
background-image: url(../img/twitter.png);
width: 30px;
height: 30px;
background-position: 0 -30px;
-webkit-transition: background-position .3s ease;
-moz-transition: background-position .3s ease;
-o-transition: background-position .3s ease;
transition: background-position .3s ease;
}
Cheers

You are using the exact same CSS rule to do both Tumblr and linkedin. So background-image: url(../img/linkedin.png) is overriding background-image: url(../img/tumbler.png). Give each of your social icons a separate class and style that.
eg:
<div class = "social">
<a class = "twitter"></a>
<a class = "linkedin"></a>
<a class = "tumblr"></a>
<a class = "facebook"></a>
</div>
and css:
.social a:link {
float: right;
width: 30px;
height: 30px;
background-position: 0 -30px;
-webkit-transition: background-position .3s ease;
-moz-transition: background-position .3s ease;
-o-transition: background-position .3s ease;
transition: background-position .3s ease;
margin-left: 2px;
}
.social .twitter{
background-image: url(../img/twitter.png);
}
.social .linkedin{
background-image: url(../img/linkedin.png);
}
.social .tumblr{
background-image: url(../img/tumbler.png);
}
.social .facebook{
background-image: url(../img/facebook.png);
}
Also, check you've spelled "tumbler.png" correctly.

Related

Using sprites as hover backgrounds on images

I am noticing a pretty hefty amount of loading time on the first visit to a page I created. My goal was to make a "meet us" page for my wife's company where when the user hovers over a photo, a different photo + text fade in appears. I finally figured this out and I love the the effect. The columns are responsive and I have no issues other than the fact that when I first visit the page, each time I hover over an image it's taking around 1 full second to load.
I read an article about sprites, which apparently help loading times. The problem is, the article formats html/css in a specific way, much different than the way I formatted my columns. I am not eager to completely re-work my code so I was wondering if someone could explain to me how to implement sprites with the code I currently have.
Also, I am sure my code is super messy and parts of it are redundant. I'm also pretty sure I could condense all of the redundant parts I'm just not 100% on how.
Here is the code:
.meetuscontainer {
max-width: 1280px;
margin: 0 auto;
clear: both;
}
.meetusimg1 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/sLL_Proofs-141chelseaport.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg2 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/sLL_Proofs-256heatherport.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg3 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/SMLL_Proofs-312momport.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg4 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/SMLL_Proofs-287magport.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg5 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/LL_Proofs-120annieports.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg6 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/LL_Proofs-055kimports.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg7 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/sLL_Proofs-257connorport.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimg8 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/LL_Proofs-088danielleports.jpg?6924964667493824007");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.meetusimgtext {
opacity: 0;
width: 350px;
text-align: center;
font-weight: 600;
font-size: 29px;
flex-wrap: wrap;
justify-content: center;
padding-top: 350px;
color: #fff;
font-family: "Poppins", sans-serif;
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3);
}
.meetusimgtext2 {
opacity: 0;
width: 350px;
font-weight: 400;
text-align: center;
font-size: 22px;
flex-wrap: wrap;
justify-content: center;
padding-top: 8px;
color: #a1ffd2;
font-family: "Pacifico", sans-serif;
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3);
}
/* Gallery */
.gallery {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-top: 20px;
}
.meetusimg1:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/sLL_Proofs-141chelseaport2.jpg?6924964667493824007");
}
.meetusimg2:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/sLL_Proofs-268heatherport.jpg?6924964667493824007");
}
.meetusimg3:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/LL_Proofs-014momports.jpg?6924964667493824007");
}
.meetusimg4:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/SLL_Proofs-403magport.jpg?6924964667493824007");
}
.meetusimg5:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/sLL_Proofs-111annieport.jpg?6924964667493824007");
}
.meetusimg6:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/LL_Proofs-048kimports.jpg?6924964667493824007");
}
.meetusimg7:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/amLL_Proofs-271connorport.jpg?6924964667493824007");
}
.meetusimg8:hover {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/SLL_Proofs-500daniellepor2t.jpg?6924964667493824007");
}
.meetusimg1:hover .meetusimgtext {
-webkit-transition: opacity 0.6s ease-in;
-moz-transition: opacity 0.6s ease-in;
-o-transition: opacity 0.6s ease-in;
opacity: 1;
}
.meetusimg1:hover .meetusimgtext2 {
-webkit-transition: opacity 0.6s ease-in;
-moz-transition: opacity 0.6s ease-in;
-o-transition: opacity 0.6s ease-in;
opacity: 1;
}
.meetusimg2:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg2:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg3:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg3:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg4:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg4:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg5:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg5:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg6:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg6:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg7:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg7:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg8:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg8:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg9:hover .meetusimgtext {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
.meetusimg9:hover .meetusimgtext2 {
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
opacity: 1;
}
#media only screen and (min-width: 320px) and (max-width: 480px) {
.meetusimg1,
.meetusimg2,
.meetusimg3,
.meetusimg4,
.meetusimg5,
.meetusimg6,
.meetusimg7,
.meetusimg8,
.meetusimg9,
.meetusimgtext,
.meetusimgtext2 {
max-width: 280px;
}
<div class="meetuscontainer">
<div class="gallery">
<figure class="meetusimg1">
<div class="meetusimgtext">CHELSEA EARLY</div>
<div class="meetusimgtext2">Founder + Designer</div>
</figure>
<figure class="meetusimg2">
<div class="meetusimgtext">HEATHER WALKER</div>
<div class="meetusimgtext2">Founder + Designer</div>
</figure>
<figure class="meetusimg3">
<div class="meetusimgtext">KAREN SAARI</div>
<div class="meetusimgtext2">Founder + Administrator</div>
</figure>
</div>
</div>
<div class="clearfix"></div>
<div class="meetuscontainer">
<div class="gallery">
<figure class="meetusimg4">
<div class="meetusimgtext">MAGGIE HABROS</div>
<div class="meetusimgtext2">Cutter</div>
</figure>
<figure class="meetusimg5">
<div class="meetusimgtext">ANNIE MIHULKA</div>
<div class="meetusimgtext2">Serger</div>
</figure>
<figure class="meetusimg6">
<div class="meetusimgtext">KIM THEISEN</div>
<div class="meetusimgtext2">Cutter</div>
</figure>
</div>
</div>
<div class="clearfix"></div>
<div class="meetuscontainer">
<div class="gallery">
<figure class="meetusimg7">
<div class="meetusimgtext">CONNOR JONES</div>
<div class="meetusimgtext2">Top Stitcher</div>
</figure>
<figure class="meetusimg8">
<div class="meetusimgtext">DANIELLE PFANNENSTIEL</div>
<div class="meetusimgtext2">Elastics</div>
</figure>
<!--<figure class="meetusimg9">
<div class="meetusimgtext">STEPHANIE TRAWICK</div>
<div class="meetusimgtext2">Cutter</div>
</figure>-->
</div>
</div>
EDIT: Including transition
.meetusimg1 {
margin: 10px;
width: 350px;
height: 525px;
background-image: url("https://i.stack.imgur.com/54AbA.jpg");
background-repeat: no-repeat;
background-position: 0 0;
background-size: cover;
transition:background-position 1s ease;
}
.meetusimg1:hover {
background-position: -350px 0;
}
<figure class="meetusimg1">
<div class="meetusimgtext">CHELSEA EARLY</div>
<div class="meetusimgtext2">Founder + Designer</div>
</figure>
Thank you guys for all the answers. I went ahead and revised my code based off of everything you said. I think it looks a TON better. Only issue I'm having is that between h2 and P there is a strange amount of padding that I didn't tell the css to put there. I changed the padding and margin to 0px on the staff-text p and that seemed to help
/* Container */
.staff-container {
max-width: 1280px;
margin: 0 auto;
clear: both;
}
/* Gallery */
.staff-gallery {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-top: 20px;
}
/* All Staff Image Styling */
.staff-img {
margin: 10px;
width: 350px;
height: 525px;
background-repeat: no-repeat;
background-position: 0 0;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
/* All Staff Text Styling */
.staff-text {
opacity: 0;
width: 350px;
text-align: center;
flex-wrap: wrap;
justify-content: center;
color: #fff;
text-shadow: 2px 2px 2px rgba(0,0,0,0.3);
}
.staff-text h2{
padding-top: 275px;
font-family: "Poppins", sans-serif;
font-size: 27px;
text-transform: uppercase;
}
.staff-text p{
font-family: "Pacifico", sans-serif;
font-size: 22px;
}
.staff-img:hover .staff-text {
-webkit-transition: opacity 0.6s ease-in;
-moz-transition: opacity 0.6s ease-in;
-o-transition: opacity 0.6s ease-in;
opacity: 1;
}
/* Img Hover */
.staff-img:hover {
background-position: -350px 0;
}
.chelsea {
background-image: url("https://cdn.shopify.com/s/files/1/2185/4785/files/1-ChelseaSprite_f89345e7-ea1e-4186-af48-d8a957b0d8b5.jpg?5470095217541866382");
}
<div class="staff-container">
<div class="staff-gallery">
<div class="staff-img chelsea">
<div class="staff-text">
<h2>Chelsea Early</h2>
<p>Founder + Designer</p>
</div>
</div>
<div class="staff-img chelsea">
<div class="staff-text">
<h2>Chelsea Early</h2>
<p>Founder + Designer</p>
</div>
</div>
<div class="staff-img chelsea">
<div class="staff-text">
<h2>Chelsea Early</h2>
<p>Founder + Designer</p>
</div>
</div>
</div>
</div>

How can I call class into another class in css3?

I want to make an effect that would trigger my button transition when I hover the outer div box (parent) that already has its own transition. Can this be done with css or is it in need of some javascript?
My example:
.box {
height: 300px;
width: 300px;
background: #eeeeee;
float: left;
margin: 50px;
-webkit-transition: All 0.5s ease;
-moz-transition: All 0.5s ease;
-o-transition: All 0.5s ease;
-ms-transition: All 0.5s ease;
transition: All 0.5s ease;
}
.box:hover {
height: 350px;
}
#box_pic1 {
background: url(http://nicholsd.com/_Media/image-15_med.png);
background-repeat: no-repeat;
background-position: relative;
height: 196px;
width: 262px;
margin: 0 auto;
margin-top: 20px;
}
.btn_ani {
font-size: 13px;
text-align: center;
color: #ffffff;
opacity: 0.5;
width: 150px;
background: #99745c;
border:1px solid #99745c;
line-height: 35px;
transition: opacity 0.5s;
-webkit-transition: all ease 0.5s;
-moz-transition: all ease 0.5s;
-o-transition: all ease 0.5s;
-ms-transition: all ease 0.5s;
transition: all ease 0.5s;
position: absolute;
margin-left: 56px;
}
.btn_ani:hover {
background: #ffffff;
color: #99745c;
opacity: 1;
-webkit-transition: all ease 0.7s;
-moz-transition: all ease 0.7s;
-o-transition: all ease 0.7s;
-ms-transition: all ease 0.7s;
transition: all ease 0.5s;
border:1px solid #99745c;
margin-top: 80px;
}
<div class="box">
<a href="www.google.com">
<div id="box_pic1">
<div class="btn_ani">View</div>
</div>
</a>
</div>
It can be done with CSS. You could simply move the :hover state to the parent .box and the target the descendants like: .box:hover .btn_ani.
In this case elements can have their own transition value.
.box {
height: 300px;
width: 300px;
background: #eeeeee;
float: left;
margin: 50px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.box:hover {
height: 350px;
}
#box_pic1 {
background: url(http://nicholsd.com/_Media/image-15_med.png);
background-repeat: no-repeat;
background-position: relative;
height: 196px;
width: 262px;
margin: 0 auto;
margin-top: 20px;
}
.btn_ani {
font-size: 13px;
text-align: center;
color: #ffffff;
opacity: 0.5;
width: 150px;
background: #99745c;
border:1px solid #99745c;
line-height: 35px;
transition: opacity 0.5s;
/* different transition from the parent */
-webkit-transition: all ease 0.7s;
-moz-transition: all ease 0.7s;
-o-transition: all ease 0.7s;
-ms-transition: all ease 0.7s;
transition: all ease 0.7s;
position: absolute;
margin-left: 56px;
}
.box:hover .btn_ani {
background: #ffffff;
color: #99745c;
opacity: 1;
border:1px solid #99745c;
margin-top: 80px;
}
<div class="box">
<a href="www.google.com">
<div id="box_pic1">
<div class="btn_ani">View</div>
</div>
</a>
</div>
If you would like to try some jQuery, you could use a solution such as this:
$('.box').hover(function(){
$('.btn_ani').toggleClass('margin');
});
With the css:
.margin{
margin-top:80px;
}
and here is an example!

Element still thinks it's being hovered after moving from under cursor

"Solution" Edit: I ended up just changing the layout a bit to get around this issue, as shown below. The original problematic behavior was present in other browsers as well, so I simply kept the button in place instead of sliding it to the left upon opening the search box.
--------- Original Question ---------
I wasn't sure how to word my title, but let me explain my issue. Using pure CSS and HTML, I'm making an expanding search box. The problem I have is when closing the search box, if you don't move your mouse, the button will still be shown as hovered, even though it has moved. Here is my problem:
What can I do to prevent this, if possible? It just messes with the look of the animation even if you move off of it when you click. The animation is smoother than shown. Using latest Chrome on W7.
CSS:
div#nav-search {
display: inline-block;
height: 34px;
float: right;
font-size: 0;
width: 60px;
position: absolute;
top: 43px;
right: 0;
-webkit-transform: skew(-45deg);
-moz-transform: skew(-45deg);
-o-transform: skew(-45deg);
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav#header-nav.small div#nav-search {
top: 18px;
}
div#nav-search.open {
background-color: #FFBC43;
width: 95%;
}
div#nav-search-wrapper {
display: inline-block;
vertical-align: top;
height: 34px;
width: calc(100% - 60px);
margin: 0;
padding: 0;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
button#nav-search-btn {
display: inline-block;
height: 34px;
width: 60px;
border: none;
background-color: transparent;
outline: none;
cursor: pointer;
margin: 0;
padding: 0;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
button#nav-search-btn span {
-webkit-transform: skew(45deg);
-moz-transform: skew(45deg);
-o-transform: skew(45deg);
display: block;
width: 100%;
height: 100%;
background-image: url({{ 'search-gold.png' | asset_url }});
background-size: 24px;
background-position: center;
background-repeat: no-repeat;
-webkit-transition: background 0.2s ease-in-out;
-moz-transition: background 0.2s ease-in-out;
-ms-transition: background 0.2s ease-in-out;
-o-transition: background 0.2s ease-in-out;
transition: background 0.2s ease-in-out;
}
button#nav-search-btn:hover {
background-color: #FFBC43;
}
button#nav-search-btn:hover > span, div#nav-search.open > button#nav-search-btn span {
background-image: url({{ 'search-brown.png' | asset_url }});
}
HTML:
<div class="nav-right transition">
<span class="phone-number">{{ settings.company_phone }}</span>
<div id="nav-search">
<button id="nav-search-btn"><span></span></button>
<div id="nav-search-wrapper">Wrapper filler text</div>
</div>
</div>

How do I set reduced width to a div

I have 4 divs floating left next to each other with a set hover width transition, three divs are the same width but the fourth is smaller. When you hover up on the div it gets bigger and I need the rest to reduce the width automaticaly to the set reduced-width value.
Here is the code
.container1 {
position: relative;
height: 600px;
width: 29%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container1:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container1 .reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image1 {
background: url("../img/bg1.jpg");
}
.container2 {
position: relative;
height: 600px;
width: 29%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container2:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container2 .reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image2 {
background: url("../img/bg2.jpg");
}
.container3 {
position: relative;
height: 600px;
width: 29%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
border-right: #000 4px solid;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container3:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container3 .reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
#image3 {
background: url("../img/bg3.jpg");
}
.container4 {
position: relative;
height: 600px;
width: 13%;
top: 0px;
left:0%;
z-index: 999;
float: right;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container4:hover {
width: 30%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
#image4 {
background: url("../img/3.jpg");
}
And the HTML
<div class="container1 animated bounceInLeft reduced-width" id="image1">
</div>
<div class="container2 animated bounceInDown reduced-width" id="image2">
</div>
<div class="container3 animated bounceInDown reduced-width" id="image3">
</div>
<div class="container4 animated bounceInRight reduced-width" id="image4">
</div>
when you are targeting 2 classes you should do it without spaces( like you did .container1 .reduced-width it should be .container1.reduced-width)
set width in such a way that your design won't break.. like your width of all containers should be 24%(as you have 4px border too) so that total will be equal or less than 100%.
You should write least css and target more elements. like you are targeting a particular div everytime which is not advisible.. you could use reduced with class only once and it would have set the size everytime.
this could be your reduced/optimized code:
HTML:
<div class="container animated bounceInLeft" id="image1"></div>
<div class="container animated bounceInDown" id="image2"></div>
<div class="container animated bounceInDown" id="image3"></div>
<div class="container animated bounceInRight" id="image4"></div>
CSS:
.container {
position: relative;
height: 600px;
width: 24%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
background-color:red;
}
.container:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container.reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image1 {
background: red;
}
#image2 {
background: yellow;
}
#image3 {
background: green;
}
#image4 {
background: blue ;
}
Here is CodePen Link
You don't need to do all that stuff for doing what you want. You can do it without any Javascript or jQuery using just CSS3.
Wrap your divs in a container.
Apply display: flex for the container.
Apply flex: 1 1 to the children. This is important.. do not give any flex-basis.. let it default.
Give a width: 100%; to children, they will automatically grow/shrink to available space.
Apply flex: 1 1 <your-width> for :hover on children. That's it.
Demo Fiddle: http://jsfiddle.net/abhitalks/xghqmq6u/
See this snippet:
.wrap {
width: 100%;
display: flex;
flex-direction: columns;
}
.floaters {
flex: 1 1 0%;
height: 120px; width: 100%;
transition: all 500ms;
}
.floaters:hover { flex: 1 1 50%; }
.container1 { background-color: #f00;}
.container2 { background-color: #0f0;}
.container3 { background-color: #00f;}
.container4 { background-color: #ccc;}
<div class="wrap">
<div class="container1 floaters" id="image1"></div>
<div class="container2 floaters" id="image2"></div>
<div class="container3 floaters" id="image3"></div>
<div class="container4 floaters" id="image4"></div>
</div>
This is how you can fix it.
HTML (you don't need a wrapper)
<div class="container1 animated bounceInLeft" id="image1"></div>
<div class="container2 animated bounceInDown" id="image2"></div>
<div class="container3 animated bounceInDown" id="image3"></div>
<div class="container4 animated bounceInRight" id="image4"></div>
CSS
.container {
position: relative;
height: 600px;
width: 24%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
background-color:red;
}
.container:hover {
width: 35%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container.reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image1 {
background: red;
}
#image2 {
background: yellow;
}
#image3 {
background: green;
}
#image4 {
background: blue ;
}
And of course you need Javascript (Jquery here)
$('.animated').mouseenter(function(){
console.log('here');
$(this).removeClass('reduced-width').siblings('.animated').addClass('reduced-width');
}).mouseout(function(){
$('.animated').removeClass('reduced-width');
});
EDIT: now the 4th column has a smaller width
Here is an example how you could fix it: http://jsfiddle.net/intergalactic_overlords/0hLmrme4/
Html needs a wrapper. When hovering the wrapper, children (the containers) width is set to 20%. When hovering a specific container, its width is set to 40%.
<div class="container-wrap">
<div class="container container1 animated bounceInLeft reduced-width" id="image1">
</div>
<div class="container container2 animated bounceInDown reduced-width" id="image2">
</div>
<div class="container container3 animated bounceInDown reduced-width" id="image3">
</div>
<div class="container container4 animated bounceInRight reduced-width" id="image4">
</div>
</div>
CSS:
.container {
background:snow;
box-sizing:border-box;
position: relative;
height: 600px;
width: 23%;
float: left;
z-index: 99;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container-4 {
width: 21%;
}
.container-wrap:hover > div {
width: 21%;
}
.container-wrap:hover > .container4 {
width: 16%;
}
.container-wrap > .container:hover {
background: yellow;
width: 42%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container-wrap > .container4:hover {
background: yellow;
width: 37%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}

HTML elements are moving badly while animation

i have a problem, HTML elements are moving while animation, i have captured 2 pics to guess what i want...
Before animation:
http://i031.radikal.ru/1406/9a/41e9b81ddaed.png
After animation:
http://i057.radikal.ru/1406/1b/c5e3f763fd98.png
all i want is, that after "transition", elements stay on their line...
Here is some HTML and CSS code
HTML
<div id="sliderdiv">
<ul>
<li>
<div id="bullets">
<div class="bullet" id="bul1"></div>
<div class="bullet" id="bul2"></div>
<div class="bullet" id="bul3"></div>
<div class="bullet" id="bul4"></div>
<div class="bullet" id="bul5"></div>
</div>
</li>
<li>
<div id="sliderimages">
<img src="sliderimages/bilberry.png">
<img src="sliderimages/dogrose.png">
<img src="sliderimages/dryedbilberry.png">
<img src="sliderimages/dryeddogrose.png">
<img src="sliderimages/dryedherbs.png">
<img src="sliderimages/wildapple.png">
</div>
</li>
<li>
<div id="arrows">
<div id="slideup"></div>
<div id="slidedown"></div>
</div>
</li>
</ul>
CSS
#sliderdiv{
text-align: center;
padding-top: 40px;
height: 771px;
width: 100%;
}
#sliderimages{
overflow: hidden;
text-align: center;
height: 771px;
width: 1187px;
}
#sliderdiv ul li{
list-style: none;
display: inline-block;
}
#arrows{
width: 26px;
margin-left: 5px;
}
#slideup{
margin-bottom: 10px;
}
#slideup{
cursor: pointer;
width: 26px;
height: 18px;
background-image: url('slideup.png');
-webkit-transition: background-image 0.5s ease-in-out;
-moz-transition: background-image 0.5s ease-in-out;
-ms-transition: background-image 0.5s ease-in-out;
-o-transition: background-image 0.5s ease-in-out;
transition: background-image 0.5s ease-in-out;
}
#slideup:hover{
background-image: url('slideuph.png');
-webkit-transition: background-image 0.5s ease-in-out;
-moz-transition: background-image 0.5s ease-in-out;
-ms-transition: background-image 0.5s ease-in-out;
-o-transition: background-image 0.5s ease-in-out;
transition: background-image 0.5s ease-in-out;
}
#slidedown{
cursor: pointer;
overflow: hidden;
margin-bottom: 380px;
width: 26px;
height: 18px;
background-image: url('slidedown.png');
-webkit-transition: background-image 0.5s ease-in-out;
-moz-transition: background-image 0.5s ease-in-out;
-ms-transition: background-image 0.5s ease-in-out;
-o-transition: background-image 0.5s ease-in-out;
transition: background-image 0.5s ease-in-out;
}
#slidedown:hover{
background-image: url('slidedownh.png');
-webkit-transition: background-image 0.5s ease-in-out;
-moz-transition: background-image 0.5s ease-in-out;
-ms-transition: background-image 0.5s ease-in-out;
-o-transition: background-image 0.5s ease-in-out;
transition: background-image 0.5s ease-in-out;
}
.bullet{
position: relative;
background-color: #747474;
width: 10px;
height: 10px;
margin-bottom: 15px;
border-radius: 30px;
border: none;
-webkit-transition: background-color, border 0.2s ease-in-out;
-moz-transition: background-color, border 0.2s ease-in-out;
-ms-transition: background-color, border 0.2s ease-in-out;
-o-transition: background-color, border 0.2s ease-in-out;
transition: background-color, border 0.2s ease-in-out;
}
.bullet:last-child{
margin-bottom: 350px;
}
.bullet:hover{
border-left: 5px;
border: solid 5px #747474;
background-color: #eeeeee;
-webkit-transition: background-color, border 0.2s ease-in-out;
-moz-transition: background-color, border 0.2s ease-in-out;
-ms-transition: background-color, border 0.2s ease-in-out;
-o-transition: background-color, border 0.2s ease-in-out;
transition: background-color, border 0.2s ease-in-out;
}
.bullet:last-child:hover{
margin-bottom: 350px;
}
#bullets{
margin-right: 10px;
}
You can set initial value for border property to 5px solid #FFFFFF to .bullet selector. Assuming here color #FFFFFF is the background color of your page (so it looks transparent).
And when hovering over the bullets replace border shorthand property with single longhand property border-color: #747474; inside the pseudo selector :hover, while border-width and border-style will be inherited from the initial border value 5px and solid
DEMO
Try adding this to your classes:
.bullet{
position: relative;
}
.bullet:hover{
right: 5px;
top: -5px;
margin-bottom: 5px;
}