use css to move a div into the row above it - html

My code has 3 divs in a row (gallery, sidebar, description). The HTML needs to remain unchanged, but I need to use CSS to get the .description up under the .sidebar (beside the .gallery) instead of beneath the .gallery.
I want to move that div like so
Code:
<div class="product">
<div class="gallery">
<img src="https://via.placeholder.com/300" alt="item" />
</div>
<div class="sidebar">
<h3>
Sidebar
</h3>
<p>
Product price, etc.
</p>
</div>
<div class="description">
<h3>
Details
</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed eros sem. Aliquam erat volutpat. Phasellus auctor lorem dolor, vitae egestas neque vestibulum sed. Proin sapien purus, faucibus ut elementum eget, consequat sed arcu. Morbi nisl libero,
molestie eget ligula quis, feugiat iaculis felis. Donec condimentum, felis eu sodales interdum, ex purus convallis augue, quis sollicitudin nibh ex vel lorem. Sed eget semper ipsum, vel dictum lorem. Proin ornare massa elit, non aliquam erat ultricies
at.
</p>
</div>
</div>
.product {
box-sizing: border-box;
position: static;
}
.gallery {
box-sizing: border-box;
float: left;
position: relative;
}
.sidebar {
box-sizing: border-box;
float: right;
position: static;
}
.description {
box-sizing: border-box;
clear: left;
float: left;
position: static;
}

If you're willing to use floats, set the width for your elements. Here's fiddle http://jsfiddle.net/y6g4p7u8/1/
I've set the background color for visual display.
.product {
box-sizing: border-box;
background: green;
}
.product:before,
.product:after {
content: " ";
display: table;
}
.product:after {
clear: both;
}
.gallery {
box-sizing: border-box;
width: 35%;
float: left;
background: red;
}
.sidebar {
box-sizing: border-box;
float: left;
width: 65%;
background: lightblue;
}
.description {
box-sizing: border-box;
float: left;
width: 65%;
background: yellow;
}

I suggest you to use a div to wrap both .sidebar and .description.
Then apply display: flex on parent .product.
HTML
<div class="column-wrap">
<div class="sidebar">..</div>
<div class="description">...</div>
</div>
CSS
.product{
display: flex
}
https://jsfiddle.net/blackcityhenry/n9qgvjh6/

css grid would be the easiest, and browser support is now pretty good.
https://css-tricks.com/snippets/css/complete-guide-grid/
https://caniuse.com/#search=grid
If I understand what you are asking correctly you could define your grid template area and then assign your elements to where they need to sit.
From the top of my head it would be something like this, check out the link to css-tricks.
Here is a pen demonstrating https://codepen.io/TomCheckley/pen/dQJQBv
<div class="product">
<div class="gallery">
<img src="https://lorempixel.com/400/200/cats/1" alt="">
</div>
<aside class="sidebar">
<h2>Sidebar</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</aside>
<div class="description">
<h2>Description</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>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.</p>
</div>
</div>
img {
width: 100%;
height: auto;
}
h2 {
margin-top: 0;
}
p:last-child {
margin-bottom: 0;
}
.product {
max-width: 90%;
margin: auto;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-gap: 1.5rem;
grid-template-areas: 'gallery gallery sidebar' 'gallery gallery description';
}
.product > * {
background-color: #c3cece;
padding: 1.5rem;
}
.gallery {
grid-area: gallery;
}
.sidebar {
grid-area: sidebar;
}
.description {
grid-area: description;
}
Well, actually grid maybe not the easiest if you've not used it! But it will give you the most flexible layout options without changing your markdown. It's definitely worth playing around with as browser support is getting near total (apart from IE). You can always progressively enhance as well - float is then overridden by flex and if you put grid after flex in the cascade the browser will use it if it understands it and use flex if it doesn't.

Related

HTML/CSS float issues

