I have a Teaser with a "toggle"-Animation, as can be seen on JSFiddle or below:
.ax {
height:60px;
width:150px;
background:gold;
}
.caption {
position: absolute;
left:0;
top: 35%;
overflow: hidden;
right: 0;
background-color: rgba(24,88,140,0.7);
width: 100%;
height: 52px;
z-index: 2;
-o-transition: 500ms;
-webkit-transition: 500ms;
-moz-transition: 500ms;
-ms-transition: 500ms;
transition: 500ms;
font-weight: lighter;
padding: 10px;
color: #fff;
}
a.link{
color: #fff;
overflow: hidden;
width: 80%;
margin-bottom: 30px;
font-weight: lighter;
font-size: 16px;
line-height: 22px;
}
.caption:hover {
height: 100%;
top: 0;
}
.box {
position:relative;
width:250px;
height:200px;
}
/*TABLE CELL METHOD*/
.caption2 {
position: absolute;
left:0;
top: 35%;
overflow: hidden;
right: 0;
background-color: rgba(24,88,140,0.7);
width: 100%;
height: 52px;
z-index: 2;
-o-transition: 500ms;
-webkit-transition: 500ms;
-moz-transition: 500ms;
-ms-transition: 500ms;
transition: 500ms;
font-weight: lighter;
padding: 10px;
color: #fff;
display:table;
}
.caption2:hover {
height: 100%;
top: 0;
}
a.link2{
display:table-cell;
vertical-align: middle;
overflow: hidden;
width: 80%;
margin-bottom: 30px;
font-weight: lighter;
font-size: 16px;
line-height: 22px;
}
<div class="box">
<div class="caption">
Lorem Ipsum blabla bla blahah ipsum lorem blablablahh
<p class="captiontext">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
</div>
</div><br><br
<br><br>
table cell method (div.caption2 display:table and a.link display:table-cell + vertical-algin:middle)
<br><br>
<div class="box">
<div class="caption2">
<a class="link2" href="#">Lorem Ipsum blabla bla blahah ipsum lorem blablablahh</a>
<p class="captiontext">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
</div>
</div>
I want to align the link in the vertical center of the blue box. The link can be a single line or two lines (at most), but it should always be centered vertically.
The CSS property lineheight doesn't work with two line links, whereas the table(-cell)-method also doesn't work (see above).
Is there any way to center both one and two line links in my box?
The display type "Flexbox" may be useful for this. Apply this CSS to the parent of the child you want centered:
display: flex;
flex-direction: column;
justify-content: center;
To verticly center any element, you can apply this style:
.element
{
position: relative;
top: 50%;
transform: translateY(-50%);
}
You will have to replace your table cells with columns in order to replicate your current styles. Credit to Sebastian Ekstrom for the solution.
Another way is vertical-align on pseudoelement:
https://codepen.io/darxide/pen/xRmYdQ
<div class="block" style="height: 300px;">
<div class="centered">
vertical center
</div>
</div>
.block:before {
content: ' ';
display: inline-block;
height: 100%;
vertical-align: middle;
}
.centered {
display: inline-block;
vertical-align: middle;
}
Related
I'm beginner to CSS & HTMl, and for now I am practicing on templates, i wanted to make a zoom effect using transform scale and overflow hidden (without overflowing the image borders, as in Snapshot Template), i made transform scale JSFiddle, but i didn't manage to make a trick and make zoom effect, can anyone help me?
.gallery-grid img {
-webkit-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
width: 100%;
height: 100%;
overflow: hidden;
}
Wrap every image into a container div and give overflow: hidden to it
<div class="image-container">
<img src="https://i.ibb.co/G9CYqz6/01.jpg">
</div>
<div class="image-container">
<img src="https://i.ibb.co/pbjtTMD/05.jpg">
</div>
<div class="image-container">
<img src="https://i.ibb.co/ckv3dPy/09.jpg">
</div>
<div class="image-container">
<img src="https://i.ibb.co/p0kYsQR/02.jpg">
</div>
...
and
.image-container {
overflow: hidden
}
You can not apply overflow: hidden on an img.
You should apply it to the container which you do not want it to bleed out of.
you may use z-indexand position , so scaled element remains under others. Also lay theme all the way throught and all the way down, overflow on the container will be hidding what overflows from the top and the bottom of itself.
To avoid to deal with this this way, wrap each image in a container , so overflow works for each of them.
Demo from your HTML and CSS updated
https://jsfiddle.net/c5ae48vL/
modification made on lines about z-index and container grid-column and height:
// modifications made
//line 140
//line 141
//line 149
//line 158
//line 176
or snippet below
// modifications made
//line 140
//line 141
//line 149
//line 158
//line 176
// and transition turned to transform instead all
<!DOCTYPE html>
<!-- https://templated.co/snapshot -->
<html lang="en">
<head>
<title>Snapshot</title>
<style>
#import "https://use.fontawesome.com/releases/v5.5.0/css/all.css";
* {
margin: 0;
padding: 0;
font-family: "Roboto Light";
}
body {
width: 100%;
height: 100%;
}
/* Side Nav Bar */
aside {
width: 5%;
height: 100%;
font-size: 22px;
text-align: center;
background: rgb(13, 18, 23);
position: fixed;
z-index: 4;
}
aside i {
margin-top: 40px;
color: rgb(134, 137, 139);
}
aside i:hover {
color: white;
}
aside i:active {
color: rgb(134, 137, 139);
}
.fas.fa-home {
color: #19b5fe;
}
/* End Of Side Nav Bar */
/* Main Section */
main {
width: 95%;
height: 100%;
position: absolute;
top: 0;
right: 0;
}
#banner-img {
background: rgba(0, 0, 0, 0.5);
overflow: hidden;
height: 500px;
z-index: 2;
}
.banner {
background-image: url("https://i.ibb.co/KKpJvX3/banner.jpg");
width: 100%;
height: 500px;
position: fixed;
overflow: hidden;
}
.main-fore {
text-align: center;
position: relative;
color: white;
z-index: 3;
margin-top: 15%;
width: 100%;
margin-right: auto;
margin-left: auto;
}
.main-fore h1 {
font-size: 50px;
margin-bottom: 10%;
}
.main-fore h2 {
border: 2px solid rgb(82, 72, 63);
border-radius: 5px;
padding-top: 15px;
padding-bottom: 15px;
width: 15%;
margin-right: auto;
margin-left: auto;
}
.main-fore h2:hover {
background: rgba(72, 57, 44, .2);
color: white;
cursor: pointer;
user-select: none;
}
/* End Of Main Section */
/* Gallery Section - What's New */
.gallery {
position: absolute;
z-index: 3;
top: 500px;
right: 0;
margin-right: 0;
width: 95%;
text-align: center;
height: 800px;
background: #f1f1f1;
}
#g-head {
margin-top: 5%;
margin-bottom: 3%;
color: rgb(34, 49, 63);
font-size: 25px;
}
.gallery-grid img {
-webkit-transition: transform .5s ease-in-out;
-o-transition: transform .5s ease-in-out;
transition: transform .5s ease-in-out;
width: 100%;
height: 100%;
overflow: hidden;
position:relative;
z-index:10;
}
.gallery-grid img:hover {
-webkit-transform: scale(1.2, 1.2);
-o-transform: scale(1.2, 1.2);
transform: scale(1.2, 1.2);
z-index:0;
}
.gallery-grid {
width: 100%;
/* height: 100%;*/ max-width: 1000px;margin:0 auto;
margin-left: auto;
overflow: hidden;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 27% 27%;
grid-template-areas: ". . . ." ". . . .";
}
#g-button {
position: relative;
bottom: 200px;
text-decoration: none;
outline: none;
padding: 15px 50px;
font-size: 22px;
font-weight: 500;
color: white;
background: #19b5fe;
transition: all .2s ease-in-out;
border-radius: 5px;
z-index:20;
}
#g-button:hover {
color: white;
background: rgb(1, 155, 227);
}
/* End Of What's New Section */
/* About Me Section */
.aboutme {
width: 47.5%;
position: absolute;
top: 1300px;
z-index: 3;
background: #e6e6e6;
right: 47%;
color: rgb(34,49,63);
height: 70%;
}
.aboutme h1 {
font-size: 20px;
margin-top: 7%;
margin-left: 10%;
}
.aboutme p {
margin-left: 10%;
margin-top: 4%;
margin-right: 7%;
line-height: 25px;
font-size: 13px;
}
.socialicons i {
position: relative;
left: 10%;
top: 20px;
font-size: 25px;
user-select: none;
color: #19b5fe;
margin: 3px;
}
.socialicons i:hover {
color: rgb(1, 155, 227);
}
/* End Of About Me Section */
/* Message Section */
.message {
width: 47.5%;
position: absolute;
top: 1300px;
background: #ececec;
right: 0;
z-index: 3;
height: 70%;
}
.message h1 {
font-size: 20px;
color: rgb(34,49,63);
margin-top: 7%;
margin-left: 10%;
}
.name_email {
display: flex;
margin-top: 5%;
font-size: 16px;
}
.name_field {
flex: 0 0 50%;
margin-left: 10%;
}
.email_field {
flex: 1;
}
.message_field {
margin-left: 10%;
margin-top: 5%;
}
.email_field input, .name_field input, .message_field textarea {
padding: 10px;
width: 75%;
border: 1px solid #bde6fc;
}
#submit_button {
margin-left: 10%;
margin-top: 10%;
background: #19b5fe;
color: white;
padding: 2% 7%;
border-radius: 5px;
border: none;
cursor: pointer;
font-size: 17px;
font-weight: 500;
}
#submit_button:hover {
background: rgb(1, 155, 227);
}
/* End Of Message Section */
/* Footer Section */
#footer-cap {
font-size: 13px;
text-align: center;
position: relative;
top: 30%;
color: black;
}
.no1-img {
overflow: hidden;
}
</style>
</head>
<body>
<aside>
<i class="fas fa-home"></i><br>
<i class="fas fa-camera-retro"></i><br>
<i class="fas fa-file-alt"></i>
</aside>
<main>
<div class="banner">
<div id="banner-img"></div>
</div>
<div class="main-fore">
<h1>Hey, I'm Snapshot</h1>
<h2>Continue</h2>
</div>
</main>
<div class="gallery">
<h1 id="g-head">What's New</h1>
<div class="gallery-grid">
<img src="https://i.ibb.co/G9CYqz6/01.jpg">
<img src="https://i.ibb.co/pbjtTMD/05.jpg">
<img src="https://i.ibb.co/ckv3dPy/09.jpg">
<img src="https://i.ibb.co/p0kYsQR/02.jpg">
<img src="https://i.ibb.co/7pgbSk9/06.jpg">
<img src="https://i.ibb.co/0F93gYK/10.jpg">
<img src="https://i.ibb.co/0Yw8zwd/03.jpg">
<img src="https://i.ibb.co/wwnzstm/07.jpg">
</div>
<a id="g-button" href="gallery.html">Full Gallery</a>
</div>
<div class="middlediv">
<div class="aboutme">
<h1>About Me</h1>
<p>Mus sed interdum nunc dictum rutrum scelerisque erat a parturient condimentum potenti dapibus vestibulum condimentum per tristique porta. Torquent a ut consectetur a vel ullamcorper a commodo a mattis ipsum class quam sed eros vestibulum quisque a eu nulla scelerisque a elementum vestibulum.<br><br><br>Aliquet dolor ultricies sem rhoncus dolor ullamcorper pharetra dis condimentum ullamcorper rutrum vehicula id nisi vel aptent orci litora hendrerit penatibus erat ad sit. In a semper velit eleifend a viverra adipiscing a phasellus urna praesent parturient integer ultrices montes parturient suscipit posuere quis aenean. Parturient euismod ultricies commodo arcu elementum suspendisse id dictumst at ut vestibulum conubia quisque a himenaeos dictum proin dis purus integer mollis parturient eros scelerisque dis libero parturient magnis.</p>
<h1>Follow Me</h1>
<div class="socialicons">
<i class="fab fa-twitter"></i>
<i class="fab fa-facebook-f"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
<!-- Message Section -->
<div class="message">
<h1>Get in Touch</h1>
<form action="#" method="POST" id="message_form">
<div class="name_email">
<div class="name_field">
<label for="name">Name</label><br><br>
<input type="text" placeholder="Name" id="name" name="user_name" required>
</div>
<div class="email_field">
<label for="email">Email</label><br><br>
<input type="email" id="email" placeholder="Email" name="user_email" required>
</div>
</div>
<div class="message_field">
<label for="message_area">Message</label><br><br>
<textarea cols="20" rows="7" id="message_area" placeholder="Message" name="user_message" required></textarea>
</div>
<input id="submit_button" type="submit" value="Send" form="message_form">
</form>
</div>
</div>
<!-- End Of Message Section -->
<footer>
<div style="width:95%; height: 100px; position: relative; z-index: 3; background: rgb(242, 242, 242); top: 1900px; right: 0; left: 5%;" class="footer">
<p id="footer-cap">© Snapshot: HASHEM. Images: Unsplash.</p>
</div>
</footer>
</body>
</html>
Having just picked up grid I am having some issues when a site is being viewed in mobile. If I set a grid to have a height of 1200px then any elements after this should appear in normal document flow, right?
So how do we deal with this on mobile when a grid is stretched further than its original height value because from what I am experiencing the element after the grid is following the normal document flow and expecting the grid to be finished at 1200px and as a result appears behind the grid element.
Here is a gif to illustrate if anyone could shed light on this it would be super helpful all mark up below also (note on JS fiddle this "bug" does not exhibit itself)
https://gyazo.com/1f3d18693c8df5a339fb5fdc09e8d2c6
HTML
<!DOCTYPE html>
<html lang="" dir="ltr">
<head>
<meta charset="utf-8">
<title>Divine Tofu - Vegan Art and Apparel</title>
<link rel="stylesheet" href = "style/style.css" type = "text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Permanent+Marker" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Shadows+Into+Light+Two" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src = "js/menuscript.js"></script>
</head>
<body>
<nav id="wrapper">
<div class="sideSpacer">
<div id="logoCont">
<img id="logo" src="images/navicons/logo.png" alt="Devine Tofu Logo" />
<div id="logoText"><img id = "logo" class="logotext" src="images/navicons/logotext.png"></div>
</div>
<div id="navWrapper">
<ul>
<a href="#apparel">
<li>Apparel</li>
</a>
<a href="#gal">
<li>Gallery</li>
</a>
<a href="#contactmetitle">
<li>Contact</li>
</a>
<a href="https://www.etsy.com/uk/shop/DivineTofu">
<li>Etsy Store</li>
</a>
</ul>
</div>
<div id="logoCont">
<img id = "logo" class="logobot" src="images/navicons/bottomCircle.png" alt="Devine Tofu Logo" />
</div>
<div id="smWrap">
<ul id="smItems">
<li><img class="icon" src="images/navicons/fb.png" /></li>
<li><img class="icon" src="images/navicons/insta.png" /></li>
<li><img class="icon" src="images/navicons/twitter.png" /></li>
</ul>
</div>
</div>
<a href="https://www.etsy.com/uk/shop/DivineTofu">
Etsy Store
</a>
</nav>
<div id = "grid">
<div id = "grid-item1">
<h1>Commissions</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vehicula, felis ut tempus pulvinar, lorem urna imperdiet velit, ac semper lectus dolor at odio. Proin vitae sapien ex. Sed at varius diam. Fusce sit amet nulla lacinia, sodales leo eu, porta urna. Vestibulum rhoncus facilisis nisl vel dapibus. Vestibulum mollis egestas bibendum. Curabitur fringilla felis vitae nunc efficitur viverra. Nunc eleifend faucibus sodales. Donec libero magna, efficitur vel nisi non, tempus tincidunt quam.</p>
<!-- Slider -->
<img src = "images/Gallery/gallery3.png">
</div>
<div id = "grid-item2">
<h1>Warcraft Chibis</h1>
<br>
<p>Sed commodo turpis in nulla ultricies, ac volutpat turpis tristique. Sed a turpis dictum, posuere arcu sit amet, sodales eros. Maecenas in eleifend lacus. Phasellus mattis eros et justo egestas pharetra. Etiam ac tortor ut orci dapibus laoreet.</p>
</div>
<div id = "grid-item3">
<img src = "images/chibi/tcomm5.png" id = "imgtrans">
<img src = "images/chibi/tcomm1.png" id = "imgtrans">
<img src = "images/chibi/tcomm3.png" id = "imgtrans">
<img src = "images/chibi/tcomm2.png" id = "imgtrans">
<img src = "images/chibi/tcomm7.png" id = "imgtrans">
<img src = "images/chibi/tcomm10.png" id = "imgtrans">
</div>
<div id = "grid-item4">
<br>
<h1>Original Artwork</h1>
<br>
<p>Sed commodo turpis in nulla ultricies, ac volutpat turpis tristique. Sed a turpis dictum, posuere arcu sit amet, sodales eros. Maecenas in eleifend lacus. Phasellus mattis eros et justo egestas pharetra. Etiam ac tortor ut orci dapibus laoreet.</p>
</div>
<div id = "grid-item5">
<img src = "images/Gallery/icongall1.png" id = "imgtrans">
<img src = "images/Gallery/icongall6.png" id = "imgtrans">
<img src = "images/Gallery/icongall3.png" id = "imgtrans">
<img src = "images/Gallery/icongall4.png" id = "imgtrans">
<img src = "images/Gallery/icongall5.png" id = "imgtrans">
<img src = "images/Gallery/icongall2.png" id = "imgtrans">
</div>
</div>
<!--This is the red bar -->
<div class = "aftergrid"> </div>
</body>
</html>
CSS
*{
box-sizing: border-box;
}
.aftergrid {
width: 100%;
height: 40px;
background-color: red;
}
#grid {
margin: 0 auto;
display: grid;
max-width: 100%;
height:1200px;
grid-template-columns: repeat(1, 1fr);
grid-template-rows: repeat(8,1fr);
grid-gap: 5px 5px;
}
#grid div {
background-color: hsla(126, 100%, 100%, 0.63);
box-shadow: 0px 20px 250px 10px #fffdd0 inset;
}
#grid:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.fixed-width {
max-width: 90%;
margin:0 auto;
}
h1 {
text-align: center;
}
#grid-item1{
background-color: aliceblue;
text-align: center;
}
#grid-item1 p{
position: relative;
margin-bottom: 1em;
padding: 1em;
animation-name: fadeinleft;
animation-duration: 1s;
animation-timing-function: ease-in-out;
}
#grid-item1 h1 {
position: relative;
animation-name: fadeinright;
animation-duration: 1s;
animation-timing-function: ease-in-out;
}
#keyframes fadeinleft{
0% {left:-50px;
opacity: 0;
}
80% {left: 10px;
}
100% {left:0px;
opacity: 1;}
}
#keyframes fadeinright {
0% {left:50px;
opacity: 0;
}
80% {left: -10px;
}
100% {left:0px;
opacity: 1;}
}
#grid-item1>img{
width: 80%;
}
#grid-item2{
grid-row: 4/5;
background-color: aliceblue;
display: flex;
flex-direction: column;
align-items: center;
}
#grid-item2 p {
padding: 1em;
display: flex;
}
#grid-item3{
grid-row: 5/6;
background-color: aliceblue;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
}
#grid-item4{
grid-row: 6/7;
background-color: aliceblue;
display: flex;
flex-direction: column;
align-items: center;
}
#grid-item4 p {
padding:1em;
}
#grid-item5{
grid-row: 7/8;
background-color: aliceblue;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
}
.icon {
max-width: 80%;
margin: 0 auto;
}
#imgtrans{
width: 32%;
transition: all .2s ease-in-out;
padding: 5px;
overflow: auto;
position: relative;
z-index: 3;
}
#imgtrans:hover{
transform: scale(1.1);
}
#navWrapper ul li:hover {
opacity: 1;
filter: alpha(opacity=0.5);
background-color: rgba(255, 74, 1, 0.54);
}
#navWrapper ul {
margin: 0 auto;
width:96%;
}
#navWrapper ul li {
text-align: center;
margin: 10px 5px 10px 0px;
padding: 1%;
color:white;
opacity: 0.6;
transition: background-color 0.25s, opacity 0.25s ease-in;
border-radius: 10px 10px 10px 10px;
-moz-border-radius: 10px 10px 10px 10px;
-webkit-border-radius: 10px 10px 10px 10px;
width:98%;
font-size: 28px;
font-family: 'Shadows Into Light Two', cursive;
}
#navWrapper ul a {
text-decoration: none;
}
#parallax {
background-image: url(../images/parallaxbg.png);
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: fixed;
opacity: 0.1;
height: 100%;
width: 100%;
z-index: 0;
margin: 0 auto;
}
.sideSpacer {
position:fixed;
top:0;
left:0;
height:100vh;
width:220px;
background-color: hsla(36, 100%, 50%, 0.80);
z-index: 2;
transition: width .5s ease-out;
}
.sideSpacer:hover {
width:250px;
}
#flexcont{
display: block;
}
#flexlist{
height: 100%;
transition: all 1s;
}
#navIcons {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.mobileLogo {
width:100px;
height: 100px;
}
.mobileNavButton {
width: 50px;
height: 50px;
align-self: center;
margin-right: 15px;
}
.mobileNavButton:hover {
cursor: pointer;
}
#smWrap {
width:100%;
}
#smItems{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
}
#smItems li{
text-align: center;
opacity: 0.6;
width:66px;
margin-bottom: 10px;
transition: width 2s, opacity 0.25s ease-in;
}
#smItems li:hover {
opacity: 0.9;
}
#logoCont{
margin:0 auto;
width:100%;
}
#logoCont{
font-weight: bold;
width: 100%;
opacity: 0.8;
color:white;
transition: width 2s, opacity 0.5s ease-in;
}
#logoCont:hover {
opacity: 1;
filter: alpha(opacity=0.5);
}
#logo{
max-width: 94%;
margin-left:3%;
margin-right:3%;
margin-top: 5%;
}
#logoText {
text-align: center;
}
.logobot{
max-width: 80%;
margin:10%;
padding-top: 1em;
}
#topNav {
width: 100%;
background-color: hsla(36, 100%, 50%, 0.80);
}
/* Tablet */
#media only screen and (min-width: 500px) {
#grid {
max-width: 90%;
margin: 0 auto;
}
.fixed-width {
width: 80%;
margin: 0 auto;
}
}
#media only screen and (max-width: 900px){
.sideSpacer {
display:none;
}
}
/* Desktop */
#media only screen and (min-width: 900px) {
#grid {
width: 70%;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(12,1fr);
grid-gap: 5px 5px;
margin-left: 25%;
}
#grid-item1{
grid-row: 2/12;
grid-column: 5/9;
background-color: aliceblue;
}
#grid-item2{
grid-row: 1/4;
grid-column: 1/4;
background-color: aliceblue;
}
#grid-item3{
grid-row: 4/7;
grid-column: 1/4;
background-color: aliceblue;
}
#grid-item4{
grid-row: 7/10;
grid-column: 1/4;
background-color: aliceblue;
}
#grid-item5{
grid-row: 10/13;
grid-column: 1/4;
background-color: aliceblue;
}
#topNav {
display: none;
}
.aftergrid {
margin-top: 25px;
}
}
I have solved it I should have been using height auto all along.
I'm trying to do some CSS translate animation. Unfortunately Firefox doesn't perform well. It looks a bit choppy. IE11, Edge, Chrome and even Firefox for Android run this animation very smoothly. So what is wrong in my code below?
Note that I have Firefox 49.0.2 64bit and Windows 10.
.content {
height: 200px;
background-color: black;
color: white;
display: flex;
justify-content: center;
align-content: center;
align-items: center;
}
p {
margin: 0;
padding: 0;
width: 300px;
opacity: 0;
font-family: Helvetica, sans-serif;
font-size: 18px;
letter-spacing: 2px;
line-height: 1.4em;
text-transform: uppercase;
animation: intro 2s ease-out infinite;
}
#keyframes intro {
0% {
opacity: 0;
transform: translate(15px, 15px);
}
100% {
opacity: 1;
transform: none;
}
}
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
I need a help I am trying to achieve animation on hamburger menu checked and unchecked. I am able to animate menu but I can not figure out how to animate left menu animation on transform to 0
&__menu {
transform: translateX(-100%);
transition: 1s ease-in-out;
// .c-hamburger--icon ~ &{
// transition: all 300ms;
// }
.c-hamburger--icon:checked ~ &{
height: 100vh;
background: #000;
width: 270px;
transform: translateX(0);
top: 0;
opacity: .7;
position: fixed;
}
}
Here is the CodePen Demo.
Apply the height and width properties to the default state of the element instead of applying it only after the menu is checked. Default values for height and width properties is auto and we cannot transition from or to auto. Thus it was resulting in an immediate hiding of the menu instead of a slow transition.
As you are using a transform: translateX(-100%) to hide the menu initially, even setting a default height and width to the element will not affect the layout. Demo with the compiled CSS is added below.
&__menu {
position: fixed;
top: 0;
height: 100vh;
width: 270px;
transform: translateX(-100%);
transition: 1s ease-in-out;
.c-hamburger--icon:checked ~ &{
background: #000;
transform: translateX(0);
opacity: .7;
}
}
Another thing to note is that the position property should also be set on the default state itself. This is needed because the position is not a transitionable property.
#import url("https://fonts.googleapis.com/css?family=Titillium+Web");
* {
padding: 0;
margin: 0;
font-size: medium;
font-family: 'Titillium Web', sans-serif;
}
.l-app__menu {
position: fixed;
top: 0;
height: 100vh;
width: 270px;
transform: translateX(-100%);
transition: 1s ease-in-out;
}
.c-hamburger--icon:checked ~ .l-app__menu {
transform: translateX(0);
background: #000;
opacity: .7;
}
.l-app__left {
float: left;
position: fixed;
background: #185a9d;
width: 50%;
height: 100%;
overflow: hidden;
}
#media (max-width: 1200px) {
.l-app__left {
position: static;
width: 100%;
height: 100vh;
background: #fff;
}
}
.l-app__right {
float: right;
background: #fff;
width: 50%;
height: 100vh;
}
#media (max-width: 1200px) {
.l-app__right {
position: static;
width: 100%;
background: #bfbfbf;
}
}
.l-app__right--inner {
padding: 50px;
}
.l-app__hamburger {
position: fixed;
z-index: 1;
}
.c-bike__image {
background: url(http://bikeshopgirl.com/wp-content/uploads/2011/10/15038.jpg) no-repeat;
background-size: contain;
min-height: 100%;
opacity: .9;
top: 0;
position: relative;
}
#media (max-width: 1200px) {
.c-bike__image {
position: static;
width: auto;
opacity: 1;
}
}
.c-bike__header {
font-size: 150%;
padding: 15px;
}
#media (max-width: 1200px) {
.c-bike__header {
padding: 0;
}
}
.c-bike__article {
letter-spacing: .3px;
padding: 10px;
}
.c-bike__article.c-bike__header {
font-size: 120%;
padding: 0;
}
.c-hamburger {
background: transparent;
display: block;
position: relative;
overflow: hidden;
margin: 0;
padding: 0;
width: 96px;
height: 96px;
font-size: 0;
text-indent: -9999px;
appearance: none;
box-shadow: none;
border-radius: none;
border: none;
cursor: pointer;
transition: background .3s;
}
.c-hamburger:focus {
outline: none;
}
.c-hamburger--icon {
display: none;
}
.c-hamburger--icon ~ .c-hamburger--htx {
transition: transform 1s;
}
.c-hamburger--icon:checked ~ .c-hamburger--htx {
transform: translate(250px, 0) rotate(90deg);
transition: 1s ease-in-out;
}
.c-hamburger--icon:checked ~ .c-hamburger--htx .c-hamburger__span {
background: none;
}
.c-hamburger--icon:checked ~ .c-hamburger--htx .c-hamburger__span::before {
top: 0;
transform: rotate(45deg);
}
.c-hamburger--icon:checked ~ .c-hamburger--htx .c-hamburger__span::after {
bottom: 0;
transform: rotate(-45deg);
}
.c-hamburger--htx__span {
transition: transform .5s;
}
.c-hamburger--htx__span::before {
transition-property: top, transform;
}
.c-hamburger--htx__span:after {
transition-property: bottom, transform;
}
.c-hamburger__span {
display: block;
position: absolute;
top: 44px;
left: 18px;
right: 18px;
height: 8px;
background: #930202;
border-radius: 5px;
}
.c-hamburger__span::before,
.c-hamburger__span::after {
position: absolute;
display: block;
left: 0;
width: 100%;
height: 8px;
background: #930202;
border-radius: 5px;
content: "";
}
.c-hamburger__span::before {
top: -20px;
}
.c-hamburger__span::after {
bottom: -20px;
}
<div class="l-app">
<div class="l-app__hamburger">
<input id="c-hamburger--icon" type="checkbox" name="c-hamburger" class="c-hamburger--icon" />
<label for="c-hamburger--icon" class="c-hamburger c-hamburger--htx">
<span class="c-hamburger__span"></span>
</label>
<nav class="l-app__menu"></nav>
</div>
<div class="l-app__left">
<div class="l-app__left--inner c-bike__image"></div>
</div>
<div class="l-app__right">
<div class="l-app__right--inner">
<section class="c-bike">
<header>
<h3 class="c-bike__header">Bike name</h3>
</header>
<article class="c-bike__article">
<header>
<h4 class="c-bike__article c-bike__header">Secion name</h4>
</header>
<p class="c-bike__article c-bike__paragraph">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis diam egestas, dictum augue ut, dignissim lorem. Integer eros felis, sodales at viverra et, ultricies malesuada lacus. Nullam ex orci, vulputate vitae porta eu, gravida vel arcu. Curabitur
mattis quis dolor sit amet dapibus. Etiam mattis diam id rhoncus tempor. Phasellus tristique auctor luctus. Nulla ullamcorper tempus porttitor. Sed et tincidunt sem. Morbi dictum ut orci sit amet pretium. Integer feugiat enim vitae neque commodo,
ac malesuada lacus scelerisque. Donec quis odio in ipsum facilisis auctor. Vestibulum turpis turpis, blandit sit amet tempus sed, facilisis nec tellus. Morbi elementum vulputate sem a rhoncus. Vivamus bibendum congue velit, ac hendrerit est
suscipit ac. Nunc a molestie libero.
</p>
</article>
</section>
</div>
</div>
</div>
I'm relatively new at coding and I'm trying to make it so one image fades to a different image and that image has text over it.
I'm using Tumblr, so PHP-5-only MVC I'm pretty sure.
And here's what I have so far:
<style>
#imagefade {
background-image: url('http://i65.tinypic.com/107kqbq.jpg');
position: absolute;
}
#imagefade img {
-webkit-transition: all ease 1.5s;
-moz-transition: all ease 1.5s;
-o-transition: all ease 1.5s;
-ms-transition: all ease 1.5s;
transition: all ease 1.5s;
}
#imagefade img:hover {
opacity: 0;
}
#text {
position: center;
}
.image {
position: relative;
}
p {
position: absolute;
top: 200px;
left: 38px;
width: 100%;
font-family: arial;
font-size: 12px;
color: white;
}
</style>
<div id="imagefade">
<img src="http://i68.tinypic.com/2i9s4eb.jpg" />
<p>text heading here</p>
</div>
If I got it correct from what you want, the easiest way to do this is use position: absolute; and opacity on :hover to achieve this. The positioning will set the layers on top of each other and not next to each other (as in your example).
See my example below.
.container {
background: lightblue;
position: relative;
width: 500px;
height: 300px;
}
.box {
background-image: url('https://i.imgur.com/AzeiaRY.jpg');
background-position: center;
position: absolute; /* Setting the boxes on top of each other */
top: 0;
left: 0;
right: 0;
bottom: 0;
display: block;
transition: opacity .4s ease-in-out; /* Transition the opacity for the :hover */
}
.image-2 {
background-position: bottom right;
opacity: 0;
}
.image-1:hover .image-2 {
opacity: 1;
}
/* Pure for styling below */
.box-text {
position: absolute;
top: 0;
left: 0;
color: #fff;
padding: 10px;
background: rgba(0, 0, 0, .8);
width: 40%;
height: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="box image-1">
<div class="box image-2">
<div class="box-text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias, mollitia. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim ipsa maxime modi velit similique maiores, porro voluptate? Molestias ratione natus consequatur libero eaque
pariatur optio quisquam minima. Nemo quis, odit.
</p>
</div>
</div>
</div>
</div>