CSS bottom aligning causing overlapping text - css

I'm having an issue with absolute and relative positing with regard to aligning an element to the bottom of another. I've set this up http://jsfiddle.net/sitrobotsit/xLahG/8/ to illustrate the problem. Basically, the bottom aligned element is overlapping the text above it.
HTML
<div class="subevents">
<ul id="events_gallery">
<li class="events_column">
<img src="http://placekitten.com/130/100">
<h3>Some heading</h3>
<p>Some vairable length text. Sed ut perspiciatis
unde omnis iste natus error sit voluptatem accusantium.</p>
<p class="bottom">Overlapping link</p>
</li>
</ul>
</div>​
CSS
#events_gallery li {
border: solid 1px #999;
list-style-type: none;
position: relative;
width: 295px;
}
#events_gallery li p, #events_gallery li h3 {
left: 139px;
}
#events_gallery li img {
float: left;
}
#events_gallery li .bottom {
vertical-align: bottom;
position: absolute;
bottom: 0;
}

Modify your design like this:
<div class="subevents">
<ul id="events_gallery">
<li class="events_column">
<img src="http://placekitten.com/130/100">
<h3>Some heading</h3>
<p class="content">Some vairable length text. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium. </p>
<p class="bottom">Find out more</p>
</li>
</ul>
</div>​
and the CSS:
#events_gallery li {
border: solid 1px #999;
margin: 0 0 5px 0;
list-style-type: none;
position: relative;
width: 295px;
}
#events_gallery li p, #events_gallery li h3 {
padding: 0;
margin: 0 0 4px 139px;
}
#events_gallery li p.content {
margin-bottom:24px;
}
#events_gallery li img {
float: left;
margin: 0 5px 5px 0;
padding: 2px;
}
#events_gallery li .bottom {
vertical-align: bottom;
position: absolute;
bottom: 0;
}
​

Remove position:absolute from
#events_gallery li .bottom {
vertical-align: bottom;
position: absolute;
bottom: 0;
}
and see it here in action

Related

nav elements not aligned + overlapping problem