I'm trying to get a layout like this picture below but I'm not doing very well.
As you can see, I'm trying to put a picture on the left and a somewhat-complicated div on the right. So far, I've been trying with float without much luck:
#image {
height: 50px;
width: 100px;
float: left;
}
#text {
float: left;
}
.column {
width: 20%;
float: left;
padding-left:10px;
}
.column::after {
clear: both
}
<div id="main_section">
<img id="image" src="http://tny.im/knQ" alt="link picture" />
<div id="text">
<h2> This is the main overhead title </h2>
<p class="column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id lacinia arcu. Sed risus ligula, placerat varius accumsan quis, gravida ut erat.</p>
<p class="column">Maecenas ante ex, dignissim a scelerisque euismod, fermentum at elit. Curabitur convallis, sapien sit amet facilisis interdum.</p>
<h2> This is the end of the section </h2>
</div>
</div>
Sorry to ask a trivial question, I'm googling all over and can't get this to work.
The issue is that #text takes 100% width. So it comes below the image. If you set a specific width for #text, it will float.
#text {
width: 500px;
}
Please try this once
#image {
padding-top:100px;
height: 50px;
width: 100px;
}
.column {
width: 20%;
padding-left:10px;
}
.column::after {
clear: both
}
#main_section{
display: flex;
}
.wrapper{
display: flex;
}
<div id="main_section">
<img id="image" src="http://tny.im/knQ" alt="link picture" />
<div id="text">
<h2> This is the main overhead title </h2>
<div class="wrapper"><p class="column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id lacinia arcu. Sed risus ligula, placerat varius accumsan quis, gravida ut erat.</p>
<p class="column">Maecenas ante ex, dignissim a scelerisque euismod, fermentum at elit. Curabitur convallis, sapien sit amet facilisis interdum.</p></div>
<h2> This is the end of the section </h2>
</div>
</div>
Can you please check the below code? Hope it will work for you. We have solved it with the help of the flex property. If you want to get two elements side by side then flex property is easy and very useful in comparison to float & it sets the flexible length on flexible items.
Please refer to this link: https://jsfiddle.net/yudizsolutions/bysj29tx/1/
.d-flex {
display: flex;
display: -webkit-flex;
}
#image {
height: auto;
align-self: flex-start;
-webkit-align-self: flex-start;
width: 100px;
flex-shrink: 0;
}
h2 {
margin-top: 0px;
}
.row {
margin: 0px -5px;
}
.column {
width: 50%;
padding: 0px 5px;
}
<div class="d-flex" id="main_section">
<img id="image" src="http://tny.im/knQ" alt="link picture" />
<div id="text">
<h2> This is the main overhead title </h2>
<div class="row d-flex">
<p class="column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id lacinia arcu. Sed risus ligula, placerat varius accumsan quis, gravida ut erat.</p>
<p class="column">Maecenas ante ex, dignissim a scelerisque euismod, fermentum at elit. Curabitur convallis, sapien sit amet facilisis interdum.</p>
</div>
<h2> This is the end of the section </h2>
</div>
</div>

My webpage won't stay at full screen on different screen size despite using viewport etc

