What is causing this html5 video glitch? - css

I have an html5 video tag with a div that has a text caption overlayed and when you scroll in chrome, the text div disappears as it gets near the top or bottom of the screen fold. Sometimes it's as its nearing the top of the screen, sometimes the bottom. I think it depends where the video is on the screen when it's refreshed.
Anyone know what is causing this? I think this is pretty barebones markup.
codepen: https://codepen.io/sharpdesigner/pen/KRgQZZ
screen capture of the issue: https://imgur.com/a/Hn8DWkP
html
<section id="video-landing" class="hide-mobile">
<div class="container">
<div class="row">
<div class="col-md-6 video-caption">
<h1>Lorem ipsum dolor sit</h1>
<p class="big">Quisque varius erat et</p>
<p>Vivamus aliquam lectus est. Nulla vitae fringilla felis. Aenean id elit sit amet sem mattis bibendum eu a felis. Interdum et malesuada fames ac ante ipsum primis in faucibus.</p>
</div>
</div>
</div> <!-- /container -->
<video muted autoplay="autoplay" loop="loop" id="bgvid">
<source src="http://www.mysportresume.com/phone.mp4" type="video/mp4" />
</video>
</section><!-- #section -->
css
body {
height: 2000px;
margin-top: 500px;
}
.container {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
section#video-landing, section#video-landing-mobile {
background: url('../images/video-bg.jpg') no-repeat 0 -175px;
background-size: cover;
}
section#video-landing .row, section#video-landing-mobile .row {
margin: 0;
position: relative;
}
.video-caption {
position: absolute;
max-width: 550px;
top: 165px;
top: 8.5vw;
left: 0;
z-index: 99;
}
.video-caption h1, .video-caption p {
color: #000;
text-align: left;
}
.video-caption h1 {
font-size: 53px;
font-weight: 600;
}
.video-caption p.big {
margin: 0 0 30px;
max-width: 400px;
}
.video-caption p {
font-size: 17px;
}
p.big {
color: #000;
font-size: 27px !important;
font-weight: 300;
line-height: 1.5;
max-width: 850px;
margin: 0 auto;
}
video {
padding-top: 50%;
position: absolute;
top: 50%;
left: 0;
-webkit-transform: translateY(-50%);
transform: translateY(-55%);
width: 100%;
}
#video-landing, #video-landing-mobile {
width: 100%;
padding-bottom: 30%;
position: relative;
overflow: hidden;
color: white;
}
#video-landing .container, #video-landing-mobile .container {
max-width: 1140px;
}
#video-landing video, #video-landing-mobile video {
position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
}

Related

How to make transform scale do not overflow?

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>

How do I overlay a transparent color on top of a div and position loading... text in the absolute center of the div?

<div class="square loading"></div>
square {
height: 200px;
width: 200px;
margin: 0px auto;
}
loading {
...
}
I'm trying to:
Overlay black color on top of div with 50% transparency (so background is still visible).
Place Loading... text in the absolute center of the div.
How do I achieve this with pure CSS?
display flex is your friend
.square {
height: 200px;
width: 200px;
margin: 0px auto;
background-color: yellow;
position: relative;
}
.loading:after {
content: '...loading';
position: absolute;
top:0;
bottom: 0;
right: 0;
left: 0;
background: rgba(0,0,0,.5);
display: flex;
justify-content: center;
align-items: center;
}
<div class='loading square'></div>
Hope this will help you..
.square {
height: 200px;
width: 200px;
margin: 0px auto;
background: rgba(0,0,0,.5);
display: flex;
justify-content: center;
align-items: center;
}
<div class="square">
<div class="loading">Loading...</div>
</div>
Use this code.
.square {
height: 200px;
width: 200px;
margin: 0px auto;
background:rgba(0,0,0,0.5);
position:relative;
}
.square::after {
color: #fff;
content: "loading...";
left: 0;
margin: auto;
position: absolute;
right: 0;
text-align: center;
top: 50%;
transform: translateY(-50%);
}
<div class="square loading"></div>
.container {
display: flex;
height: 200px;
width: 200px;
position: relative;
border: 1px solid: #ddd;
padding: 10px;
}
.loader {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(127, 127, 127, 0.6);
opacity: 0;
transition: all 0.3s ease;
z-index: -1;
}
.loader.active {
opacity: 1;
z-index: 1;
}
<div class="container">
<div class="loader active">Loading</div>
<div class="content">Hai</div>
</div>
In this snippet, you can see the loader div. You can toggle its mode ON/OFF by toggling the class active. Also, the content in the loader (Now it is Loading) div will always be in the center. No matter what the content and its width or height are. Because the flexbox is used here.
Also, the overlay can be changed by changing the background of the loader.
Here is a div with content and a div with class overlay. you can try like this.
.overlay {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: 0px auto;
background: rgba(0,0,0,.7);
display: flex;
justify-content: center;
align-items: center;
}
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam laoreet nisl vel eros pulvinar, eu ultrices lorem interdum. Donec maximus massa ullamcorper est egestas faucibus et ac ligula. </p>
<div class="overlay">Loading...</div>
</div>

