I'm trying to do a thumbnail page with a hover transition that zooms and displays a description. EDIT: I do not want to use jquery.
Problem 1. The hovered div pushes the neighbor div out of alignment. All the thumbs should stay in nice neat rows.
Problem 2. The hovered div pushes the bottom of the container down.
.container {
margin-top: 75px;
text-align: center;
border: 2px solid black;
padding: 5px;
}
.tn-wrapper {
display: inline-block;
position: relative;
border: 0;
margin: 5px;
height: 150px;
overflow: hidden;
transition: all 200ms ease-in;
transform: scale(1);
}
.tn-wrapper:hover {
z-index: 1;
transition: all 200ms ease-in;
transform: scale(1.5);
height: 300px;
}
.thumb-box {
background: lightgray;
height: 150px;
width: 150px;
}
.descr-box {
background: gray;
height: 150px;
width: 150px;
}
<div class="container">
<div class="tn-wrapper">
<div class="thumb-box">
Thumb
</div>
<div class="descr-box">
Description
</div>
</div>
<div class="tn-wrapper">
<div class="thumb-box">
Thumb
</div>
<div class="descr-box">
Description
</div>
</div>
</div>
You can update your code like below. You fix the alignment of the inline-block elements (not mandatory but to make sure they will stay at the top) and you adjust the height of the description instead of the parent element.
.container {
margin-top: 75px;
text-align: center;
border: 2px solid black;
padding: 5px;
}
.tn-wrapper {
display: inline-block;
position: relative;
border: 0;
margin: 5px;
height: 150px;
transition: all 200ms ease-in;
transform: scale(1);
vertical-align:top; /* added */
}
.tn-wrapper:hover {
z-index: 1;
transition: all 200ms ease-in;
transform: scale(1.5);
}
.thumb-box {
background: lightgray;
height: 150px;
width: 150px;
}
.descr-box {
background: gray;
height: 0;
width: 150px;
overflow:hidden;
transition: all 200ms ease-in;
}
.tn-wrapper:hover .descr-box{
height: 150px;
}
<div class="container">
<div class="tn-wrapper">
<div class="thumb-box">
Thumb
</div>
<div class="descr-box">
Description
</div>
</div>
<div class="tn-wrapper">
<div class="thumb-box">
Thumb
</div>
<div class="descr-box">
Description
</div>
</div>
</div>
I'm not sure if this is the desired look you're trying to achieve but check out this example
I've added a flexbox to your container, changed your transform-origin and utilized the appropriate margins to keep your spacing.
.container {
margin-top: 75px;
text-align: center;
border: 2px solid black;
padding: 5px;
display:flex;
justify-content:center;
}
.tn-wrapper {
display: inline-block;
position: relative;
border: 0;
margin: 5px;
height: 150px;
transition: all 200ms ease-in;
transform: scale(1);
transform-origin:top;
}
.tn-wrapper:hover {
z-index: 1;
transition: all 200ms ease-in;
transform-origin:top;
transform: scale(1.5);
margin:5px 43px 305px 43px;
}
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>
So I have a border transition on hover and on active for a circular button so the border increases in size. However, the border expands downwards, pushing the button downward. Is there any way to make it so the border expands evenly outward? I've searched this site and others for solutions, and while there are similar questions, they don't answer this specifically.
Thanks!
HTML:
<center><a class="btn" href="#"></a></center
CSS:
.btn {
vertical-align: top;
transform: translateY(20px);
background-color: black;
display: inline-block;
height: 300px;
width: 300px;
border-radius: 50%;
border: 0px solid red;
transition: border-width 0.1s ease-in;
margin: 0.5em;
}
.btn:hover {
border: 20px solid red;
}
.btn:focus {
border: 75px solid red;
}
Instead of using border, you can generate a border effect by placing a pseudoelement behind the button, and transforming its scale on hover and focus as needed.
*also note that <center> is deprecated in HTML5. You can center content with CSS instead.
.btn {
display: block;
margin: 5rem auto;
position: relative;
background-color: black;
height: 300px;
width: 300px;
border-radius: 50%;
transition: border-width 0.1s ease-in;
}
.btn:before {
content: '';
display: block;
position: absolute;
background: red;
border-radius: 50%;
width: 300px;
height: 300px;
z-index: -1;
transition: all .1s ease;
}
.btn:hover:before {
transform: scale(1.1);
}
.btn:focus:before {
transform: scale(1.25);
}
<a class="btn" href="#"></a>
Is it possible to adress only the image (id doesn't work because it includes the code between the brackets), to get scaled when hovered? Div + text should stay the same size.
I tried to scale the div + text in the other way round (1/1.1=0.9). But it wobbles, when the mouse leaves the area.
.center {
position: absolute;
}
.scrolldownbutton {
background-color: green;
position: relative; /* absolute um ueber Text zu schweben*/
width: 300px;
height: 300px;
border: 1px solid black;
text-align: center;
line-height: 300px;
transition: all .5s ease;
}
.scrolldownbutton:hover {
transform: scale(1.1);
}
.rahmen {
border: 2px solid yellow;
margin: 5%;
height: 90%;
}
.rahmen:hover {
transition: all .5s ease;
transform: scale(0.9);
}
.text {
margin: -10%;
font-size: 300%;
color: white;
}
#newYork {
background-image: url('http://www.travelersjoy.com/images/planning/destinations/new-york-city/newyork1.jpg');
}
<div class="center">
<div id="newYork" class="scrolldownbutton">
<div class="rahmen">
<p class="text">New York</p>
</div>
</div>
</div>
I am having two different issues. The first is really irritating. I am attempting to align the text with the image inside of the first box, so that they are side-by-side an inline fashion. I am not sure what I am doing wrong and I do not want to use floats.
Secondly, I am attempting to get the image to transform: translate on the x-axis on hover. The thing is, I want the image to transform on the .extra-box:hover...not on the actual image, but I only want the image to move. I cannot figure this out.
What am I doing wrong?
#extra {
margin: 25px auto;
width: 460px;
height: auto;
}
.extra-box {
position: relative;
width: 40%;
padding: 8px;
border-radius: 3px;
/*border: 1px solid #739BAF;*/
border: 2px solid black;
display: inline-block;
background: none;
transition: 0.5s ease;
}
.extra-box:hover {
border: 2px solid red;
transition: 0.5s ease;
}
.extra-box:first-child {
margin-left: 0;
width: 40%;
margin-right: 10%;
}
.extra-box:last-child {
width: 40%;
}
.extra-box a {
text-decoration: none;
}
.extra-box-text {
color: black;
font-size: 1em;
display: inline-block;
width: auto;
}
.extra-box-icon img {
padding-left: 5px;
width: 15px;
height: auto;
display: inline-block;
-webkit-transition: all .5 ease-in-out;
transition: all .5 ease-in-out;
/*transform: translateX(30px);
-webkit-transform: translateX(30px);*/
}
<div id="extra"><div class="extra-box">
<a href="contact">
<div class="extra-box-text">Need help?<br>Contact Us Now</div><div class="extra-box-icon"><img src="icons/right-arrow.png"></div>
</a>
</div><div class="extra-box">
<a href="register">
<div class="extra-box-text">Need an account?<br>Register Now</div>
</a>
</div>
</div>
As other answers pointed out, you were missing a display: inline-block, but the problem was in .extra-box-icon
I have also added the transform for the image: (See the beginning of the CSS)
.extra-box-icon {
display: inline-block;
}
img {
transition: transform 1s;
}
.extra-box:hover img {
transform: translateX(-100px);
}
#extra {
margin: 25px auto;
width: 460px;
height: auto;
}
.extra-box {
position: relative;
width: 40%;
padding: 8px;
border-radius: 3px;
/*border: 1px solid #739BAF;*/
border: 2px solid black;
display: inline-block;
background: none;
transition: 0.5s ease;
}
.extra-box:hover {
border: 2px solid red;
transition: 0.5s ease;
}
.extra-box:first-child {
margin-left: 0;
width: 40%;
margin-right: 10%;
}
.extra-box:last-child {
width: 40%;
}
.extra-box a {
text-decoration: none;
}
.extra-box-text {
color: black;
font-size: 1em;
display: inline-block;
width: auto;
}
.extra-box-icon img {
padding-left: 5px;
width: 15px;
height: auto;
display: inline-block;
-webkit-transition: all .5 ease-in-out;
transition: all .5 ease-in-out;
/*transform: translateX(30px);
-webkit-transform: translateX(30px);*/
}
<div id="extra">
<div class="extra-box">
<a href="contact">
<div class="extra-box-text">Need help?
<br>Contact Us Now</div>
<div class="extra-box-icon">
<img src="icons/right-arrow.png">
</div>
</a>
</div>
<div class="extra-box">
<a href="register">
<div class="extra-box-text">Need an account?
<br>Register Now</div>
</a>
</div>
</div>
Add vertical-align:top; in .extra-box class to align it to same level.
to fix the alignment issue and if you don't want to use float, you can change the display property of .extra-box-text and extra-box-text img to inline-block
.extra-box-text, .extra-box-text img{
display:inline-block;
width: /*adjust as needed*/
}
to deal with the animation, i suggest you set the image itself as a background of .extra-box, you would then change the background-position on hover
Hope this helps
I want to have a swipeable horizontal menu on my mobile website, just like Google uses on it's results page. I created one with basic html/css, which works fine but I cannot get rid of the scroll bar...
Here's the code:
<div style=" -ms-overflow-style: -ms-autohiding-scrollbar; -webkit-user-select: none; display: block; height: 50px; overflow-y: hidden; padding: 0px; position: relative; -webkit-overflow-scrolling: touch; overflow-x: scroll;">
<div style="display: inline-block; position: relative; white-space: nowrap; overflow: hidden;">
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
</div>
</div>
Any idea?
See my menu here
See Google example here
You can make a container <div> element that holds the scrolling <div>.
This parent <div> style can be set to: oveflow:hidden and its size smaller than its child <div> -of which the style is set to overflow:scroll.
This way the scrollbar is hidden and you need not worry about doing this with JavaScript; however:
It is recommended that you create your CSS classes in either a <style> element, or a separate CSS file in which you can define these classes, and use these classes in your HTML like: <div class="menu">...
Using inline CSS as per the example above renders unmanageable code, especially in larger projects
Update
Here's a full example:
div
{
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
.scrollHider
{
display:inline-block;
width:302px;
height:162px;
overflow:hidden;
border:1px solid #AAA;
}
.menuBox
{
width:315px;
height:175px;
overflow:scroll;
white-space:nowrap;
}
.menuSection
{
width:300px;
height:160px;
display:table-cell;
overflow:hidden;
}
.menuItem
{
width:300px;
height:40px;
text-align:center;
padding:10px;
border:1px solid #AAA;
}
<div class="scrollHider">
<div class="menuBox">
<div class="menuSection">
<div class="menuItem">ITEM 1</div>
<div class="menuItem">ITEM 2</div>
<div class="menuItem">ITEM 3</div>
<div class="menuItem">ITEM 4</div>
</div>
<div class="menuSection">
<div class="menuItem">ITEM 5</div>
<div class="menuItem">ITEM 6</div>
<div class="menuItem">ITEM 7</div>
<div class="menuItem">ITEM 8</div>
</div>
</div>
</div>
Preview: (partial screenshot)
The preview (above) shows where it is scrolled to the right. Copy & paste the code above in an empty HTML file, save & open in web browser. You can also click it and use keyboard arrows to scroll if you're not using a phone/touch-screen.
First put this link in your head tags. it is from purecss.io which is a small library of css modules. I use pure in about 40% of my projects.
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
Then put this into the body of your HTML page. I would recommend separating the css and js into their own files later.
<style>
.custom-menu-wrapper {
background-color: #808080;
margin-bottom: 2.5em;
white-space: nowrap;
position: relative;
}
.custom-menu {
display: inline-block;
width: auto;
vertical-align: middle;
-webkit-font-smoothing: antialiased;
}
.custom-menu .pure-menu-link,
.custom-menu .pure-menu-heading {
color: white;
}
.custom-menu .pure-menu-link:hover,
.custom-menu .pure-menu-heading:hover {
background-color: transparent;
}
.custom-menu-top {
position: relative;
padding-top: .5em;
padding-bottom: .5em;
}
.custom-menu-brand {
display: block;
text-align: center;
position: relative;
}
.custom-menu-toggle {
width: 44px;
height: 44px;
display: block;
position: absolute;
top: 3px;
right: 0;
display: none;
}
.custom-menu-toggle .bar {
background-color: white;
display: block;
width: 20px;
height: 2px;
border-radius: 100px;
position: absolute;
top: 22px;
right: 12px;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
.custom-menu-toggle .bar:first-child {
-webkit-transform: translateY(-6px);
-moz-transform: translateY(-6px);
-ms-transform: translateY(-6px);
transform: translateY(-6px);
}
.custom-menu-toggle.x .bar {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.custom-menu-toggle.x .bar:first-child {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.custom-menu-screen {
background-color: rgba(0, 0, 0, 0.5);
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
height: 3em;
width: 70em;
position: absolute;
top: 0;
z-index: -1;
}
.custom-menu-tucked .custom-menu-screen {
-webkit-transform: translateY(-44px);
-moz-transform: translateY(-44px);
-ms-transform: translateY(-44px);
transform: translateY(-44px);
}
#media (max-width: 62em) {
.custom-menu {
display: block;
}
.custom-menu-toggle {
display: block;
display: none\9;
}
.custom-menu-bottom {
position: absolute;
width: 100%;
border-top: 1px solid #eee;
background-color: #808080\9;
z-index: 100;
}
.custom-menu-bottom .pure-menu-link {
opacity: 1;
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
-ms-transform: translateX(0);
transform: translateX(0);
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
.custom-menu-bottom.custom-menu-tucked .pure-menu-link {
-webkit-transform: translateX(-140px);
-moz-transform: translateX(-140px);
-ms-transform: translateX(-140px);
transform: translateX(-140px);
opacity: 0;
opacity: 1\9;
}
.pure-menu-horizontal.custom-menu-tucked {
z-index: -1;
top: 45px;
position: absolute;
overflow: hidden;
}
}
</style>
<div class="custom-menu-wrapper">
<div class="pure-menu custom-menu custom-menu-top">
Brand
<s class="bar"></s><s class="bar"></s>
</div>
<div class="pure-menu pure-menu-horizontal pure-menu-scrollable custom-menu custom-menu-bottom custom-menu-tucked" id="tuckedMenu">
<div class="custom-menu-screen"></div>
<ul class="pure-menu-list">
<li class="pure-menu-item">Home</li>
<li class="pure-menu-item">About</li>
<li class="pure-menu-item">Contact</li>
<li class="pure-menu-item">Blog</li>
<li class="pure-menu-item">GitHub</li>
<li class="pure-menu-item">Twitter</li>
<li class="pure-menu-item">Apple</li>
<li class="pure-menu-item">Google</li>
<li class="pure-menu-item">Wang</li>
<li class="pure-menu-item">Yahoo</li>
<li class="pure-menu-item">W3C</li>
</ul>
</div>
</div>
<script>
(function (window, document) {
document.getElementById('toggle').addEventListener('click', function (e) {
document.getElementById('tuckedMenu').classList.toggle('custom-menu-tucked');
document.getElementById('toggle').classList.toggle('x');
});
})(this, this.document);
</script>