For my webpage I am tried to make it a one page website that fits all screen without scrolling, but I had white spaces in between my section and nav and footer so I added this box-sizing code:
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
It works for my desktop screen and s10 galaxy phone, but when I check my laptop the footer was stuck at something like "bottom: 10px" but when I check the css using inspect, it shows the css for the footer is at bottom: 0; You can view this bug via the snippet and if the using inspect and change width to >1000px. In my opinion it might have to do with the #media screen and (max-width: 1000px) which i set it to 1000px, If I change the height of section, class main, it will move the footer into the correct position but thats not the case for the different screen size monitors.
If I remove the box-sizing, the white spaces (not padding or margin) is above my section tag which I do not want but the footer is at bottom: 0px. So I am 100% confused. is there something wrong with my css or am I missing something that would be a fix all solution. Any help would be great! Thank you for the help in advance!
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
font-family: sans-serif;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.main {
display: grid;
justify-content: center;
align-content: center;
text-align: center;
height: 91.8%;
padding: 10% 5%;
margin-left: auto;
margin-right: auto;
}
.headerNav {
background-color: rgb(0, 0, 0);
color: white;
font-weight: bold;
z-index: 100;
max-width: 100%;
right: 0;
top: 0;
left: 0;
padding: 10px 0px;
font-size: 20px;
display: grid;
grid-template-columns: auto auto;
}
.homePG {
text-transform: uppercase;
text-decoration: none;
text-align: left;
padding: 10px 10px;
}
.headerLogin {
display: inline;
text-align: right;
line-height: 5px;
grid-gap: 5px;
padding: 0px 10px;
}
.navIcon {
display: none;
text-align: right;
color: blue;
padding: 0px 10px;
}
#mobile-navLinks {
margin-top: 10px;
padding: 0px 5px;
display: none;
text-decoration: none;
text-align: left;
grid-column-start: 1;
grid-column-end: 3;
}
footer {
position: relative;
text-align: center;
background-color: black;
color: white;
padding: 10px;
font-size: 15px;
bottom: 0;
}
#media screen and (max-width: 1000px) {
#mobile-navLinks {
grid-template-columns: 1fr;
}
.main {
height: 91.5%;
}
.homePGh1 {
font-size: 15px;
}
.homePGpara {
font-size: 13px;
}
.headerLogin {
display: none;
}
.navIcon {
display: block;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav class="headerNav">
<nav>
HOME
</nav>
<div class="headerLogin">
HOME
HOME
HOME
</div>
<nav class="navIcon">
<a href="javascript:void(0);" class="icon" onclick="mobileNavs()">
<i class="fa fa-bars"></i></a>
</nav>
<div id="mobile-navLinks">
HOME
HOME
HOME
</div>
</nav>
<section class="main">
<div>
<h1 class="homePGh1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </h1>
<p class="homePGpara">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>
<p class="homePGpara">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Augue interdum velit euismod in pellentesque massa placerat duis ultricies. Purus ut faucibus pulvinar elementum. Nunc sed
blandit libero volutpat. Fermentum leo vel orci porta non pulvinar. </p>
<p class="homePGpara">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Augue interdum velit euismod in pellentesque massa placerat duis ultricies. Purus ut faucibus pulvinar elementum. Nunc sed
blandit libero volutpat. Fermentum leo vel orci porta non pulvinar.</p>
</div>
</section>
<footer>
© 2020
</footer>
</body>
</html>

Center a div unequally using CSS

I am centering a div inside another div using a flexbox. Think of a dialog window that pops up in the center of the screen when needed.
It works fine, however it would look much better if the space above and below the dialog was not exactly equal, having 40% of the remaining space be above and 60% below the dialog. It gets tricky because the dialog height varies with the amount of text inside.
So for example, if the browser height is 1000px, and the dialog window height is 400px, I want the remaining vertical space (600px) to be 240px above and 360px below the dialog.
I could do it with JavaScript, but I'm curious if there is some clever way with CSS. I tried adding a bottom margin to the #dialogBox div, but that doesn't work when the dialog height is getting near the browser height.
#dialogBoxPanel {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
#dialogBox {
width: 350px;
}
<div id="dialogBoxPanel">
<div id="dialogBox">Text</div>
</div>
Use pseudo element and column direction to simulate the white space. Simply adjust the flex-grow of the pseudo element to control how much free space each one should take. Equal flex-grow will give equal space:
#dialogBoxPanel {
position: absolute;
display: flex;
flex-direction: column;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
/* the center */
background:linear-gradient(red,red) center/100% 1px no-repeat;
}
#dialogBox {
width: 350px;
border:1px solid;
}
#dialogBoxPanel:before {
content:"";
flex-grow:4;
}
#dialogBoxPanel:after {
content:"";
flex-grow:6;
}
<div id="dialogBoxPanel">
<div id="dialogBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc hendrerit diam eu nisl fringilla ornare. Pellentesque aliquam quam et tellus egestas sodales. Interdum et malesuada fames ac ante ipsum primis in faucibus. Proin bibendum,</div>
</div>
You can also use 2 and 3. We simply need to keep the same ratio:
#dialogBoxPanel {
position: absolute;
display: flex;
flex-direction: column;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
/* the center */
background:linear-gradient(red,red) center/100% 1px no-repeat;
}
#dialogBox {
width: 350px;
border:1px solid;
}
#dialogBoxPanel:before {
content:"";
flex-grow:2;
}
#dialogBoxPanel:after {
content:"";
flex-grow:3;
}
<div id="dialogBoxPanel">
<div id="dialogBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc hendrerit diam eu nisl fringilla ornare. Pellentesque aliquam quam et tellus egestas sodales. Interdum et malesuada fames ac ante ipsum primis in faucibus. Proin bibendum,</div>
</div>
Another idea is to use top value equal to 40% and rectify the position with translate (same logic with the 50% when centring)
#dialogBoxPanel {
position: absolute;;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
/* the center */
background:linear-gradient(red,red) center/100% 1px no-repeat;
}
#dialogBox {
position:relative;
top:40%;
width: 350px;
transform:translateY(-40%);
margin:auto;
border:1px solid;
}
<div id="dialogBoxPanel">
<div id="dialogBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc hendrerit diam eu nisl fringilla ornare. Pellentesque aliquam quam et tellus egestas sodales. Interdum et malesuada fames ac ante ipsum primis in faucibus. Proin bibendum,</div>
</div>
You can add spacers divs and set the flex-grow with 4:6 ratio.
#dialogBoxPanel {
position: absolute;
display: flex;
flex-direction: column;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
#dialogBox {
width: 350px;
border: 1px solid black;
}
.spacer-top{
flex-grow: 4;
}
.spacer-bottom{
flex-grow: 6;
<div id="dialogBoxPanel">
<div class="spacer-top"></div>
<div id="dialogBox">Text</div>
<div class="spacer-bottom"></div>
</div>
This solution uses display: grid, it's a new feature so be sure to check the browser support and click here to learn more.
This is the line that controls the top and bottom spaces:
grid-template-rows: 40fr [content-start] auto [content-end] 60fr;
The snippet text content can be edited for you to check that the box keeps centered even if the height changes.
#dialogBoxPanel {
display: grid;
place-content: center;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
grid-template-rows: 40fr [content-start] auto [content-end] 60fr;
}
#dialogBox {
border: 1px solid;
width: 350px;
grid-area: content;
}
<div id="dialogBoxPanel">
<div id="dialogBox" contenteditable>Text</div>
</div>
Simple way using position and margin, i assumed that your dialog height is always 40% of browser height.
.modal{
max-height:50%;
width:400px;
margin: 10% auto 5% auto;
position:absolute;
top:0;
bottom:0;
right:0;
left:0;
overflow-y: auto
}
.modal-body{
background-color: beige;
padding: 20px;
line-height: 21px
}
HTML
<div class="modal">
<div class="modal-body">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. 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 </div>
</div>