Multiple z-index elements

I' am doing a project and I have a little issue with z-index property.
Here is my code:
(HTML)
<div class="outer_obw">
<div class="obw1">
<div class="box" id="blue_box">
<div id="inn_blue" class="inner_box"><p>Box1</p></div>
</div>
</div>
<div class="main_box_content">
<div class="back_box">
<div class="main_box">
<p id="texts">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<div class="obw3">
<div class="box" id="green_box">
<div id="inn_green" class="inner_box"><p>Box2</p></div>
</div>
</div>
</div>
</div>
(CSS)
.outer_obw {
width: 78.5%;
margin: 0 auto;
}
.obw1 {
min-height: 80px;
}
.obw3 {
min-height: 80px;
margin-top: -40px;
}
.box {
width: 25.25%;
min-height: 80px;
cursor:pointer;
position: relative;
}
.inner_box {
height: 68px;
margin: -10.5px 6px;
text-align: center;
position: relative;
}
#inn_blue {
background-color: #fff;
z-index: 5;
}
#inn_green {
background-color: #fff;
z-index: 5;
}
#blue_box {
background-color: blue;
float: left;
z-index: 1;
}
#green_box {
background-color: green;
float: right;
}
.main_box_content {
display: table;
width: 78.5%;
position: absolute;
margin-top: -40px;
}
.back_box {
display: table;
background-color: blue;
width: 65%;
margin: 0 17%;
position: relative;
z-index: 3;
}
.main_box {
display: table;
background-color: #f1f1f1;
margin: 6px;
padding: 0.5% 3%;
position: relative;
z-index: 10;
}
Here is all code and visualization.
I intended to achieve such an effect:
All what I need to do is insert inn_blue and inn_green (white fields of box1 and box2) between main_box (gray field with a text) and back_box (red background of the main box.
I don't know what I'm doing wrong. Z-index of the main_box should be greater than z-index of inn_blue/inn_green and z-index of the inn_blue/inn_green should be greater then back_box.
And so it is in my code, but the effect is not what I expected...
So the question is what am I doing wrong?
There are so many layers of complexity in your example. Instead, let's use the natural layers to our advantage and position with absolute and minimal markup.
The basics
Start off with a wrapper to contain your three boxes:
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
The wrapper will be position: relative and its three children will be positioned with position: absolute and top / right / bottom / left. In order to allow a flexible size that resizes in proportion, we can make use of the viewport width (vw) unit for both the width and the height. Each child div is given a percentage height.
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
}
.wrapper div {
position: absolute;
height: 25%;
width: 20%;
}
.wrapper .one {
top: 16px;
left: 16px;
background: blue;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: red;
}
.wrapper .three {
bottom: 16px;
right: 16px;
background: green;
}
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
That gives us this:
Layer the main box
Now we want the red square to overlap both the blue and green squares. All we have to do is move the red <div> below them in the markup. The last element in the markup will overlap the elements before it naturally.
<div class="wrapper">
<div class="one"></div>
<div class="three"></div>
<div class="two"></div><!-- move it one line down -->
</div>
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
}
.wrapper div {
position: absolute;
height: 25%;
width: 20%;
}
.wrapper .one {
top: 16px;
left: 16px;
background: blue;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: red;
}
.wrapper .three {
bottom: 16px;
right: 16px;
background: green;
}
<div class="wrapper">
<div class="one"></div>
<div class="three"></div>
<div class="two"></div><!-- move it one line down -->
</div>
Now we have the correct layers:
Add the border layers
In order to reduce complexity, we can create the box borders with :before pseudo elements. These will create the extra elements we need to create the overlapping borders.
Give each child div a :before element and background color like below:
.wrapper div:before {
content: '';
position: absolute;
top: -6px;
right: -6px;
bottom: -6px;
left: -6px;
z-index: -1;
}
.one:before {
background: blue;
}
.two:before {
background: red;
}
.three:before {
background: green;
}
The -1 z-index will ensure that they are overlapped by the div backgrounds and the -6px position on all sides pulls them outside by 6px to give us a 6px border.
The final product
We add z-index: 1 to the wrapper, so that it wont overlap our border pseudo elements. box-sizing: border-box is used so that the padding is incorporated into the widths and heights.
Example 1
Limitation of this example: We cannot use overflow to hide excessive text on the main box, as it will cut off our border or cause a scroll bar to always be present..
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
max-width: 772px;
max-height: 579px;
min-width: 390px;
min-height: 292px;
z-index: 1;
}
.wrapper div {
position: absolute;
box-sizing: border-box;
background: #FFF;
height: 25%;
width: 20%;
text-align: center;
padding: 10px;
}
.wrapper div:before {
content: '';
position: absolute;
top: -6px;
right: -6px;
bottom: -6px;
left: -6px;
z-index: -1;
}
.one:before {
background: blue;
}
.two:before {
background: red;
}
.three:before {
background: green;
}
.wrapper .one {
top: 16px;
left: 16px;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: #EEE;
text-align: left;
}
.wrapper .three {
bottom: 16px;
right: 16px;
}
<div class="wrapper">
<div class="one">Box1</div>
<div class="three">Box3</div>
<div class="two">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
Example 2
Slightly less elegant, the main box border is positioned relative to the wrapper itself, we can use overflow in this example to cut off or scroll excessive text.
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
max-width: 772px;
max-height: 579px;
min-width: 390px;
min-height: 292px;
z-index: 1;
}
.wrapper div {
position: absolute;
box-sizing: border-box;
background: #FFF;
height: 25%;
width: 20%;
text-align: center;
padding: 10px;
}
.wrapper:after {
content: '';
position: absolute;
margin: -23% 0 0 -31%;
top: calc(50% - 6px);
left: calc(50% - 6px);
height: calc(60% + 12px);
width: calc(62% + 12px);
background: #F00;
z-index: -1;
}
.wrapper div:before {
content: '';
position: absolute;
top: -6px;
right: -6px;
bottom: -6px;
left: -6px;
z-index: -1;
}
.one:before {
background: blue;
}
.three:before {
background: green;
}
.wrapper .one {
top: 16px;
left: 16px;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: #EEE;
text-align: left;
}
.wrapper .three {
bottom: 16px;
right: 16px;
}
<div class="wrapper">
<div class="one">Box1</div>
<div class="three">Box3</div>
<div class="two">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
By streamlining the markup and css a bit and only z-indexing the necessaries (namely .top-box-border and .mid-box-inner) I believe I have what you're looking for:
[class*="border"] {
width: 100px;
height: 100px;
border: 10px solid green;
position: relative;
}
[class*="inner"] {
width: 100%;
height: 100%;
background-color: #999;
position: relative;
text-align: center;
box-sizing: border-box;
padding: 1ex 1em;
}
.mid-box-border {
width: 200px;
height: 200px;
border-color: blue;
margin-top: -40px;
margin-left: 75px;
}
.mid-box-inner {
background-color: #ccc;
text-align: left;
z-index: 20;
}
.bot-box-border {
margin-top: -40px;
margin-left: 255px;
}
.top-box-border {
z-index: 10;
}
<div class="top-box-border">
<div class="top-box-inner">Box 1</div>
</div>
<div class="mid-box-border">
<div class="mid-box-inner">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic accusantium dicta sint a cum eveniet, id! Corrupti sit reprehenderit ad veniam ratione mollitia molestiae, sapiente quasi id esse, incidunt eligendi.</div>
</div>
<div class="bot-box-border">
<div class="bot-box-inner">Box 2</div>
</div>
Set position: initial; for .back_box
Just make position relative for each box and position absolute for the background(border) and content holder to make them out of their workflow, then first element will take higher z-index and the elements in the back will take lower, look at this one https://jsfiddle.net/s3y94x1w/
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.cont {
width: 100%;
}
.blue-box {
width: 20%;
height: 150px;
position: relative;
margin: 10px 0px 0px 8%;
cursor: pointer
}
.blue-box .background {
background-color: blue;
height: 100%;
width: 100%;
position: absolute;
}
.blue-box .content {
background-color: #fff;
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
z-index: 2
}
.red-box {
width: 40%;
height: 150px;
position: relative;
margin-left: 19%;
margin-top: -70px;
}
.red-box .background {
background-color: red;
height: 100%;
width: 100%;
position: absolute;
}
.red-box .content {
background-color: #eee;
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
z-index: 3;
overflow: hidden
}
.green-box {
width: 20%;
height: 150px;
position: relative;
margin-left: 50%;
margin-top: -70px;
cursor: pointer
}
.green-box .background {
background-color: green;
height: 100%;
width: 100%;
position: absolute;
z-index: -1
}
.green-box .content {
background-color: #fff;
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
}
<div class="cont">
<div class="blue-box">
<div class="background"></div>
<div class="content">Box1</div>
</div>
<div class="red-box">
<div class="background"></div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
<div class="green-box">
<div class="background"></div>
<div class="content">Box2</div>
</div>
</div>