I have two major problems with my code.
Problem 1 - Alignment: Inside the <nav> I created two <div> tags. One for the logo, and one for the hyperlinks, but I can't manage to align then. I've been stuck on this for hours.
Problem 2 - Overlapping: If the screen-size is a bit small, when I hover over an element of the navigation bar they overlap each other, which in theory is fine, however it doesn't cover the element behind, so both element keeps displaying.
Is there a way to prevent this from happening? btw, this problem only happens when I'm using a small screen size.
The image below can illustrate both problems:
body{
background-color: rgb(210,210,210);
margin:0px;
padding: 0px;
}
nav{
background-color: rgb(97, 97, 97);
padding-top: 10px;
padding-bottom: 10px;
padding-left: 10px;
padding-right:10px;
display: flex;
}
section{
padding: 0 10%;
}
#Logo{
width: 20%;
height: inherit;
float: left;
clear: left;
}
#Hyperlinks{
width: 80%;
float: right;
text-align: right;
}
#Logo p{
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande';
font-size: 120%;
color: white;
padding-left: 40px;
}
#Hyperlinks a{
font-size: 1.2rem;
text-align: center;
text-decoration: none;
color: white;
padding-right: 5px;
}
#Hyperlinks li li>a{
font-size: 1.1rem;
}
#Hyperlinks>ul>li:hover {
background-color: rgb(27, 129, 107);
border-radius: 0 0 10px 0;
}
#Hyperlinks ul li li:hover{
background-color: rgb(27, 129, 107);
}
#Hyperlinks ul ul li:last-child{
border-radius: 0 0 10px 0;
}
#Hyperlinks>ul>li>a{
border-right:solid white 3px;
}
#Hyperlinks ul{
padding-inline-start: 0;
}
#Hyperlinks>ul>li{
display: inline-block;
padding: 10px 50px 10px 2px;
margin-right: 10px;
}
#Hyperlinks ul ul{
display: none;
}
#Hyperlinks>ul>li{
position: relative;
}
#Hyperlinks ul li:hover ul{
display: block;
position: absolute;
width: 92%;
left: 0%;
top: 42px;
background-color: rgb(97, 97, 97);
border-radius: 0 0 10px 0;
}
#Hyperlinks li:hover li{
display: block;
padding: 1em 0em 1em 5px;
text-align: left;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Navigation Bar 3</title>
<link rel="stylesheet" href="gabarito2.css">
</head>
<body>
<header>
<nav>
<div id="Logo">
<p>MySite.com</p>
</div>
<div id="Hyperlinks">
<ul>
<li>Home</li>
<li>Tutorial
<ul>
<li>Tutorial 1</li>
<li>Tutorial 2</li>
<li>Tutorial 3</li>
</ul>
</li>
<li>About</li>
<li>Newsletter
<ul>
<li>News 1</li>
<li>News 2</li>
<li>News 3</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
</nav>
</header>
<section>
<h2>Test</h2>
<p>Hello, it`s just a test. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia, temporibus, culpa.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia, temporibus, culpa! Impedit amet voluptates reiciendis esse quisquam. Eum quia, facere laboriosam quos possimus, ratione, optio incidunt sunt dolorum commodi magni.</p>
</section>
</body>
</html>
Get rid of all the floats and use flexbox exclusively. Make sure your ul and li have no default margins and paddings.
Just set a background color and z-index if necessary.

CSS - Fixed button on expanding

I am trying to make the search bar expand on device size < 768px. GIF Image.
How to fixed button when I click expand?
#media (max-width: 768px) {
.header-search {
margin-left: 1em;
.search-bar {
max-width: 3em;
margin-left: auto;
&:focus-within {
max-width: 100%;
.search-bar__input {
width: auto;
padding: 0 1em;
}
}
}
.search-bar__input {
width: 0;
padding: 0;
}
}
}
Here is my codepen:
https://codepen.io/phamtien990819/pen/PoqGwEv
I suggest remove the line width:auto in &:focus-within .search-bar__input.
Moreover, you can add padding transition to .search-bar__input to make the transition smoother
#media (max-width: 768px) {
.header-search {
margin-left: 1em;
.search-bar {
max-width: 3em;
margin-left: auto;
&:focus-within {
max-width: 100%;
.search-bar__input {
/*Remove width: auto*/
padding: 0 1em;
}
}
}
.search-bar__input {
width: 0;
padding: 0;
/*Add padding transition*/
transition: padding 3s
}
.search-bar__btn { }
}
}
This CSS code I updated. I used position: absolute; to place button on right of the bar. So even after input is opened button stays on right without moving.
#media (max-width: 768px) {
.header-search {
margin-left: 1em;
position: relative;
.search-bar__input {
margin-left: 10px;
background: transparent;
overflow: hidden;
}
.search-bar__btn {
width: 40px;
position: absolute;
right: 1px;
height: 29px;
}
body {
display: flex;
flex-direction: column;
margin: 0;
min-height: 100vh;
font-size: 14px;
}
ol,
ul {
padding: 0;
margin: 0;
list-style: none;
}
main {
flex: 1;
}
.material-icons {
font-size: 24px;
vertical-align: middle;
}
.material-icons::before {
content: attr(icon);
}
.site-header {
position: sticky;
top: -40px;
width: 100%;
z-index: 99;
background: #fff;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.top-nav {
background: rgba(0, 0, 0, 0.03);
}
.top-nav .container {
display: flex;
justify-content: space-between;
align-items: center;
height: 40px;
}
.top-nav ul {
display: flex;
font-size: 12px;
list-style: none;
}
.top-nav ul>li+li {
margin-left: 1.5em;
}
.top-nav ul a {
color: currentColor;
}
.main-nav .container {
display: flex;
justify-content: space-between;
align-items: center;
height: 5em;
}
.header-brand {
display: flex;
align-items: center;
justify-content: space-between;
}
.header-brand .logo {
text-decoration: none;
color: currentColor;
}
.header-brand .menu-toggle {
display: none;
border: 0;
outline: 0;
background: transparent;
margin-left: 1em;
padding: 6px;
}
/* BEGIN SEARCH BAR */
.header-search {
flex: auto;
margin-left: 4em;
}
.header-search .search-bar {
display: flex;
align-items: center;
border: 1px solid rgba(0, 0, 0, 0.1);
max-width: 25em;
height: 2.5em;
transition: all 3s;
}
.header-search .search-bar__input {
flex: auto;
height: 100%;
border: 0;
padding: 0 1em;
outline: 0;
}
.header-search .search-bar__btn {
width: 3em;
height: 100%;
border: 0;
outline: 0;
text-align: center;
}
#media (max-width: 768px) {
.header-search {
margin-left: 1em;
position: relative;
}
.header-search .search-bar__input {
margin-left: 10px;
background: transparent;
overflow: hidden;
}
.header-search .search-bar__btn {
width: 40px;
position: absolute;
right: 1px;
height: 29px;
}
.header-search .search-bar {
max-width: 3em;
margin-left: auto;
}
.header-search .search-bar:focus-within {
max-width: 100%;
}
.header-search .search-bar:focus-within .search-bar__input {
width: auto;
}
.header-search .search-bar__input {
width: 0;
padding: 0;
}
}
/* END SEARCH BAR */
.header-user {
display: flex;
align-items: center;
}
.header-user .item {
position: relative;
flex-shrink: 0;
display: inline-flex;
}
.header-user .item .user-link {
font-weight: 500;
color: currentColor;
padding: 6px;
border-radius: 4px;
margin-left: 8px;
}
.header-user .item .user-link:hover {
text-decoration: none;
background-color: rgba(0, 0, 0, 0.03);
}
#media (max-width: 768px) {
.s-header {
top: 0;
}
.top-nav {
display: none;
}
.main-nav .container {
height: 4em;
}
.header-brand .menu-toggle {
display: inline-block;
margin-left: 0;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<body>
<header class="site-header">
<div class="top-nav">
<div class="container">
<ul>
<li>Top menu item</li>
<li>Top menu item</li>
<li>Top menu item</li>
<li>Top menu item</li>
<li>Top menu item</li>
</ul>
</div>
</div>
<nav class="main-nav">
<div class="container">
<div class="header-brand">
<a class="logo d-none d-md-inline-block" href="#">LOGO HERE</a>
<button class="menu-toggle">
<i class="material-icons" icon="menu"></i>
</button>
</div>
<div class="header-search">
<form action="#" class="search-bar">
<input class="search-bar__input" type="search" placeholder="Search..." />
<button class="search-bar__btn" type="button">
<i class="material-icons" icon="search"></i>
</button>
</form>
</div>
<ul class="header-user">
<li class="item">
<a class="user-link" href="#">
<i class="material-icons" icon="person_add"></i>
<span class="d-none d-md-inline">Login / Register</span>
</a>
</li>
</ul>
</div>
</nav>
</header>
<main>
<div class="container" style="height: 1000px">
<p class="mt-4">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. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</main>
<footer>
<div class="container">
<p>Footer content</p>
</div>
</footer>
</body>

CSS padding-bottom not working

I'm currently trying to add some simple padding to the bottom of my testimonial element, so that it doesn't end right after the text.
It seems that no matter what value I enter in padding or padding-bottom, the bottom padding expands a set amount. I'm wondering how to fix this so it displays padding that is specific to the value I set.
/****
GENERAL
****/
* {
margin: 0;
padding: 0;
font-family: sans-serif;
color: black;
}
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 120px;
}
li {
list-style: none;
}
a, a:visited {
text-decoration: none;
color: black;
cursor: pointer;
}
a:hover {
color: #009999;
}
.divide {
width: 75%;
border: 1px solid grey;
margin: 20px auto;
}
/****
NAVIGATION
****/
.navigation {
display: flex;
flex-direction: row;
justify-content: center;
z-index: 1000;
}
.navigation li {
display: inline-block;
padding: 5px;
}
.navigation li a {
padding: 8px 10px;
display: block;
}
.submenu {
position: relative
}
.sub-hover {
position: absolute;
width: 106.42px;
display: none;
}
.sub-hover a {
font-size: 1em;
}
.submenu:hover ~ .sub-hover,
.sub-hover:hover {
display: block;
background-color: rgba(38, 12, 12, 0.04);
border-bottom-left-radius: 5%;
border-bottom-right-radius: 5%;
}
/****
LOGO
****/
.circle {
border: 1px solid gray;
border-radius: 100%;
height: 90px;
width: 90px;
margin-left: auto;
margin-right: auto;
margin-bottom: 30px;
clear: both;
}
/****
IMAGE SLIDER
****/
.main-gallery {
background-color: rgba(38, 12, 12, 0.03);
border-radius: 5px;
height: 450px;
clear: both;
margin-bottom: 25px;
}
/****
TESTIMONIAL
****/
.testimonial {
clear: both;
display: block;
margin: 10px 0;
padding: 0 5%;
background-color: rgba(50, 173, 140, 0.82);
}
/****
SOCIAL
****/
.insta {
height: 50px;
width: 90%;
background-color: blue;
margin: 10px auto;
}
/****
FOOTER
****/
.footer {
background-color: grey;
height: 100px;
clear: both;
bottom: 0;
position: absolute;
}
.footer p {
text-align: center;
padding: 20px;
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/normalize.css">
<link type="text/css" rel="stylesheet" href="css/skeleton.css">
<link type="text/css" rel="stylesheet" href="css/main.css">
</head>
<body>
<ul class="navigation six columns offset-by-three">
<li>HOME</li>
<li>PORTFOLIO
<div class="sub-hover">
Photos
Physical
Write
Studies
</div>
</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
<div id="logo">
<div class="circle">
</div>
</div>
<div class="main-gallery eleven columns offset-by-half">
<div id="main-images">
<img src=""/>
<img src=""/>
<img src=""/>
<img src=""/>
</div>
</div>
<div class="testimonial">
<div class="test-text">
<p><b>Joe Blogs</b></p>
<p>Distinguished Person</p>
<p><i>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas et orci sit amet nibh aliquam auctor eu eget turpis. Quisque quis leo lacus. Etiam vitae magna eu arcu gravida tincidunt. Ut consectetur mi id enim."</i></p>
</div>
</div>
<div class="divide"></div>
<div class="insta">
</div>
<div class="footer twelve columns">
<p>Jacob Riman Design</p>
</div>
</body>
</html>
How padding shorthand works....
default declaration of padding looks like this:
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
You can abbreviate that and apply padding to all sides equally:
padding: 10px;
You can abbreviate a little less and apply different values to top and bottom, and right and left.
This equates to padding: top/bottom right/left;
padding: 10px 20px;
You can use full abbreviations to apply different values to each of the 4 sides independently:
This equates to padding: top right bottom left; or:
padding: 10px 20px 5px 20px;
In your CSS you have no top or bottom padding applied to the testimonial class, you only have right/left padding applied:
.testimonial {
padding: 0 5%;
}
You basically have (pseudo code as example):
.testimonial {
padding: top=0 right=5% bottom=0 left=5%;
}
If you want a the same padding all the way around, remove the first 0 in the property:
.testimonial {
padding: 5%;
}
If you want a similar top/bottom padding, then merely adjust the padding property to add top/bottom values:
.testimonial {
padding: 10% 5%;
}
If you want different padding on the top and bottom, then adjust the padding property to add all the values:
.testimonial {
padding: 0 5% 10% 5%;
}
You don't have any bottom padding. Changing to padding: 10px 5% adds 10px padding to the top and bottom, 5% to the left and right.
/****
GENERAL
****/
* {
margin: 0;
padding: 0;
font-family: sans-serif;
color: black;
}
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 120px;
}
li {
list-style: none;
}
a, a:visited {
text-decoration: none;
color: black;
cursor: pointer;
}
a:hover {
color: #009999;
}
.divide {
width: 75%;
border: 1px solid grey;
margin: 20px auto;
}
/****
NAVIGATION
****/
.navigation {
display: flex;
flex-direction: row;
justify-content: center;
z-index: 1000;
}
.navigation li {
display: inline-block;
padding: 5px;
}
.navigation li a {
padding: 8px 10px;
display: block;
}
.submenu {
position: relative
}
.sub-hover {
position: absolute;
width: 106.42px;
display: none;
}
.sub-hover a {
font-size: 1em;
}
.submenu:hover ~ .sub-hover,
.sub-hover:hover {
display: block;
background-color: rgba(38, 12, 12, 0.04);
border-bottom-left-radius: 5%;
border-bottom-right-radius: 5%;
}
/****
LOGO
****/
.circle {
border: 1px solid gray;
border-radius: 100%;
height: 90px;
width: 90px;
margin-left: auto;
margin-right: auto;
margin-bottom: 30px;
clear: both;
}
/****
IMAGE SLIDER
****/
.main-gallery {
background-color: rgba(38, 12, 12, 0.03);
border-radius: 5px;
height: 450px;
clear: both;
margin-bottom: 25px;
}
/****
TESTIMONIAL
****/
.testimonial {
clear: both;
display: block;
margin: 10px 0;
padding: 10px 5%;
background-color: rgba(50, 173, 140, 0.82);
}
/****
SOCIAL
****/
.insta {
height: 50px;
width: 90%;
background-color: blue;
margin: 10px auto;
}
/****
FOOTER
****/
.footer {
background-color: grey;
height: 100px;
clear: both;
bottom: 0;
position: absolute;
}
.footer p {
text-align: center;
padding: 20px;
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/normalize.css">
<link type="text/css" rel="stylesheet" href="css/skeleton.css">
<link type="text/css" rel="stylesheet" href="css/main.css">
</head>
<body>
<ul class="navigation six columns offset-by-three">
<li>HOME</li>
<li>PORTFOLIO
<div class="sub-hover">
Photos
Physical
Write
Studies
</div>
</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
<div id="logo">
<div class="circle">
</div>
</div>
<div class="main-gallery eleven columns offset-by-half">
<div id="main-images">
<img src=""/>
<img src=""/>
<img src=""/>
<img src=""/>
</div>
</div>
<div class="testimonial">
<div class="test-text">
<p><b>Joe Blogs</b></p>
<p>Distinguished Person</p>
<p><i>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas et orci sit amet nibh aliquam auctor eu eget turpis. Quisque quis leo lacus. Etiam vitae magna eu arcu gravida tincidunt. Ut consectetur mi id enim."</i></p>
</div>
</div>
<div class="divide"></div>
<div class="insta">
</div>
<div class="footer twelve columns">
<p>Jacob Riman Design</p>
</div>
</body>
</html>
.testimonial {
clear: both;
display: block;
margin: 10px 0;
padding: 0 5% 5% 0;
background-color: rgba(50, 173, 140, 0.82);
}
Adding all of the values ( even if 0 ) solved the problem right away.
Also, I am aware that if only two values are given the 1st represents top and bottom.
You don't currently have padding on the bottom of the testimonial div.
.testimonial {
clear: both;
display: block;
margin: 10px 0;
padding: 1% 5%;
background-color: rgba(50, 173, 140, 0.82);
}
Change the padding to the above ... padding: 1% 5%; or to target specifically the bottom ... padding 0 5% 1%; ... do that and you should be good to go, unless I'm misunderstanding your question. Good luck!
Found that having the last set of text in .testimonial in a paragraph tag, it was inserting a line break. So simply took that away and now it seems to be working fine.

Center H2 slightly above it's parent div?

I am trying to position a styled heading to be centered and to sit slightly above it's parent div. I assumed the heading would have to be absolutely positioned to be able to be shifted outside of the parent by adding a negative margin to the top. I can center it when it's position is relative, but I can not add a negative margin to bring it outside of the parent.
HTML
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="content">
<h2 class="content-box-title">A Heading</h2>
<div class="content-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam, culpa illum! Sint maiores numquam provident, consequatur voluptatibus, repudiandae, dolorum sed, itaque saepe magni fugit mollitia! Repellat dignissimos, quas esse itaque.</p>
</div>
</div>
</div>
</div>
</div>
CSS
.content {
position: relative;
background-color: #d5d5d5;
}
.content-box-title {
position: absolute;
background-color: grey;
text-align: center;
padding: 10px;
margin: -40px auto;
}
.content-body {
padding: 20px;
}
http://jsfiddle.net/LsohxL3m/
By making the title an inline-block, you can center it using text-align: center on the parent div. You don't need absolute positioning or auto margin then, so you can just use a negative top margin. You can use text-align left on the content to keep that left aligned:
.content {
background-color: #d5d5d5;
text-align: center;
}
.content-box-title {
display: inline-block;
background-color: grey;
text-align: center;
padding: 10px;
margin-top: -40px;
}
.content-body {
padding: 20px;
text-align: left;
}
Here's a fiddle.
I adjusted that fiddle to include this css content:
.content h2 {
box-sizing: border-box;
margin: -60px auto 0;
width: 100%;
}
an it seemed to center the h2 and set it just a bit above the content div.
but after deeper investigation, it looks like you just need to as a width to your original tag, and the box-sizing rule to assist with the padding/margin on the element.
I appended this to your existing .content-box-title css and it worked fine:
width: 100%;
box-sizing: border-box;
Check now: http://jsfiddle.net/LsohxL3m/1/
I changed the styling of the title as follows:
.content-box-title {
background-color: grey;
text-align: center;
padding: 10px;
margin-top: -40px;
margin-left: auto;
margin-right: auto;
}
You can use translate:
.content-box-title {
position: absolute;
background-color: grey;
text-align: center;
padding: 10px;
margin-top: -40px;
left:50%;
transform: translate(-50%, 0);
}
http://jsfiddle.net/LsohxL3m/6/
change
.content-box-title {
position: absolute;
background-color: grey;
text-align: center;
padding: 10px;
margin: -40px auto;
}
.content-body {
padding: 20px;
}
to
.content-box-title {
transform: translateY(-60px);
background-color: grey;
margin-top: 60px;
text-align: center;
padding: 10px;
}
.content-body {
padding: 0 20px 20px 20px;
}
Here is a sample

Flex creates margin that won't go away

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;
}

Resources