Changing font color and height of child in parent by calling the class in css

I'm a newbie. I have this code but the problem is i dont know how can i change the paragraph color of each child in the container. and also when i change the height of the 2nd child. Both 1st and 2nd child change height but i only want the child 2 to change height only. Please Help Thank You.
.div-container {
max-width: 1400px;
margin: 40px auto 0px auto;
display: flex;
justify-content: space-around;
}
.container{
padding: 30px;
box-sizing: border-box;
margin-bottom: 20px;
flex-basis: 30%;
}
.container:nth-child(1) {
background-color: #000;
border-radius: 10%;
}
.container:nth-child(2) {
background-color: #cdf1c3;
border-radius: 10%;
}
<title id="page-title"></title>
<div class="div-container">
<div class="container">
<p class="info">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sed euismod nisi porta lorem mollis aliquam. Aliquam faucibus purus in massa tempor. Enim neque volutpat ac tincidunt. At quis risus sed vulputate odio ut enim blandit volutpat.</p>
</div>
<div class="div-container">
<h2 class="h2">Sample</h2>
<p class="p2">P2</p>
<p class="p3">p3</p>
<p id="p4"></p>
</div>
</div>
Each of your paragraphs has a class or id, so you can use that to target the each paragraph separately.
For example:
.div-container .p2 {
color: tomato;
}
Also, default align-items property for flex container is stretch, thats why both of your elements share the same height. You can disable that by setting it to flex-start for example.
.div-container {
display: flex;
align-items: flex-start;
}

Can't get horizontal <UL> menu to center or be wide enough, keeps wrapping to new line