Vertically center a heading tag and a heading pseudo selector's content

Another vertical alignment question...
Given the following,
HTML:
<div class="thing">
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et tempus mauris. Vivamus imperdiet congue iaculis.</h2>
</div>
<div class="thing">
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et tempus mauris.</h2>
</div>
CSS:
.thing{
background: #eee;
margin: 0 auto 10px;
width: 625px
}
h2{
display: inline-block;
font-size: 15px;
line-height: 20px;
margin: 0 0 0 40px;
vertical-align: middle;
}
.thing:before{
background: red;
content: '';
display: inline-block;
height: 40px;
position: absolute;
vertical-align: middle;
width: 40px;
}
What do I need to do in order to have the text and the red box vertically centered? This should work for headings of any height.
Fiddle
You just need to remove the position:Absolute that breaks the inline-block behavior. Instead use some trick to fight the space between inline-block elements and be sure the two elements can be aside on the containers width. Try this:
.thing{
font-size:0; /*ADD*/
}
h2{
/*margin: 0 0 0 40px; REMOVE*/
width:585px; /*ADD*/
}
.thing:before{
/*position: absolute; REMOVE*/
}
Check this Demo Fiddle
I guess your question has two answers.
Here's solution one: (Make the red box equal the height of the .thing content.
.thing{
background: #eee;
margin: 0 auto 10px;
position: relative; // Make .thing:before relate it's position to this
width: 625px
}
h2{
font-size: 15px;
line-height: 20px;
margin: 0 0 0 40px;
}
.thing:before{
background: red;
content: '';
height: 100%; // Height will equal .thing height
position: absolute;
width: 40px;
}
Demo 1
Second solution: (Make text center vertically)
.thing{
background: #eee;
margin: 0 auto 10px;
min-height: 40px;
position: relative;
width: 625px
}
h2{
font-size: 15px;
line-height: 20px;
margin: 0 0 0 40px;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.thing:before{
background: red;
content: '';
height: 40px;
left: 0;
position: absolute;
top: 0;
width: 40px;
}
Demo 2

Page too long (used sticky-footer)

Hi~ I'm making an art portfolio online and I've run into an issue. I've used sticky footer ryanfaitdotcom/sticky-footer/ and now my page seems unnecessarily long. Any advice would be appreciated!
Here's the code:
deleted because it's wrong. correct code can be found on bottom
or here:
html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/layout.css"/>
<link rel="stylesheet" href="css/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div class="wrapper">
<div id="page-wrap" class="group">
<div id="main-content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut </p>
</div> <!-- End main-content -->
</div> <!-- End page-wrap -->
<div class="push"></div>
</div> <!-- End wrapper -->
<div class="footer">
<img src="Images/organicspahouston_logo.png" width="400" height="238" />
<div class="bottom">
<p>Copyright (c) 2008</p>
</div>
</div>
</body>
with style.css
* {margin: 0;padding: 0;}
html { height: 100%; background:#B5A9A0 url(../Images/osh_pic_bg1.png) no-repeat; background-size: 100%}
body { height: 100%; font: RomulC; font-size: 12px; color:#A39E95; text-align: center }
article, aside, figure, footer, header, nav, section { display: block; }
.group:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
.group { display: inline-block; clear: both; }
/* start commented backslash hack \*/ * html .group { height: 1%; } .group { display: block; } /* close commented backslash hack */
.wrapper {
position: relative;
width: 800px;
margin: 0 auto -258px;
}
#page-wrap { width:800px; -moz-border-radius: 15px;
border-radius: 15px; margin: 175px auto; background:#000; position:relative;}
#main-content { float:right; width: 640px; margin: 10px 10px 10px 0px; -moz-border- radius: 15px;
border-radius: 15px; background: #2D261C; position: relative; padding: 10px 0px 0px 0px; }
.footer {
position: relative;
width: 100%;
margin: 0 auto 0;
padding: 0;
text-align:center;
height: 258px;
overflow:hidden;
}
.footer img {
position: relative;
width: 400px;
margin: 0 auto;
}
.bottom {
position: relative;
width: 100%;
height: 20px;
margin: 0 auto 0;
padding: 0;
text-align:center;
background-color: #000000;
}
.bottom a {
color: #fff;
text-decoration: underline;
border: 0;
}
.bottom p {
position: absolute;
left: 0;
bottom: 4px;
width: 100%;
padding: 0;
color: #fff;
font: 0.8em arial,sans-serif;
}
</html>
and layout.css from sticky footer
* {
margin: 0;
}
html, body {
height: 800px;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -258px; /* the bottom margin is the negative value of the footer's height */
}
.footer {
height: 258px; /* .push must be the same height as .footer */
}
.push {
height: 258px; /* .push must be the same height as .footer */
}
/*
#Samich provided me with the solution below (plus helped me immensely with cleaning things up). I was adding margin, but I had to add it to BOTH sides so it went from:
#page-wrap { width:800px; -moz-border-radius: 15px;
border-radius: 15px; margin: 175px auto; background:#000; position:relative;}
to
#page-wrap { width:800px; -moz-border-radius: 15px;
border-radius: 15px; margin: 175px auto Opx; background:#000; position:relative;}
http://jsfiddle.net/kagawa_leah/c2N24/11/
What a difference a 0 makes.
You need to set the height of your footer and margin-bottom of your wrapper to the same value. In your case it's 4em.
http://jsfiddle.net/WqNEj/3/
P.S.
http://jsfiddle.net/WqNEj/8/
I've set overflow:hidden in the footer because it's height 260px which is bigger than footer height.
.push must be the same height as your footer , but negative: Set .push to margin-bottom: -258px

Resources