I just made a text window which gets bigger if you hover over it (with a transition that adds more height). It basically "drops" down to the bottom and pushes away the other text. Is there any way I can make it "drop" to the bottom by 50% and "climb" up by 50%?
#tcontent {
float: left;
background-color: yellow;
height: 150px;
width: 100%;
margin-top: 100px;
}
#mcontent {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 150px;
transition: height 0.5s ease;
}
#bcontent {
float: left;
background-color: green;
height: 30px;
width: 100%;
height: 150px;
}
#mcontent:hover {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 250px;
}
<div id="main">
<div id="tcontent">
</div>
<div id="mcontent">
</div>
<div id="bcontent">
</div>
</div>
This is awkward through conventional means as content flows from left to right, top to bottom and #mcontent needs space to move into above. However, this can be achieved by using flexbox.
Add #main with display: flex; to get its children to use the flexbox model
Add flex-direction: column; to #main to make the children order from top to bottom
Add height: 550px; to #main to make it as high as the three children will be when #mcontent is expanded
Add justify-content: center; to #main to center the children in the middle
The principle behind it is that the elements are set to always be in the middle of #main. When #mcontent grows, it pushes #tcontent up and #bcontent because they have space to move into. As they are set to be centered #mcontent will stay in the middle.
#main {
display: flex;
flex-direction: column;
height: 550px;
justify-content: center;
}
#tcontent {
background-color: yellow;
height: 150px;
width: 100%;
}
#mcontent {
background-color: blue;
height: 150px;
transition: height 0.5s ease;
width: 100%;
}
#mcontent:hover {
height: 250px;
}
#bcontent {
background-color: green;
height: 150px;
width: 100%;
}
<div id="main">
<div id="tcontent"></div>
<div id="mcontent"></div>
<div id="bcontent"></div>
</div>
The reason the div pushes and moves down is the default behavior of CSS height is to increase the height to the bottom. You can use a new CSS3 feature: Transformation . Precisely, the scale() function.
CSS:
Add these lines to your style
#mcontent {
transition: all 0.5s ease;
}
#mcontent:hover {
-ms-transform: scale(1, 1.2);
-webkit-transform: scale(1, 1.2);
transform: scale(1, 1.2);
height: 185px;
}
Also, in your stylesheet you're using multiple height properties together, in a single block. That's not a good practice, try cleaning those up.
#mcontent {
height: 30px; /* this line is not necessary */
height: 150px; /* as this line overrides the first one */
}
Please see my fiddle here.
I used margin-top: -50px; and animated the margin as well. Used margin for the top expansion and let the bottom expansion still make the div below slide.
EDITED CSS
#mcontent {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 150px;
transition: height 0.5s ease, margin-top 0.5s ease;
}
#mcontent:hover {
height: 250px;
margin-top: -50px;
}
Use transform: scale(1,2); as shown in the snippet.
In your css you set height multiple times, try to avoid this. Also in the :hover declaration you only need to specify the parameters who change. So in this case only transform.
#tcontent {
float: left;
background-color: yellow;
height: 150px;
width: 100%;
margin-top: 100px;
}
#mcontent {
float: left;
background-color: blue;
width: 100%;
height: 150px;
transition: all 0.5s ease;
}
#bcontent {
float: left;
background-color: green;
width: 100%;
height: 150px;
}
#mcontent:hover {
transform: scale(1,2)
}
<div id="main">
<div id="tcontent">
</div>
<div id="mcontent">
</div>
<div id="bcontent">
</div>
</div>
If you can allow the effect to occur when hovering over #main and not just #mcontent, this works perfectly:
#main > div {
transition: all 0.5s ease;
}
#tcontent {
float: left;
background-color: yellow;
height: 150px;
width: 100%;
margin-top: 100px;
}
#mcontent {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 150px;
/* new */
position: relative;
}
#bcontent {
float: left;
background-color: green;
height: 30px;
width: 100%;
height: 150px;
transition: all 0.5s ease;
}
#main:hover #mcontent {
height: 250px;
margin-top: -50px;
}
#main:hover #tcontent {
transform: translateY(-50px);
}
Fiddle demo here.
Related
I have an image within a container. The container has rounded corners in order to make the child image circular.
There's a hover effect on the parent, but in Chrome (but not Firefox!) the effect remains when the cursor leaves the image.
Expected (Firefox):
Actual (Chrome):
Please see my demo code below:
.user {
display: inline-block;
width: 200px;
height: 200px;
object-fit: cover;
}
.image-container {
background: black;
overflow: hidden;
width: 200px;
height: 200px;
border-radius: 50%;
padding-left: 0%;
}
.image-container:hover {
cursor: pointer;
}
.image-container:hover .user {
opacity: 0.3;
transition: 0.5s;
}
<div class="image-container">
<img src="https://avatars.githubusercontent.com/u/16269580?v=4" class="user">
</div>
I'm looking to have the hover effect end immediately on leaving the "circle". Any help would be appreciated.
Try to add border-radius to image class .user too:
.user {
display: inline-block;
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 50%;
}
.image-container {
background: black;
overflow: hidden;
width: 200px;
height: 200px;
border-radius: 50%;
padding-left: 0%;
}
.image-container:hover {
cursor: pointer;
}
.image-container:hover .user {
opacity: 0.3;
transition: 0.5s;
}
<div class="image-container">
<img src="https://avatars.githubusercontent.com/u/16269580?v=4" class="user">
</div>
Im tryng to make my modal transition from bottom to top when activated, i having no luck with transform-origin: bottom, made a sample codepen
HTML
<div class="main">
<div class="hidden">HOVER</div>
</div>
css
.main{
height: 500px;
width: 500px;
background: blue;
}
.hidden{
height: 0px;
width: 300px;
background-color: red;
transform-origin: bottom;
top: 100%;
-webkit-transition: 1s;
}
.hidden:hover{
height:200px;
-webkit-transition:height 1s;
}
https://codepen.io/danielkmx/pen/OevOLW
This should work for you but this might flicker a bit.
.main{
height: 500px;
width: 500px;
background: blue;
}
.hidden{
height: 0px;
width: 300px;
background-color: red;
transform-origin: 100% 0;
transition: all 1.0s;
position: relative;
top: 200px;
}
.hidden:hover{
height:200px;
top: 0px;
transition: all 1.0s;
}
You can do it with a relative/absolute position combination for the two DIVs (parent relative, child absolute) and according position settings in relation to the bottom of the parent:
.main {
height: 500px;
width: 500px;
background: blue;
position: relative;
}
.hidden {
height: 16px;
width: 300px;
position: absolute;
left: 0;
bottom: 0;
background-color: red;
transition: 1s;
}
.hidden:hover {
height: 200px;
}
<div class="main">
<div class="hidden">HOVER</div>
</div>
I'm having some CSS issues I hope someone here can help with. I basically am trying to set a group of inline divs that slide out to the right, expanding to the width of the parent div containing them. As you can see from the jsfiddle I have (https://jsfiddle.net/0o9bw101/), the divs expand to the width of the parent div, instead of expanding only to the rightmost border of the parent div. If anyone can help I'd be quite thankful. Thank you in advance!
Here is the CSS I'm using in case you want to see it here:
.container {
width: 70%;
height: 100px;
background-color: black;
}
.greyDiv {
height: 60px;
width: 60px;
background-color: white;
border-radius: 5px;
color: white;
display: inline-block;
margin: 20px;
vertical-align: top;
color: black;
}
.greyDiv:hover {
transition: 2s;
width: 70%;
position: absolute
}
Try this
.container {
width: 70%;
height: 100px;
background-color: black;
position:relative;
overflow:hidden;
}
.greyDiv {
height: 60px;
width: 60px;
background-color: white;
border-radius: 5px;
color: white;
display: inline-block;
margin: 20px;
vertical-align: top;
}
.greyDiv:hover {
transition: 2s;
width: 100%;
position: absolute;
}
<div class='container'>
<div class='greyDiv'></div>
<div class='greyDiv'></div>
<div class='greyDiv'></div>
<div class='greyDiv'></div>
</div>
EDIT:
The trick is to add another box inside main container.
DEMO: https://jsfiddle.net/0o9bw101/3/
<div class='container'>
<div class='invisible_container'>
<div class='greyDiv'></div>
<div class='greyDiv'></div>
<div class='greyDiv'></div>
<div class='greyDiv'></div>
</div>
</div>
previous answer:
It's hard to do when you mix parent's with in % with children margins in px.
Also having parent's position set to something other than default helps a bit.
Here is working example for you:
.container {
width: 70%;
height: 100px;
background-color: black;
position: absolute;
}
.greyDiv {
height: 60px;
width: 60px;
background-color: white;
border-radius: 5px;
color: white;
display: inline-block;
margin: 20px;
margin-left: 2%;
vertical-align: top;
}
.greyDiv:hover {
transition: 2s;
width: 96%;
position: absolute
}
DEMO: https://jsfiddle.net/0o9bw101/2/
This might not be quite what you were going for, but here elements will grow to the full width of the container (left to right) regardless of it's starting position using 2 extra elements per object.
The .inner is used to grow the background to the full width
The .placeholder is used to keep the other elements from collapsing left
#keyframes grow {
from {width: 0%;}
to {width: 92%;}
}
.container {
width: 70%;
height: 100px;
position: relative;
background-color: black;
}
.greyDiv {
height: 60px;
width: 60px;
background-color: white;
border-radius: 5px;
color: black;
display: inline-block;
margin: 20px 4%;
vertical-align: top;
position: relative;
z-index: 2;
}
.inner {
width: 0%;
height: 100%;
display: none;
background-color: transparent;
position: absolute;
left: 0;
top: 0;
z-index: 1;
}
.placeholder {
display: none;
background-color: transparent;
height: 60px;
width: 60px;
margin: 20px 4%;
}
.greyDiv:hover {
width: 100%;
position: absolute;
left: 0;
margin: 20px 0;
background-color: transparent;
z-index: 4;
}
.greyDiv:hover + .placeholder {
display: inline-block;
}
.greyDiv:hover .inner {
display: inline-block;
left: 4%;
width: 100%;
background-color: white;
animation-name: grow;
animation-duration: 2s;
animation-fill-mode: forwards;
z-index: 5;
}
<div class='container'>
<div class='greyDiv'>1a<div class="inner">1x</div></div><div class="placeholder"></div>
<div class='greyDiv'>2a<div class="inner">2x</div></div><div class="placeholder"></div>
<div class='greyDiv'>3a<div class="inner">3x</div></div><div class="placeholder"></div>
<div class='greyDiv'>4a<div class="inner">4x</div></div><div class="placeholder"></div>
</div>
I've been working on an Angular plugin that uses a template. My goal is to add more padding-top to the section "loader-wrap", but when I do this, the second div called "message-wrap" is modified and moved as well.
I need add padding-top: 100px to 'loader-wrap' without moving down 'message-wrap' along with it. How do I fix this?
Basic Structure HTML
<div id="page-wrap">
<section id="loader-wrap"></section>
<section id="message-wrap"></section>
</div>
CSS
gp-splash-loader #page-wrap {
z-index: 999;
position: fixed;
background: #FFFFFF;
width: 100%;
height: 80%;
top: 10%;
margin: 0 auto;
-webkit-transition: opacity .5s;
-moz-transition: opacity .5s;
transition: opacity .5s;
-webkit-backface-visibility: hidden;
}
#media ( max-height: 735px) {
gp-splash-loader #page-wrap.opened{
height: 100%;
top: 0;
};
}
gp-splash-loader #page-wrap.closed {
opacity: 0;
}
gp-splash-loader #page-wrap.opened {
opacity: 1;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 0.5s;
}
gp-splash-loader #loader-wrap {
width: 30%;
height: 70%;
min-width: 300px;
max-width: 600px;
margin: 10px auto;
padding-top: 50px;
}
gp-splash-loader #message-wrap {
min-width: 1px;
margin: 0 auto;
height: 30%;
min-height: 30%;
}
gp-splash-loader #header-wrap {
display: inline-block;
}
check in codepen: http://codepen.io/gpincheiraa/pen/obdXEx
Here's the deal. You can't move that loader down with padding, otherwise it will affect the message. you need a different solution. try the below html/css.
Basically I set it up so the loader and the message are in a div that will be centered. then inside of that centered div, you can do whatever you want. But the loader and message will be in the middle
if you want only the loader to be centered, then you can take the message out of the 'loader-message-box' div, and apply different styles to it. I'll work up a another fiddle for that solution
https://jsfiddle.net/ahmadabdul3/huf5zjkv/ - both message and loader are centered
https://jsfiddle.net/ahmadabdul3/huf5zjkv/1/ - this one will keep the message on the bottom
code:
html
<div class='loader-message-box'>
<div class='loader-message'>
<div class='loader'>
</div>
<div class='message'>
Message
</div>
</div>
<div class='vertical-mid-hack'>
</div>
</div>
css
body, html {
height: 100%;
margin: 0;
}
.loader-message-box {
width: 100%;
height: 100%;
text-align: center;
}
.loader-message {
display: inline-block;
vertical-align: middle;
margin: 0 -2px;
}
.vertical-mid-hack {
display: inline-block;
vertical-align: middle;
margin: 0 -2px;
height: 100%;
}
.loader {
width: 100px;
height: 100px;
background-color: teal;
border-radius: 100px;
margin: 0 auto;
margin-bottom: 20px;
}
.message {
background-color: white;
border-radius: 3px;
font-family: arial;
padding: 20px 0;
margin: 0 auto;
margin-top: 20px:
}
I removed any instance of gp-splash-loader from CSS. I don't know ng but I do know gp-splash-loader is not a valid selector. Other than that, the following CSS is the important part:
CSS:
body {
margin: 0;
padding: 0;
background: slateblue;
text-align: center;
top: 0;
position: relative;
}
#loader-wrap {
width: 30%;
height: 70%;
min-width: 300px;
max-width: 600px;
margin: 10px auto;
padding-top: 100px;
position: relative;
z-index: 10;
}
#message-wrap {
min-width: 1px;
margin: 0 auto;
height: 30%;
min-height: 30%;
position: relative;
z-index: 11;
}
Added 50px padding-top
Positioned both relative (and body as well)
Made sure that one never touches the other by using different z-index
http://codepen.io/zer00ne/full/qbYMMQ/
BTW, if you want to adjust either section up or down, add top and a negative value if you want the section to go up and vice versa. ex.
#message-wrap {
min-width: 1px;
margin: 0 auto;
height: 30%;
min-height: 30%;
position: relative;
z-index: 11;
top: -100px;
}
That should place #message-wrap 100px higher.
I have this div and I want to show the title when I hover over title div. The problem is that I get the hover effect even if I hover on the edges of the div. So the div is treated as a square and not as a circle when I hover on it. This works pretty well on Firefox but not on Chrome and Safari.
Fiddle: http://jsfiddle.net/roeg629c/2/
Note: I do not want to change the aspect ratio of the image. The image should be 100% of the parent height.
HTML
<div class="video_wrap update" video_name="rikthejmna">
<div class="related img_wrap"><img src="http://img.youtube.com/vi/XyzYVpJGRG8/hqdefault.jpg"></div>
<div class="title">rikthejm na</div>
</div>
CSS
.video_wrap {
width: 232px;
height: 232px;
display: inline-block;
border-radius: 116px;
overflow: hidden;
margin: 10px;
position: relative;
z-index: 2;
}
.img_wrap img {height: 100%}
.related {height: 100%;}
.title {
position: relative;
top: -50px;
left: 0px;
background: #fff;
height: 50px;
opacity: .5;
color: #f8008c;
font-size: 12px;
text-align: center;
line-height: 50px;
overflow: hidden;
cursor: default;
transition: all .5s ease-in;
}
.title:hover {opacity: 1}
Avoid positioning of the .title, and opacity.
.video_wrap{
width: 232px;
height: 232px;
border-radius: 50%;
overflow: hidden;
margin: 10px;
}
.related {
width: 232px;
height: 232px;
position: absolute;
border-radius: 50%;
overflow: hidden;
z-index: -1;
}
.img_wrap img {
height: 100%;
}
.title{
margin: 185px 0 0;
background: rgba(255,255,255,.5);
line-height: 50px;
text-align: center;
transition: all .5s ease-in;
}
.title:hover{
background: #fff;
}
<div class="video_wrap update">
<div class="related img_wrap"><img src="http://img.youtube.com/vi/XyzYVpJGRG8/hqdefault.jpg"></div>
<div class="title">
rikthejm na
</div>
</div>