i have 2 images, and one background:
(red and brown are images)
(white is background)
When i hover on first or second image it will slide to left/right side. Like a doors in shop. Slide both in same time (no only one).
Can someone help me? Thanks.
I tried the accepted answer but it's a bit buggy (in firefox more so) if you put your cursor over the center and it bounces the sides back and forth and doesn't open. Personally I'd do something more like this.
CODEPEN TO PLAY WITH
#stage {
width: 20rem;
height: 15rem;
background: green;
border: black 1px solid;
margin: 0 auto;
position: relative;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
span {
color: white;
font-size: 150%;
}
#left-curtain, #right-curtain {
position: absolute;
top: 0;
bottom: 0;
width: 10rem;
-webkit-transition: all 1s ease;
transition: all 1s ease;
display: flex;
align-items: center;
justify-content: center;
}
#left-curtain {
background: red;
left: 0;
}
#right-curtain {
background: blue;
right: 0;
}
#stage:hover #left-curtain {
left: -10rem;
}
#stage:hover #right-curtain {
right: -10rem;
}
<div id="stage">
<span>PEEK - A - BOO!</span>
<div id="left-curtain">Mouse</div>
<div id="right-curtain">Over</div>
</div>
Here is my quick and dirty solution. It's not perfect and perhaps someone else can fine tune it - but it works. Javascript/jQuery might allow you to come up with a more complete solution.
Hope this helps.
.l,
.r {
-webkit-transition: width .35s ease-in-out;
transition: width .35s ease-in-out;
width: 200px;
height: 100px;
}
.container {
width: 400px;
}
.l {
background-color: red;
float: left;
}
.r {
background-color: brown;
float: right;
}
.container:hover div {
width: 150px;
}
<div class='container'>
<div class='l'>
</div>
<div class='r'>
</div>
</div>
Related
I am trying to create an effect when div class="container" is being hovered, a smooth upper transition occurs of another div from bottom. Only during hover, this should happen cause I want that .bottom div to be hidden. When that div is not hidden, I can see the effect as I want. But as I hide the bottom div, that hovering effect smooth transition effect cannot be seen. Check this code once.
HTML CODE
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
CSS code
.box{
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top:80px;
left:0;
/* display: none; */
}
.box:hover .bottom {
display: block;
transition: linear 0.2s;
top:55px;
}
Here is the codepen link
https://codepen.io/Biebk/pen/MWpREqb
First off, rather than display: none to hide the incoming element altogether, you can set its opacity to 0, and then when the parent is hovered, set it to 1, like so:
.bottom {
opacity: 0;
}
.box:hover .bottom {
opacity: 1;
}
I suppose that given you want an incoming "pull-up" effect on hover, you want to that element to also "pull-down" when the hover ends. You can reverse the same effect by using a :not(:hover) on the parent element:
.box:not(:hover) .bottom {
opacity: 0;
}
Also, be sure to set the transition on the non-hovered state. The following example provides the smooth transition you're looking for:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
transition: all .25s ease;
}
.box:not(:hover) .bottom {
top: 80px;
opacity: 0;
}
.box:hover .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
A secondary approach would be to place the bottom div as a sibling to the box, and use the adjacent sibling combinator to apply the hover effects:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
font-size: 20px;
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
top: 80px;
opacity: 0;
cursor: default;
transition: all .25s ease;
}
.box:hover + .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
</div>
<div class="bottom">
Everyone
</div>
Use opacity property rather than display to achieve the desired effect, then
use the following code
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
opacity: 0;
}
.box:hover .bottom{
opacity: 1;
transition: opacity 0.2s , top 1s;
top: 55px;
}
Use the following code.
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.hovered{
transition: all .2s;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
visibility: hidden;
}
.hovered:hover+.bottom {
transition: all .2s;
top: 55px;
visibility: visible;
}
<div class="box">
<div class="hovered">Hello</div>
<div class="bottom">
Everyone
</div>
</div>
I am trying to have a square-shaped div (the red box) on the page by default. When the user hover the mouse over it, a second div should display with a semi-transparent black background and some text/content. I'm trying to imitate Devon Stank's project section on his website.
The code I have right now increases the height of the default square red box and the second div doesn't cover the whole of the red box. What's wrong with the code?
Fiddle
.project-box {
position: relative;
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-o-transition: 0.5s;
-ms-transition: 0.5s;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
<div class="default-box project-box">
<div class="default-hover hover-content">hello</div>
</div>
height: 100%; won't work on the element if the parent's height isn't defined.
Also, if you stick with position: relative with a padding on the parent, you won't be able to cover it all.
If you want to cover all the .project-box (parent) no matter its padding values,
I suggest you to use an absolute positioning on its child:
(I've done it by adding the new class .veil, but it could be done within your existing class)
.project-box {
position: relative; /* ADDED so that the absolute positioning refers to this parent */
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
/* REMOVED position and sizes */
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
/* ADDED this class */
.veil {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="default-box project-box">
<!-- Added a class for the child here -->
<div class="default-hover hover-content veil">hello</div>
</div>
Hope it helps.
Here, it may help you, try it.
.project-box {
position: relative;
width: 30%;
height:100%
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
text-align:center;
padding-top: 30%;
}
I know this question has been asked before (here and here), but for some reason I can't get mine to work when using the same techniques. Basically when you hover over this,
You should get this:
By the way, if there's a simpler way to do this without loading a new image when hovering, please let me know.
Here's what I tried:
HTML
<div class="image">
<a href="#">
<img class="image" src="wp-content/themes/TheBullshitCollection/Images/bs-1.jpg">
</a>
</div>
CSS
.image {
width: 100%;
margin-right: 28px;
margin-bottom: 28px;
display: inline-block;
}
.image a:hover {
display:block;
background-image:url("/wp-content/themes/TheBullshitCollection/Images/bs-1.5.jpg");
margin-right:28px;
margin-bottom:28px;
transition: all 0.2s ease-in-out;
position: absolute;
z-index:1;
width: 100px;
height: 120px;
}
JS Fiddle Link:
https://jsfiddle.net/ot8a5oba/
You can see that the width and height is also confusing me - I'm not sure how to make sure it stays the same size, and that it appears on top. Thanks in advance!
I would do it like this using a pseudo element to apply an overlay. Simplifies things quite a bit.
.imageContainer a {
width: 100%;
display: inline-block;
position: relative;
}
.imageContainer a:after {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(139,69,19,0.5);
content: 'Buy';
display: flex;
justify-content: center;
align-items: center;
color: white;
font: 5em cursive;
opacity: 0;
transition: opacity .5s;
}
.imageContainer a:hover:after {
opacity: 1;
}
.imageContainer img {
max-width: 100%;
vertical-align: top;
}
/*
.image a:hover {
display: block;
background-image: url("http://i.imgur.com/ARiA0ua.jpg");
margin-right: 28px;
margin-bottom: 28px;
transition: all 0.2s ease-in-out;
position: absolute;
z-index: 1;
width: 100px;
height: 120px;
}
*/
<div class="imageContainer">
<a href="#">
<img class="image" src="http://i.imgur.com/F2PaGob.jpg">
</a>
</div>
So, I have a div that appears at the top of my screen, and when you hover over it, at the bottom of the screen, text appears.
I want to add another effect to the div that makes more text appear in a completely different place on the screen, while the other text stays in the same place.
Is that possible? Preferably using CSS/HTML instead of Java or anything?
You can use ~ (tilde) operator to target all your siblings (all should have the same parent) show on hover. Please have a look at the example snippet below:
body { margin: 0; }
.holder {
text-align: center;
height: 100vh;
}
.hover {
position: absolute;
top: 10%;
left: 50%;
transform: translateX(-50%);
color: red;
font-size: 30px;
font-weight: bold;
border: 2px solid red;
padding: 10px 15px;
cursor: default;
transition: all .2s linear;
}
.hover:hover {
background: rgba(255, 0, 0, 0.1);
}
.hover:hover ~ .show-text {
opacity: 1;
transition: all .2s linear;
}
.show-text {
position: absolute;
opacity: 0;
font-size: 20px;
border-bottom: 1px solid #aaa;
transition: all .2s linear;
}
.one {
bottom: 20%;
left: 20%;
}
.two {
bottom: 20%;
right: 20%;
}
<div class="holder">
<div class="hover">Hover Me!</div>
<div class="show-text one">I'm Text 1</div>
<div class="show-text two">I'm Text 2</div>
</div>
Hope this helps!
Currently I have a sidebar on my website, and when a user hovers something on the sidebar it should bring up a popover. Yet there is this really weird issue!
The sidebar has a vertical scroll bar, and when the popover comes up it will not go over the scroll bar. Here is a image of it (Please note that is not going to be the actual popover, it is just for testing):
Sorry, not sure why the text is appearing down here. Anyhow as you can see when there is a scroll bar the text will not pass through it, yet when the scroll bar is removed the text WILL pass through it. Here is all of the important CSS:
.sidebarbuttons2 {
width: 100%;
height: 5%;
margin-left: auto;
margin-right: auto;
background-color: gray;
text-align: center;
font-size: 70%;
border-bottom: 2px solid #474747;
z-index: 2;
}
.sidebarbuttons2 li .dropdownbuttonsholder {
display: none;
margin: 0;
padding: 0;
margin-left:150px;
float:left;
margin-top: -45px;
height: 0;
z-index: 3;
}
.sidebarbuttons2 li:hover .dropdownbuttonsholder {
width: 200px;
background-color: blue;
border: 1px solid black;
list-style: none;
height: 25px;
display: block;
z-index: 4000;
position: absolute;
}
#dropdownbuttonitem1 {
background-color: red;
height: 25px;
z-index: 5;
}
#dropdownbuttonitem2 {
background-color: green;
height: 25px;
z-index: 5;
}
#dropdownbuttonitem3 {
background-color: yellow;
height: 25px;
z-index: 5;
}
#dropdownbuttonitem4 {
background-color: orange;
height: 25px;
z-index: 5;
}
/*-------------------------------------------------------*/
/*Sidebar Style*/
/*-------------------------------------------------------*/
.sidebarpostinbutton {
color: orange;
font-weight: bold;
}
#sidebar {
width: 20%;
height: 1900px;
background-color: gray;
z-index: 1;
border-right: 3px solid #474747;
position: absolute;
overflow-y: scroll;
font-size: 88%;
}
#sidebar:hover {
width: 25%;
z-index: 5;
-webkit-transition: 1s linear;
-moz-transition: 1s linear;
-o-transition: 1s linear;
-ms-transition: 1s linear;
transition: 1s linear;
}
.sidebarbuttons {
width: 100%;
height: 5%;
margin-left: auto;
margin-right: auto;
background-color: gray;
text-align: center;
font-size: 70%;
line-height: 0%;
border-bottom: 2px solid #474747;
}
#sidebarbuttonlast1 {
border-bottom: 0px;
}
#sidebarscrollinformation {
display: none;
}
/*-------------------------------------------------------*/
/*Main Contents Box Style*/
/*-------------------------------------------------------*/
.maincontentssection {
background-color: lightgray;
margin-left: 20%;
height: 1900px;
position: absolute;
width: 80%;
overflow-y: scroll;
z-index: 1;
}
And then here is the important HTML:
<div id="sidebar">
<div class="col-xs-12 col-sm-6 col-md-12">
<ul class="nav sidebarbuttons2"> <!-- navbar -->
<li> <h1> Art </h1>
<ul class="dropdownbuttonsholder row">
<ul id="dropdownbuttonitem1" class="col-xs-3"> All Posts </ul>
<ul id="dropdownbuttonitem2" class="col-xs-3"> Most Popular </ul>
<ul id="dropdownbuttonitem3" class="col-xs-3"> Most Viewed </ul>
<ul id="dropdownbuttonitem4" class="col-xs-3"> Newest </ul>
</ul>
</li>
</ul>
</div>
</div>
I can not figure out why it is not going through the scroll bar. Please Help! :)
P.S. If you would like the full HTML go here: http://pastebin.com/c89M7MPk (it is a include), and the full CSS go here: http://pastebin.com/yJZp9HT2
That's just how overflow: scroll works. Even if you use overflow-x or overflow-y, you cannot mix this with overflow: visible in the same element.
The only thing you can do, is to use overflow-x: visible; overflow-y: hidden; for the CSS, and use javascript to scroll the element. Check out a library like this for the scroll: http://darsa.in/sly/
In the CSS, LINE 974 change margin-left:150px; to margin-left: 0px;