I'm trying to get my webpage to look like this:
http://imgur.com/sRHv30U
I am having trouble with the horizontal menu, though. I'm not sure what I did wrong but it keeps wanting to wrap to the next line for some reason even though there is plenty of room on the current line. I'm sure I'm overlooking something or have done something completely the wrong way. I'm not very good with this sort of thing. Here is my code, any help is appreciated.
Here's my code. I made the #menu background color orange just to try and see what was going on:
#header {
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
color: red;
text-align: center;
}
#menu {
background-color: orange;
float: right;
position: relative;
left: -50%;
text-align: left;
}
ul {
list-style: none;
position: relative;
left: 50%;
}
ul li {
list-style: none;
float: left;
background-color: red;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 15px;
}
ul li a {
text-decoration: none;
color: white;
float: left;
text-align: center;
}
a[href="#"]:hover {
color: white;
background: gray;
}
#left {
margin-top: 100px;
width: 160px;
float: left;
padding: 10px
}
#right {
margin-top: 100px;
width: 160px;
float: right;
padding: 10px;
}
#content {
margin-top: 100px;
margin-left: 200px;
margin-right: 200px;
}
<div id="header">Ball State University Education Redefined
</div>
<div id="menu">
<ul>
<li>About
</li>
<li>Admissions
</li>
<li>Academics
</li>
<li>Campus Life
</li>
<li>Athletics
</li>
<li>News
</li>
<li>Calendar
</li>
<li>Giving
</li>
</ul>
</div>
<br/>
<br/>
<br/>
<div id="left">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.
</div>
<div id="right">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.
</div>
<div id="content">
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 aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue
duis dolore te feugait nulla facilisi.
</div>
Here is an update of your code. Is this the layout you want?
To make it behave I removed float: right;, left: -50%; and changed to text-align: center on #menu, removed left: 50% and added display: inline-block on ul
I also recommend removing the float on the li, and either use flex or display: inline-block.
#charset "UTF-8";
/* CSS Document */
#header {
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
color: red;
text-align: center;
}
#menu {
background-color: orange;
position:relative;
text-align:center;
}
ul {
list-style:none;
position:relative;
display: inline-block;
padding: 0;
}
ul li{
list-style: none;
float: left;
background-color: red;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
}
ul li a {
text-decoration: none;
color: white;
float: left;
text-align: center;
}
a[href="#"]:hover {
color: white;
background: gray;
}
#left {
margin-top: 100px;
width: 160px;
float: left;
padding: 10px
}
#right {
margin-top: 100px;
width: 160px;
float: right;
padding: 10px;
}
#content {
margin-top: 100px;
margin-left: 200px;
margin-right: 200px;
}
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="project1.4.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="header">Ball State University Education Redefined
</div>
<div id="menu">
<ul>
<li>About</li>
<li>Admissions</li>
<li>Academics</li>
<li>Campus Life</li>
<li>Athletics</li>
<li>News</li>
<li>Calendar</li>
<li>Giving</li>
</ul>
</div>
<br/>
<br/>
<br/>
<div id="left">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.
</div>
<div id="right">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.
</div>
<div id="content">
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 aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</div>
</body>
</html>
You don't need to float your centered nav bar. Also, the left: 50%s on both the ul and the container are unnecessary. Instead, center the containing #menu with margin:0 auto and center the lis with display:inline-block and text-align:center. This will allow it to stay in the document's flow, and resize more dynamically. It will now only wrap when the window gets too small.
#menu {
background-color: orange;
margin:0 auto;
position:relative;
text-align:left;
}
ul {
list-style:none;
position:relative;
text-align:center;
}
ul li{
list-style: none;
display:inline-block;
background-color: red;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 15px;
}
https://jsfiddle.net/ez8hy7yt/
Like Blue_Dragon said, you can get rid of several things. I commented out some code in your CSS that you don't need. There may be more. Also, consider adjusting the ul to inline-block and text-align center the #menu, to get rid of the spaces between each list item - https://jsfiddle.net/shwL0wr1/
#menu {
text-align: center;
}
ul {
display: inline-block;
}