I would like this image(smaller - grey one) to stay at the bottom of its div(meadow image) when the window is resized.. I have tried with auto values on attributes but I guess it has something to do with positioning, can't figure out what it is exactly..any ideas maybe? Thanks a tonne!
Codepen: http://codepen.io/anon/pen/zoEYgP
.images {
background: url("http://kingofwallpapers.com/meadow/meadow-008.jpg");
background-size: cover;
height: 780px;
/*position: relative;*/
}
.smaller {
text-align: center;
}
.smaller img {
position: relative;
bottom: -280px;
}
#media screen and(max-width: 768px) {
.images {
height: auto;
/*position: relative;*/
}
.smaller img {
width: 80%;
/*height: auto;*/
/*margin-bottom: 0px;*/
}
}
<section class="images">
<div class="smaller">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97500&w=400&h=500" alt="">
</div>
</section>
see the codepen, I made smaller .image position: absolute and tweak some css aound
.images {
background: url("http://kingofwallpapers.com/meadow/meadow-008.jpg");
background-size: cover;
height: 768px;
/*height: 100vh;*/
min-height: 500px;
max-width: 100%;
position: relative;
}
.smaller img {
position: absolute;
bottom: 0;
left: 0;
max-width: 50%;
margin: 0 auto;
right: 0;
}
#media screen and(max-width: 768px) {
.images {
height: 100vh;
//position: relative;
}
.smaller img {
//width: 80%;
//height: auto;
//margin-bottom: 0px;
}
}
<section class="images">
<div class="smaller">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97500&w=400&h=500" alt="">
</div>
</section>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis nulla laboriosam laborum sapiente sit voluptate voluptatum, velit eius quam minus natus incidunt omnis quidem cupiditate, maxime, ex reprehenderit minima enim!</p>
Related
The following code snippet displays some headlines, with some icons floated on the left. The parent div has a defined height, with scroll:auto set.
Currently, scrolling to the bottom looks like this:
However, I'd like to clip off the icons when the text entries end, so when scrolling to the bottom, it looks like this:
The reason for the use of float is so that when there are not many icons, the text flows like this:
.parent {
position: absolute;
height: 100px;
width: 400px;
overflow: scroll;
}
.content {
background-color: cyan;
padding: 6px;
}
.icon {
float: left;
clear: both;
background-color: lightpink;
width: 38px;
height: 38px;
margin-right: 8px;
margin-bottom: 6px;
}
.entry {
font-size: 18px;
}
<div class="parent">
<div class="content">
<img class="icon">
<img class="icon">
<img class="icon">
<img class="icon">
<div class="entry">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
<div class="entry">Quisque eleifend viverra risus, nec maximus nisi vestibulum eu</div>
<div class="entry">Mauris in libero lacus</div>
</div>
</div>
Just smack a overflow: clip on your .content along with the sexy overflow-clip-margin: content-box.
Note on overflow-clip-margin: Safari doesn't support it (yet). Quick edit: Firefox has some issues with overflow-clip-margin's visual-box property too. My bad!
Without it, the images are still clipped but without caring about your .content padding. Shouldn't be an issue if your text isn't actually behind a cyan background-color; it's hard to tell on a white background.
.parent {
position: absolute;
height: 100px;
width: 400px;
overflow: scroll;
}
.content {
background-color: cyan;
padding: 6px;
overflow: clip;
overflow-clip-margin: content-box;
}
.icon {
float: left;
clear: both;
background-color: lightpink;
width: 38px;
height: 38px;
margin-right: 8px;
margin-bottom: 6px;
}
.entry {
font-size: 18px;
}
<div class="parent">
<div class="content">
<img class="icon">
<img class="icon">
<img class="icon">
<img class="icon">
<div class="entry">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
<div class="entry">Quisque eleifend viverra risus, nec maximus nisi vestibulum eu</div>
<div class="entry">Mauris in libero lacus</div>
</div>
</div>
.parent {
position: absolute;
height: 100px;
width: 400px;
overflow: scroll;
}
.content {
background-color: cyan;
padding: 6px 6px 0 6px;
overflow: hidden;
position: relative;
border-bottom: 8px solid cyan; /* same color */
}
.icons,
.entries {
display: flex;
flex-direction: column;
}
.icons {
position: absolute;
top: 8px;
left: 8px;
}
.entries {
margin-left: 56px; /* icon width '38' + icon left '8' and right '8' distance */
}
.icon {
background-color: lightpink;
width: 38px;
height: 38px;
margin-bottom: 6px;
}
.entry {
font-size: 18px;
}
<div class="parent">
<div class="content">
<div class="icons">
<img class="icon">
<img class="icon">
<img class="icon">
<img class="icon">
</div>
<div class="entries">
<div class="entry">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
<div class="entry">Quisque eleifend viverra risus, nec maximus nisi vestibulum eu</div>
<div class="entry">Mauris in libero lacus</div>
</div>
</div>
</div>
So I have this black transparent box in my header. It's got some text inside. When the text shrinks I want the the box to shrink as well, but I want it to shrink proportionately. The problem I'm running into is that when I shrink the text in my media queries, the width of the p tags doesn't shrink with it. so This pushes the right side of its parent farther out making it disproportional. I've tried setting the p tags to inline but then the parent won't shrink to fit the tags unless I set the parent to inline. And If I do that I need to use flexbox to stack the p tags on top of each other again, and I can't use display: flex cause its already display: inline. Any Ideas?
const navLinks = document.querySelectorAll('.nav-links .link');
const linksArray = Array.from(document.querySelectorAll('.links div'));
const header = document.querySelector('header');
const form = document.querySelector('form');
for (var i = 0; i < navLinks.length; i++) {
navLinks[i].addEventListener('click', changeColor);
}
for (var i = 0; i < linksArray.length; i++) {
linksArray[i].addEventListener('click', shuffle);
}
function changeColor() {
let hexArray = [0, 1, 2, 3, 4, 5, 6, 'A', 'B', 'C', 'D', 'E', 'F'];
let hexColor = '#';
for(let i = 0; i < 6; i++) {
let random = Math.floor(Math.random()*hexArray.length);
hexColor += hexArray[random];
}
header.style.backgroundImage = 'none';
header.style.backgroundColor = hexColor;
setTimeout(function() {
header.style.backgroundImage = 'url(img/canada.jpeg)';
}, 2000);
}
function shuffle() { // Fisher-Yates shuffle algorithm
for (let i = linksArray.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[linksArray[i].innerHTML, linksArray[j].innerHTML] = [linksArray[j].innerHTML, linksArray[i].innerHTML];
}
}
form.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.querySelector('.name').value;
const address = document.querySelector('.address').value;
const city = document.querySelector('.city').value;
const dialog = document.querySelector('.dialog-wrap');
const close = document.querySelector('.close');
dialog.style.display = 'block';
document.querySelector('.dialog-name').innerHTML = name;
document.querySelector('.dialog-address').innerHTML = address;
document.querySelector('.dialog-city').innerHTML = city;
close.onclick = () => {
dialog.style.display = 'none';
document.querySelector("form").reset();
}
})
html, body {
margin: 0;
padding: 0;
}
body {
font-family: 'Verdana';
box-sizing: border-box;
color: #63889b;
}
* {
outline: 1px solid red;
}
/*------NAV-----*/
nav {
display: flex;
justify-content: space-between;
font-size: 1.8rem;
padding: 25px 0;
position: fixed;
background-color: #fff;
width: 100%;
top: 0;
left: 0;
right: 0;
z-index: 10;
box-shadow: 0px 0px 70px rgb(99, 99, 99, 0.5);
}
.brand, .nav-links {
display: flex;
align-items: center;
}
.brand {
margin-left: 6%;
}
.logo {
max-width: 70px;
max-height: 45px;
margin-right: 25px;
}
.nav-links {
position: relative;
margin-right: 6%;
}
.nav-links .link {
text-transform: uppercase;
margin-right: 20px;
cursor: pointer;
transition: all .2s ease;
}
.nav-links .link:hover {
color: #014263;
}
/*-----HEADER-----*/
header {
margin-top: 92px;
background-image: url(img/canada.jpeg);
background-position: center;
background-size: cover;
padding-top: 7%;
padding-bottom: 25%;
}
.header-info {
display: inline-block;
color: #fff;
font-size: 1.5rem;
background-color: rgba(0,0,0,0.6);
padding: 35px;
margin-left: 10%;
}
header p {
margin: 0;
padding: 0;
}
header p:first-child {
margin-bottom: 25px;
}
/*-----MAIN-----*/
main {
display: flex;
background-color: #fff;
}
.col {
flex-basis: 33.33%;
padding: 50px 0 40px 0;
}
.col p {
width: 65%;
font-size: 1.25rem;
text-align: center;
margin-left: auto;
margin-right: auto;
}
.col img {
display: block;
margin: 0 auto;
}
.col-3 img {
width: 280px;
height: 155px;
}
.col-3 img, .col-3 h3, .col-3 p {
position: relative;
top: -8px;
}
.col-2 img, .col-2 h3, .col-2 p {
position: relative;
top: 30px;
}
.col-1 {
margin-left: 7%;
}
.col-3 {
margin-right: 7%;
}
h3 {
text-align: center;
}
/*------FOOTER-----*/
footer {
font-family: 'Helvetica';
background-color: #63889b;
display: flex;
justify-content: space-between;
color: #fff;
padding-bottom: 30px;
}
.internal-links {
padding-left: 15%;
font-size: 1.5rem;
}
.links div {
margin:2px 0;
cursor: pointer;
}
.internal-links h4 {
text-decoration: underline;
text-align: center;
margin-bottom: 8px;
margin-top: 30PX;
color: #fff;
}
.links {
font-size: 1.2rem;
display: flex;
flex-direction: column;
}
.form-wrap {
padding-top: 30px;
display: flex;
align-items: flex-end;
flex-basis: 50%;
}
form {
margin: 0 100px 0 0;
display: flex;
flex-direction: column;
width: 100%;
}
input {
border: none;
outline: none;
font-size: 1.6rem;
}
label {
font-size: 1.3rem;
padding: 3px 0;
}
button {
margin-top: 20px;
border: 1px solid #fff;
width: 50%;
font-size: 1.3rem;
background-color: #1090d1;
align-self: flex-end;
color: #fff;
padding: 4px 30px;
}
.dialog-wrap {
background-color: rgba(0,0,0,0.7);
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
z-index: 1000;
display: none;
}
dialog {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 500px;
height: 220px;
border: none;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
dialog div {
font-size: 1.4rem;
color: #fff;
margin: 10px 0;
outline: 1px solid #63889b;
}
dialog div:first-child {
margin-top: 0px;
}
dialog .label {
background-color: #63889b;
padding: 7px;
display: inline-block;
width: 30%;
margin: 0;
text-align: center;
}
dialog .info {
display: inline-block;
padding-left: 5px;
color: #000;
}
dialog button {
border: none;
width: 100%;
margin: auto;
padding: 7px;
}
dialog button:hover {
cursor: pointer;
transition: all .3s ease;
background-color: #0675ad;
}
dialog div:last-child {
outline: none;
}
#media screen and (max-width: 1600px) {
.header-info {
font-size: 1.4rem;
width: 392px;
margin-left: 7%;
}
}
#media screen and (max-width: 1400px) {
.col p, .links {
font-size: 1.1rem;
}
}
#media screen and (max-width: 1200px) {
nav {
font-size: 1.5rem;
}
.header-info {
font-size: 1.3rem;
}
.col-1 img {
width: 270px;
height: 132px;
}
.col-2 img {
width: 280px;
height: 107px;
}
.col-3 img {
width: 250px;
height: 140px;
}
.col p, .links, label {
font-size: 1rem;
}
}
#media screen and (max-width: 1000px) {
.col p {
width: 85%;
}
.col-1 img {
width: 230px;
height: 112px;
}
.col-2 img {
width: 220px;
height: 82px;
}
.col-3 img {
width: 210px;
height: 120px;
}
button {
font-size: 1.1rem;
}
dialog div {
font-size: 1.2rem;
}
}
#media screen and (max-width: 925px) {
}
#media screen and (max-width: 900px) {
.header-info {
font-size: 1.1rem;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapman Automotive Skills Assessment</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav>
<div class="brand">
<img src="img/Logo.png" alt="logo" class="logo">
<div class="comp-name">CHAPMAN</div>
</div>
<div class="nav-links">
<div class="link">Home</div>
<div class="link">Sales</div>
<div class="link">Blog</div>
<div class="link">Login</div>
</div>
</nav>
<header>
<div class="header-info">
<p>We are a company that does stuff.</p>
<p>Car and web stuff.</p>
</div>
</header>
<main>
<div class="col col-1">
<img src="img/car1.jpg" alt="car1">
<h3>Some Header</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo tempore quia enim quod, perferendis illum quae id, natus dolores temporibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati, rem. Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div class="col col-2">
<img src="img/car2.jpg" alt="car2">
<h3>More Stuff</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo tempore quia enim quod, perferendis illum quae id, natus dolores temporibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo, dolor. Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div class="col col-3">
<img src="img/car3.jpg" alt="car3">
<h3>Last Column</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo tempore quia enim quod, perferendis illum quae id, natus dolores temporibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Esse, ipsa. Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
</main>
<footer id="footer">
<div class="internal-links">
<h4>Internal Links</h4>
<div class="links">
<div>Page One</div>
<div>Another Page</div>
<div>Sales Page</div>
<div>Page Three</div>
<div>Keep Going</div>
<div>Last One</div>
<div>Just Kidding</div>
</div>
</div>
<div class="form-wrap">
<form>
<label for="Name">Name</label>
<input type="text" class="name" required>
<label for="Name">Address</label>
<input type="text" class="address" required>
<label for="Name">City</label>
<input type="text" class="city" required>
<button type="submit" id="submit">Submit Form</button>
</form>
<div class="dialog-wrap">
<dialog>
<div><span class="label">Name:</span><span class="dialog-name info"></span></div>
<div><span class="label">Address:</span><span class="dialog-address info"></span></div>
<div><span class="label">City:</span><span class="dialog-city info"></span></div>
<div><button class="close">Close</button></div>
</dialog>
</div>
</footer>
<script src="script.js"></script>
</body>
</html>
I can't use magic numbers.
How do you shrink the text?
I tried your code and it seems to scale fine when the font size is modified in 'header p' with the font-size CSS property.
header p {
font-size: 50%;
}
I have got my footer to stay at the bottom of the page however it is overlapping the content and i cant stop it.
I have looked all over the internet for a solution and none works. I have a feeling that i need to move divs around etc but i could be wrong.
Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=Concert+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Eczar" rel="stylesheet">
<link rel="stylesheet" href="style/stylesheet.css">
<title>Layout</title>
</head>
<body>
<div id="header">
<img src="img/top-bar/bar.png" height="10px" class="top">
<ul id="menu-bar">
<li>Home</li>
<li>Page 1</li>
<li class="dropdown">
Page 2
<div class="dropdown-content">
Drop 1
Drop 2
</div>
</li>
<li>Page 3</li>
<li>Login</li>
</ul>
<img src="img/archery-1839284.jpg" class="cover">
</div>
<div id="wrapper">
<div id="content">
<div id="first" class="item">
<p class="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime distinctio sed officia, nam iure quam necessitatibus nobis non, aut quaerat autem. Quam mollitia, fugiat amet veritatis, voluptate earum quidem et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci ex earum impedit ipsum consequatur dolor doloremque eum. Sed fugit dolor maiores pariatur nesciunt iste cupiditate consequuntur, dolore alias numquam voluptatum!
</p>
</div>
<div id="img-span">
<img src="img/board-911636.jpg" class="wide">
</div>
<div class="item" style="background-color: red;">
<p class="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem sit non ipsam aut perferendis neque magnam deleniti, officia necessitatibus porro odio ipsum est eum aliquam nulla placeat, deserunt? Atque, nisi.
</p>
</div>
</div>
<div id="footer">
<img src="img/top-bar/bar.png" height="10px" class="bottom">
</div>
</div>
</body>
</html>
CSS:
body {
background-color: grey;
margin: 0;
padding: 0;
font-family: 'Eczar', serif;
scroll-behavior: smooth;
}
#header {
position: relative;
text-align: center;
}
.top {
position: fixed;
width: 100%;
z-index: 3000;
left: 0;
top: 0;
}
.bottom {
width: 100%;
position: absolute;
bottom: 0;
left: 0;
}
#wrapper {
padding: 0;
margin: 0;
position: absolute;
width: 100%;
margin-top: 100%;
}
.cover {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
max-width: 100%;
background-image: url(../img/archery-1839284.jpg);
overflow: hidden;
}
#content {
width: 100%;
top: 100%;
height: 100%;
position: relative;
background-color: blue;
text-align: center;
}
.item {
padding-left: 20%;
padding-right: 20%;
padding-top: 4px;
padding-bottom: 4px;
overflow: hidden;
margin: 0;
position: relative;
}
.item p {
font-size: 18px;
}
.img-span {
padding: 0;
margin: 0;
width: 100%;
position: relative
}
.wide {
width: 100%;
height: 100%;
opacity: 1;
overflow: hidden;
display: block;
}
#footer {
width: 100%;
height: 70px;
background-color: greenyellow;
z-index: 3000;
bottom: 0;
left: 0;
position: absolute;
clear: both;
}
Just set the #footer to position: relative; will fix the overlapping issue.
#footer {
width: 100%;
height: 70px;
background-color: greenyellow;
position: relative;
clear: both; }
But you should have a look at the following website which explains how to create a footer that will always stick on the bottom of the page, with large or with small contents. This would be a much better way.
http://www.cssstickyfooter.com/using-sticky-footer-code.html
I don't think that the way you go at it is the best but what would work in your case is to change your wrapper class adding a padding bottom equal to your footer height like:
#wrapper {
padding: 0 0 10px 0;
margin: 0;
position: absolute;
width: 100%;
margin-top: 100%;
}
#footer {
height:10px;
}
As per your problem you want stick your footer to the bottom of your page right ? so, that you have to put following css code to
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom:70px;
}
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>
I am using display:flex in order to center/vertically center the content on the page. I have set a media query so that there is a hamburger menu for mobile size. However, there appears to be a right margin on the homePage. No matter what I try, I can't get the margin to go away. Here's a jsfiddle of it. Please help!
http://jsfiddle.net/crcommons/Lxepj9ko/2/
(p.s. make sure you adjust the browser size so that it is in mobile).
$('.hamburger').on('click', function() {
$('.menu').slideToggle();
});
function setPageHeight () {
var windowHeight = $(window).height();
var headerHeight = $('header').height();
pageHeight = (windowHeight - headerHeight);
$('.homePage').css('min-height', pageHeight + 'px');
};
setPageHeight();
$(window).resize(setPageHeight);
*, *:after, *:before {
box-sizing: border-box
}
body {
font-size: 18px;
}
.container {
margin: 0 auto;
}
nav {
background-color: white;
max-width: 100%;
padding-top: .75em;
}
.mainNav {
max-width: 1024px;
margin: 0 auto;
}
.mainNav li {
width: 19%;
display: inline-block;
border-right: 1px solid black;
text-align: center;
}
.mainNav li:last-child {
border-right: none;
}
.hamburger {
display: none;
line-height: .3em;
}
.hamburger:before {
content: "≡";
}
.homePage {
background-color: #CBD5D2;
max-width: 100%;
display: flex;
}
.introduction {
max-width: 40em;
margin: auto;
}
.logo {
text-align: center;
}
.tagline {
font-size: 3em;
text-align: center;
}
.introduction p {
text-align: justify;
}
#media screen and (max-width: 479px) {
.wrapper {
padding: 1.5em;
}
nav {
display: none;
}
.hamburger {
display: inline-block;
font-size: 3.5em;
text-decoration: none;
float: right;
}
.navigation {
float: left;
float: left;
position: absolute;
right: 0;
margin-top: 30px;
padding: 0;
background: gray;
}
.mainNav {
padding: 0;
}
.mainNav li {
display: block;
padding: .5em;
width: 100%;
}
.homePage {
padding: 1em;
}
.tagline {
font-size: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="container">
<header>
<div>
</div>
<nav class="navigation menu">
<ul class="mainNav">
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
<div class="homePage">
<div class="introduction">
<h1 class="logo">Title</h1>
<h2 class="tagline">Lorem ipsum dolor sit.</h2>
<p class="introP">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis nam velit, voluptates dolore consequuntur ea tempore laborum mollitia, corporis impedit distinctio aperiam itaque perspiciatis repellat neque facilis esse molestiae maiores eum, incidunt eius quaerat! Dicta illo ut, incidunt ratione magni cum unde architecto obcaecati illum harum tempora veniam placeat voluptatem.</p>
</div>
</div>
</body>
One option to solve this would be within the .hamburger class media query setting position: absolute; right: 0px;
This is happening because .hamburger is floating right, and there is nothing to clear the float. .homepage has a max-width: 100% but the width is not set. Since the homepage isn't 100%, it will float around the hamburger.
Clear the float:
header::after {
content: '';
display: block;
clear: both;
}
Set homepage width to 100%:
.homepage {
background-color: #CBD5D2;
max-width: 100%;
width: 100%;
display: flex;
}