I have a header with two divs. The two divs are next to each other. I'm using bootstrap with flex box for this. I want to create a sliding effect (and zoom) when hovering over the divs. Hovering over the left div should change the width of both the left and right div.
Tricky part I'm having is that I want to add a diagonal line with the same color as the right div to create a nice look. I've tried creating that with a pseudo after on the right div but the issue is when hovering it will not move with the rest of the div. I had to give it position: absolute to display it outside the right div.
Maybe I'm doing something wrong or maybe there is a better solution. I haven't figured this one out yet.
JSfiddle
https://jsfiddle.net/aq9Laaew/235971/
.header {
z-index: 1;
height: 50vh;
position: relative;
overflow: hidden;
}
.header-img {
width: 60vw;
height: 50vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url(asset_path("bgs/bg-1.jpg"));
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
}
.header-img:hover {
transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
width: 80vw;
}
.header-content {
color: #000000;
background-color: #FFFFFF;
width: 40vw;
height: 50vh;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
overflow-x: visible;
}
.header-content:hover {
width: 80vw;
}
.overlay::after {
content: " ";
display: inline-block;
position: absolute;
width: 20%;
height: 100%;
left: 50%;
border-style: dashed;
border-width: 1em;
border-color: #000000;
}
<div class="header d-flex flex-row">
<div class="header-img"></div>
<div class="header-content">
<div class="overlay"></div>
<div class="d-flex justify-content-center">
<div class="mt-5">
<div class="text-center header-text">
<h2>Text</h2>
</div>
</div>
</div>
</div>
</div>
After some investigation I've fixed the sliding effect of the overlay. I've appended the div.overlay inside the header-content and set postion:relative on .header-content class.
.header {
z-index: 1;
height: 50vh;
position: relative;
overflow: hidden;
}
.header-img {
width: 60vw;
height: 50vh;
background-position: 75% 50%;
background-color: #EFEFEF;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
}
.header-img:hover {
transform: scale(1.1);
width: 100vw;
}
.header-content {
position: relative;
color: #000000;
background-color: #FFFFFF;
width: 40vw;
height: 50vh;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
overflow-x: visible;
}
.header-content:hover {
width: 80vw;
}
.content-text {
position: absolute;
left: -2%;
}
.overlay::after {
content: " ";
display: inline-block;
position: absolute;
width: 70%;
height: 200%;
left: -35%;
top: -60%;
background-color: #FFFFFF;
transform: rotate(10deg);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="header d-flex flex-row">
<div class="header-img"></div>
<div class="header-content">
<div class="overlay"></div>
<div class="d-flex justify-content-center">
<div class="mt-2">
<div class="text-center content-text">
<h3>text</h3>
</div>
</div>
</div>
</div>
</div>
Related
I saw many apps that can do this: When you click a menu expand icon. The whole content moves to the right or left. making some room for the menu.
Is it possible to shift the whole existing page to the right or left out of the screen, making room for the menu? If so, how can I achieve it with CSS or JavaScript?
JS Below
$(document).ready(function() {
$('.menu-switch').draggable({containment: "parent"});
$('.menu-switch').click(function(){
$('.content').toggleClass('show-menu');
});
$('.left-menu span').click(function(){
$('.content').toggleClass('show-menu');
});
})
CSS Below
.content {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-transition: -webkit-transform 0.3s linear;
transition: -webkit-transform 0.3s linear;
transition: transform 0.3s linear;
transition: transform 0.3s linear, -webkit-transform 0.3s linear;
}
.content.show-menu {
-webkit-transform: translateX(200px);
transform: translateX(200px);
-webkit-transition: -webkit-transform 0.3s linear;
transition: -webkit-transform 0.3s linear;
transition: transform 0.3s linear;
transition: transform 0.3s linear, -webkit-transform 0.3s linear;
}
.content .inner-content {
position: relative;
top: 50%;
left: 50%;
width: 60%;
padding: 20px 30px;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.content .menu-switch {
position: absolute;
z-index: 1;
left: 2%;
top: 2%;
padding: 10px 13px;
background:#999;
border-radius: 50%;
}
.content .left-menu {
text-align: center;
position: absolute;
box-sizing: border-box;
left: -200px;
width: 200px;
height: 100%;
}
.content .left-menu span {
position: absolute;
left: 2%;
top: 2%;
}
.content .left-menu .left-menu-content a {
display: block;
}
HTML Below
<div class="content">
<aside class="left-menu">
<span class="fa fa-times-circle fa-lg fa-fw fa-inverse"></span>
<div class="left-menu-header">
<h3>My Menu<h3>
<hr />
</div>
<div class="left-menu-content">
Menut Item 1
</div>
</aside>
<nav class="menu-switch">
<span class="fa fa-navicon fa-2x fa-inverse f-fw"></span>
</nav>
<div class="inner-content">
<p>Page Content Would be over here</p>
</div
</div>
You can solve the problem with an CSS animation that overlays the whole screen.
Have a look at the 9th example from Eduard L. in the link below you can pretty much do the same thing you only need to adjust the navbar how you like it and make the animation way bigger.
https://freefrontend.com/css-sidebar-menus/
I have a navigation menu that contains a burger icon made with 3 <span> that is inside another elements :
.navbar {
width: 100%;
color: #fff;
background-color: #df0024;
padding: 1% 0;
}
.tog {
display: flex;
cursor: pointer;
float: right;
width: 6%;
position: absolute;
top: 0;
right: 0;
bottom: 0;
align-items: center;
justify-content: center;
height: auto;
}
/*This is the div that contain the burger 3 layers*/
#nav-icon {
height: -webkit-fill-available;
height: -moz-fill-available;
height: -o-fill-available;
height: fill-available;
position: relative;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
cursor: pointer;
}
/*/The style of each of the burger icon 3 layers*/
#nav-icon span {
display: block;
position: absolute;
height: 3.1vh;
width: 100%;
background: white;
border-radius: 9px;
opacity: 1;
left: 0;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
#nav-icon span:nth-child(1) {
top: 0px;
}
#nav-icon span:nth-child(2) {
top: 12px;
}
#nav-icon span:nth-child(3) {
top: 24px;
}
<nav class="navbar">
<div class="logo">
<img src="" alt='Logo' />
</div>
<div id='tog' class="tog">
<label for="toggle" id='nav-icon'>
<div class='icon-container'>
<span></span>
<span></span>
<span></span>
</div>
</label>
</div>
</nav>
How to center the #nav-icon span inside the #nav-icon vertically ? All I want is centering the burger icon so I don't care of changing the other elements style that contain the burger icon.
I had to tweak a lot to make this work, but I used a nice vertical-centering trick I know involving top: 50%; plus transition: translateY(-50%);. If you apply those to a child div then it will be vertically centered within a sized parent (the parent should also have position relative or absolute).
I applied these styles to the .icon-container in your code.
.navbar{
width: 100%;
position: relative;
color: #fff;
background-color: #df0024;
padding: 1% 0;
}
.tog {
display: flex;
cursor: pointer;
float: right;
width: 6%;
position: absolute;
top: 0;
right: 0;
bottom: 0;
align-items: center;
justify-content: center;
height: auto;
}
/*This is the div that contain the burger 3 layers*/
#nav-icon{
position: absolute;
top:0;
bottom:0;
left:0;
right: 0;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
cursor: pointer;
}
.icon-container {
padding: 0 5px;
box-sizing: border-box;
position: relative;
top: 50%;
-ms-transform: translateY(-50%); /* IE 9 */
-webkit-transform: translateY(-50%); /* Chrome, Safari, Opera */
transform: translateY(-50%);
}
#nav-icon span{
display: block;
width: 100%;
height: 5px;
margin-bottom: 3px;
background: white;
border-radius: 9px;
opacity: 1;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
<nav class="navbar">
<div class="logo">
<img src="" alt='Logo'/>
</div>
<div id='tog' class="tog">
<label for="toggle" id='nav-icon'>
<div class='icon-container'>
<span></span>
<span></span>
<span></span>
</div>
</label>
</div>
</nav>
If you have nothing against flex, you may also drop the absolute positionning.
.navbar {
display: flex;
align-items: center;/* vertical-centering */
color: #fff;
background-color: #df0024;
padding: 1% 0;
/* DEMO PURPOSE ONLY to show vertical centering */
transition:0.25s;
height: 100px;
background-image:linear-gradient(to top, transparent 50%, rgba(255,255,255,0.15) 50%);
}
.navbar:hover {height:200px;}
/* end -- DEMO PURPOSE ONLY to show vertical centering */
nav a {
/* demo purpose , useless about centering */
margin: 0 0.5em;
color: white;
}
.tog {
cursor: pointer;
width: 1.5em;
margin-left: auto;/* goes all the way to the right side */
}
/*This is the div that contain the burger 3 layers*/
#nav-icon {
display: block;
transform: rotate(0deg);
transition: .5s ease-in-out;
cursor: pointer;
}
/*The style of each of the burger icon 3 layers*/
#nav-icon span {
display: block;
background: white;
margin: 0.25em 0;
border-radius: 9px;
opacity: 1;
height: 0.25em;
transform: rotate(0deg);
transition: .25s ease-in-out;
box-shadow: 1px 1px 1px;
}
<nav class="navbar">
<div class="logo">
<img src="" alt='Logo' />
</div>
another link ?
<div id='tog' class="tog">
<label for="toggle" id='nav-icon'>
<div class='icon-container'>
<span></span>
<span></span>
<span></span>
</div>
</label>
</div>
</nav>
I have an absolutely positioned image inside a relatively positioned container.
Height of image is bigger than that of the container.
I want the image to scroll up to its end using only CSS.
The catch is that height of the image could vary, so it makes sense to make sure that bottom of the image is aligned with bottom of the container once hovered.
Following is the code:
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
img:hover {
bottom: 0;
}
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
Try transition on transform
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
top: 0;
transition: transform 1s ease;
}
img:hover {
transform: translateY(-60%);
}
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
EDIT:
As the height is not set, I'd suggest a jQuery/js solution
$("img")
.mouseover(function() {
var offset = -$(this).height() + 200;
$(this).css("top", offset);
})
.mouseleave(function() {
$(this).css("top", 0);
});
body {
display: flex;
justify-content: space-around;
}
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
top: 0;
transition: top 1s ease;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
<div class="box">
<img src="https://upload.wikimedia.org/wikipedia/commons/0/0c/Vertical-Banner-EN.jpg">
</div>
You need a way to position the element equivalent to bottom: 0px, but taken for the reference the top .
If you set top: 100%, the top of the element will be at the bottom of the parent.
Then, set a transform of 100%, and the bottom will be where the top was.
Notice that this solution works for any image and container height.
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
top: 0%;
transform: translateY(0%);
transition: all 1s ease;
}
img:hover {
top: 100%;
transform: translateY(-100%);
}
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
You can have a transition between bottom: 0 and bottom: calc(100% - 18px), which is the height of the container minus the height of box2.
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
}
.box2 {
position: absolute;
height: 18px;
bottom: calc(100% - 18px);
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.box:hover .box2 {
background-color: green;
bottom: 0;
}
<div class="box">
<div class="box2">
test
</div>
</div>
You can use this, try this with working snippet,
.box{
position:relative;
display:block;
height:200px;
width:200px;
background-color:red;
transition: all 1s ease;
}
.box2{
position: absolute;
transition: all 1s ease;
}
.box:hover .box2{
background-color:green;
margin-top: 180px;
}
<div class="box">
<div class="box2">
test
</div>
</div>
I'm working on a template using Bootstrap. I have a little problem with my CSS hover. I just make a hover on div inside div.
This fiddle show my problem: https://jsfiddle.net/iklas/q5Lm7cLe/
When I hover on thumbnail the hover is showing on all parent div product-box.
I want when I hover on product-box the hover showing on just thumbnail div.
How can I solve this problem?
Just add position: relative; to .thumbnail
Updated fiddle
When You hover on thumbnail the hover is showing on all parent beacause you haven't give the css property Position:relative to .thumbnail.
.product-box a {
color: #666;
}
.product-box a:hover {
color: #666;
text-decoration: none;
}
.thumbnail {
position: relative;
}
.thumbnail:hover:before {
background-color: #000;
width: 100%;
height: 100%;
display: block;
position: absolute;
content: "";
top: 0px;
right: 0;
bottom: 0;
left: 0;
margin: auto;
opacity: 0.5;
-webkit-transition: all 0.1s ease;
-moz-transition: all 0.1s ease;
-ms-transition: all 0.1s ease;
-o-transition: all 0.1s ease;
transition: all 0.1s ease;
}
<div class="container">
<div class="row">
<div class="product-box col-md-3 col-sm-4 col-xs-12">
<a href="#">
<div class="thumbnail">
<img src="http://dummyimage.com/100x250/bdbdbd/fff&text=image" alt="...">
</div>
<div class="caption">
<h4 class="product-title">SheIn Grey Contrast Collar Long Sleeve Pleated Dress</h4>
<h4 class="brand-name pull-left"><span>By</span> Day Dresses</h4>
<h4 class="price-number pull-right">$34.56</h4>
<div class="clearfix"></div>
</div>
</a>
</div>
<!-- /.box-product -->
</div>
</div>
Your transition is not working because you haven't used this.
Try this is would work.
.thumbnail:before {
content: "";
transition: all 600ms linear 0s;
}
.thumbnail:hover:before {
background-color: #000;
width: 100%;
height: 100%;
display: block;
position: absolute;
content: "";
top: 0px;
right: 0;
bottom: 0;
left: 0;
margin: auto;
opacity: 0.5;
-webkit-transition: all 600ms ease;
-moz-transition: all 600ms ease;
-ms-transition: all 600ms ease;
-o-transition: all 600ms ease;
transition: all 600ms ease;
}
Just making this from scratch for a project of mine. I am wanting to create a hover affect on an image that then displays content about that image on top. The image would dim on the hover and the content would then display above it.
The problem that I am having is the content is going off the opacity of its parent div. How do I make the child div not get affected by the opacity property?
Here is my HTML:
<div class="featured-home-bg">
<div class="background-content">
<div class="featured-home-content">
<h2>Home Name</h2>
<p>Lorem Ipsum leo dormit tan loius ov noetermit.</p>
</div><!--- end featured-home-content --->
</div><!--- end background-content --->
</div><!--- end featured-home-bg --->
Here is my CSS:
.featured-home-bg {
background: url(../images/home-1.jpg) no-repeat;
background-size: 400px;
height: 300px;
}
.background-content {
background-color: #000;
height: 225px;
width: 400px;
opacity: 0;
}
.background-content:hover {
opacity: 0.6;
-webkit-transition: opacity 0.50s ease-in-out;
-moz-transition: opacity 0.50s ease-in-out;
-ms-transition: opacity 0.50s ease-in-out;
-o-transition: opacity 0.50s ease-in-out;
}
.featured-home-content {
width: 400px;
height: 300px;
}
.featured-home-content:hover {
cursor: pointer;
width: 400px;
height: 300px;
}
here this is the way to do that as #Henric Ã…kesson said but here with every div
html
> <div class="image"><!-- image can be placed here --> <div
> class="imagehover">text </div></div>
css
.image {
width: 400px;
height: 400px;
background-color: red;
line-height: 400px;
}
.imagehover{
width: 400px;
height: 400px;
background:;
opacity:0;
text-align: center;
font-size:20px;
transition: 0.2s ease-in-out;
}
.image:hover .imagehover {
transition: 0.2s;
opacity:1;
background-color: rgba(0, 0, 0, 0.5);
text-align:justify;
color:white;
font-size:25px;
font-weight:700;
font-family: "apercu",Helvetica,Arial,sans-serif;
text-align: center;
line-height: 400px;
}
http://jsfiddle.net/d6yhnmnf/5/
I think you would like to have the code something like this?
.featured-home-bg:hover .background-content {
opacity: 0.6;
}