Why are my flex items wrapping off the screen? - html

I have a flex nav and it's wrapping to the left and partially off of the screen. Does anyone with more experience know what could be causing this? I can't figure out why it's doing this.
header {
background-color: rgba(255, 165, 0, .8);
border-bottom: 12px solid black;
display: flex;
flex-flow: row wrap;
align-content: center;
}
header h1 {
text-align: center;
margin: 0;
padding: 15px;
text-shadow: 5px 5px 5px rgba(0, 0, 0, .3);
border: 8px solid black;
}
header h1,
nav a {
font-weight: 700;
font-family: arial;
}
header nav {
display: none;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
text-align: center;
margin: 1px;
border: 1px solid white;
border-radius: 15px;
}
a {
text-decoration: none;
}
a:visited,
a,
h1 {
color: white;
}
#media screen and (min-width: 400px) {
header {
height: 120px;
display: flex;
justify-content: space-between;
}
header h1 {
margin: 0 0 0 8%;
font-size: 2em;
align-self: flex-start;
white-space: nowrap;
}
header nav {
display: block;
align-self: flex-end;
}
nav ul {
display: flex;
justify-content: flex-end;
margin: 0 8% 0 0;
}
nav ul li {
border-radius: 8px;
padding: 5px;
margin: 4px 1%;
font-size: 1.5rem;
}
.characters:hover {
position: relative;
border-radius: 8px 8px 0 0;
}
.drop-menu {
position: absolute;
display: none;
top: 38px;
white-space: nowrap;
left: 0;
background-color: rgba(255, 165, 0, .8);
border: 1px solid rgba(0, 0, 0, .02);
box-shadow: 5px 5px 5px 2px rgba(0, 0, 0, .3);
}
.characters:hover .drop-menu {
display: block;
}
.drop-menu li {
margin: 0;
border-radius: 0;
}
footer nav {
display: none;
}
}
<header>
<h1>Seraph Chronicles</h1>
<nav>
<ul class="main-nav">
<li class="main-nav-item">Home</li>
<li class="main-nav-item">About</li>
<li class="main-nav-item characters">
Characters
<ul class="drop-menu">
<li>Ethan Clarke</li>
<li>Serena Kiriaga</li>
<li>Marcus Flynn</li>
<li>Emily Ashdown</li>
<li>Director Miles West</li>
</ul>
</li>
<li class="main-nav-item">Author</li>
</ul>
</nav>
</header>
https://jsfiddle.net/ca75sqzc/17/

Short Answer
Don't use percentages on flex item margins. Use another unit, such as px or em.
revised demo
Explanation
When you make the primary container (.header) a flex container, its children become flex items.
These are the two children: h1 and nav (red borders added below)
Each nav item (li) has a horizontal margin (1% on each side).
nav ul li{
border-radius: 8px;
padding: 5px;
margin: 4px 1%;
font-size: 1.5rem;
}
This causes them to overflow the container.
Then, because the container has justify-content: flex-end, the items are aligned to the container's right edge. This means the overflow occurs on the left side (see image above).
On smaller screens, the nav element wraps to the left edge of the header, and the overflowing items go out of view:
If you switch to justify-content: flex-start, the items overflow on the right side.
But the real problem is actually this:
Why isn't the ul container expanding to accommodate the li children?
The answer appears to be the use of percentages for the horizontal margins.
nav ul {
display: flex;
justify-content: flex-end;
margin: 0 8% 0 0;
}
nav ul li {
border-radius: 8px;
padding: 5px;
margin: 4px 1%;
font-size: 1.5rem;
}
The container is not recognizing this unit on the margins and, therefore, not expanding.
Note that the flexbox spec recommends against using percentage margins and padding on flex items.
4.2. Flex Item Margins and
Paddings
Authors should avoid using percentages in paddings or margins on flex
items entirely, as they will get different behavior in different browsers.
Once you switch to non-percentage units on your margins, everything seems to work.

Change the following in your CSS:
nav ul{
display: flex;
/* justify-content: flex-end; */
margin: 0 8% 0 0;
}

Just erase justify-content: flex-end; from the rule for nav ul in the media query section:
header {
background-color: rgba(255, 165, 0, .8);
border-bottom: 12px solid black;
display: flex;
flex-flow: row wrap;
align-content: center;
}
header h1 {
text-align: center;
margin: 0;
padding: 15px;
text-shadow: 5px 5px 5px rgba(0, 0, 0, .3);
border: 8px solid black;
}
header h1,
nav a {
font-weight: 700;
font-family: arial;
}
header nav {
display: none;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
text-align: center;
margin: 1px;
border: 1px solid white;
border-radius: 15px;
}
a {
text-decoration: none;
}
a:visited,
a,
h1 {
color: white;
}
#media screen and (min-width: 400px) {
header {
height: 120px;
display: flex;
justify-content: space-between;
}
header h1 {
margin: 0 0 0 8%;
font-size: 2em;
align-self: flex-start;
white-space: nowrap;
}
header nav {
display: block;
align-self: flex-end;
}
nav ul {
display: flex;
margin: 0 8% 0 0;
}
nav ul li {
border-radius: 8px;
padding: 5px;
margin: 4px 1%;
font-size: 1.5rem;
}
.characters:hover {
position: relative;
border-radius: 8px 8px 0 0;
}
.drop-menu {
position: absolute;
display: none;
top: 38px;
white-space: nowrap;
left: 0;
background-color: rgba(255, 165, 0, .8);
border: 1px solid rgba(0, 0, 0, .02);
box-shadow: 5px 5px 5px 2px rgba(0, 0, 0, .3);
}
.characters:hover .drop-menu {
display: block;
}
.drop-menu li {
margin: 0;
border-radius: 0;
}
footer nav {
display: none;
}
}
<header>
<h1>Seraph Chronicles</h1>
<nav>
<ul class="main-nav">
<li class="main-nav-item">Home</li>
<li class="main-nav-item">About</li>
<li class="main-nav-item characters">
Characters
<ul class="drop-menu">
<li>Ethan Clarke</li>
<li>Serena Kiriaga</li>
<li>Marcus Flynn</li>
<li>Emily Ashdown</li>
<li>Director Miles West</li>
</ul>
</li>
<li class="main-nav-item">Author</li>
</ul>
</nav>
</header>
https://jsfiddle.net/7dubc44L/

Related

How to center menu within the page instead of having it on the left

I have use this tool to generate the menu: https://www.cssportal.com/css3-menu-generator/
It works great except that the menu is horizontally align to the left of the page.
I have tried to wrap the content in div and use text align. I have tried to use left and margin-left
But the last menu item goes to the next row.
What I want to achieve is having the whole menu sitting in the middle of the page (horizontally).
link text
#menu-bar {
width: 95%;
margin: 0px 0px 0px 0px;
padding: 6px 6px 4px 6px;
height: 40px;
line-height: 100%;
background: #FFFFFF;
border: solid 0px #FFFFFF;
position: relative;
z-index: 999;
}
#menu-bar li {
margin: 0px 0px 8px 0px;
padding: 0px 20px 0px 4px;
float: left;
position: relative;
list-style: none;
}
#menu-bar a {
font-weight: normal;
font-family: arial;
font-style: normal;
font-size: 17px;
color: #000000;
text-decoration: none;
display: block;
padding: 6px 20px 6px 20px;
margin: 0;
margin-bottom: 8px;
}
#menu-bar .active a,
#menu-bar li:hover>a {
background: #FFFFFF;
color: #FA550F;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
#menu-bar:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#menu-bar {
display: inline-block;
}
html[xmlns] #menu-bar {
display: block;
}
* html #menu-bar {
height: 1%;
}
<ul id="menu-bar">
<li class="active">Home</li>
<li>Products</li>
<li>Services</li>
<li>About</li>
</ul>
I edited the CSS to achieve the result.
#menu-bar {
/* display: inline-block;*/
display: block;
text-align: center;
}
I changed the #menu-bar display property to display: block; and to make link inside it at the center used text-align: center;. But it will not enough to make the link center so I made the following edit.
#menu-bar li {
margin: 0px 0px 8px 0px;
padding: 0px 20px 0px 4px;
/**float: left;**/
position: relative;
list-style: none;
display: inline-block;
}
float:left actually forcing the link items to left so I omitted it and make it an inline element with display: inline-block;.
#menu-bar {
width: 95%;
margin: 0px 0px 0px 0px;
padding: 6px 6px 4px 6px;
height: 40px;
line-height: 100%;
background: #FFFFFF;
border: solid 0px #FFFFFF;
position: relative;
z-index: 999;
}
#menu-bar li {
margin: 0px 0px 8px 0px;
padding: 0px 20px 0px 4px;
/**float: left;**/
position: relative;
list-style: none;
display: inline-block;
}
#menu-bar a {
font-weight: normal;
font-family: arial;
font-style: normal;
font-size: 17px;
color: #000000;
text-decoration: none;
display: block;
padding: 6px 20px 6px 20px;
margin: 0;
margin-bottom: 8px;
}
#menu-bar .active a,
#menu-bar li:hover>a {
background: #FFFFFF;
color: #FA550F;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
#menu-bar:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#menu-bar {
/*display: inline-block;*/
display: block;
text-align: center;
}
html[xmlns] #menu-bar {
display: block;
}
* html #menu-bar {
height: 1%;
}
<ul id="menu-bar">
<li class="active">Home</li>
<li>Products</li>
<li>Services</li>
<li>About</li>
</ul>
You should add text-align: center; to #menu-bar, remove float: left; from #menu-bar li and add display: inline-block;
The correct code:
#menu-bar {
width: 95%;
margin: 0px 0px 0px 0px;
padding: 6px 6px 4px 6px;
height: 40px;
line-height: 100%;
background: #FFFFFF;
border: solid 0px #FFFFFF;
position: relative;
z-index: 999;
text-align: center;
}
#menu-bar li {
margin: 0px 0px 8px 0px;
padding: 0px 20px 0px 4px;
position: relative;
list-style: none;
display: inline-block;
}
Apply on menu-bar CSS :
margin: 0 auto;
Or :
left: 50%;
Also, add on menu-bar li CSS :
display: inline-block;
Try using diplay: flex to get alignment done easily. This is a sample code
HTML
<div class="flex">
<ul id="menu-bar">
<li class="active">Home</li>
<li>Products</li>
<li>Services</li>
<li>About</li>
</ul>
</div>
CSS
#menu-bar {
height: 40px;
line-height: 100%;
background: #FFFFFF;
border: solid 0px #FFFFFF;
position: relative;
z-index: 999;
}
#menu-bar li {
margin: 0px 0px 8px 0px;
padding: 0px 20px 0px 4px;
float: left;
position: relative;
list-style: none;
}
#menu-bar a {
font-weight: normal;
font-family: arial;
font-style: normal;
font-size: 17px;
color: #000000;
text-decoration: none;
display: block;
padding: 6px 20px 6px 20px;
margin: 0;
margin-bottom: 8px;
}
#menu-bar .active a, #menu-bar li:hover > a {
background: #FFFFFF;
color: #FA550F;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
#menu-bar:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#menu-bar {
display: inline-block;
}
html[xmlns] #menu-bar {
display: block;
}
* html #menu-bar {
height: 1%;
}
.flex {
display: flex;
flex-direction: row;
justify-content: center;
}
JS Fiddle Link: https://jsfiddle.net/SJ_KIllshot/6z483d7n/
As option add text-align property to container:
#menu-bar {
width: 95%;
margin: 0px 0px 0px 0px;
padding: 6px 6px 4px 6px;
height: 40px;
line-height: 100%;
background: #FFFFFF;
border: solid 0px #FFFFFF;
position: relative;
z-index: 999;
text-align: center;
}
and change styles of
#menu-bar li {
margin: 0px 0px 8px 0px;
padding: 0px 20px 0px 4px;
list-style: none;
display: inline-block;
}
just edit #menu-bar style :
#menu-bar {
display: flex;
justify-content: center;
align-items: center
}
screenshot :
You can center inline elements horizontally, within a block-level parent element, with just:
.center-children {
text-align: center;
}
You can center a block-level element by giving it margin-left and margin-right of auto (and it has a set width, otherwise it would be full width and wouldn't need centering). That's often done with shorthand like this:
.center-me {
margin: 0 auto;
}
I recommend to all this article https://css-tricks.com/centering-css-complete-guide/

My Footer is not aligned and it needs fixing so that it is in the center

As seen in this screenshot: https://i.imgur.com/7fh65T6.png
my footer is not aligned to the center and it is really bugging me.
I'll send a screen to how I kinda want it to look. The screenshot -> https://i.imgur.com/5tf1SYN.png
ul {
margin: 0;
padding: 0;
list-style: none;
}
h2,
h3,
a {
color: #34495e;
}
a {
text-decoration: none;
}
.logo {
margin: 0;
font-size: 1.45em;
}
.main-nav {
margin-top: 5px;
}
.logo a,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
.footer {
position: -1%;
padding-top: .5em;
padding-bottom: .5em;
border: 1px solid #a2a2a2;
background-color: #f4f4f4;
-webkit-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
/* =================================
Media Queries
==================================== */
#media (min-width: 769px) {
.footer,
.main-nav {
display: flex;
}
.footer {
flex-direction: column;
align-items: center;
.footer {
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
#media (min-width: 1025px) {
.footer {
flex-direction: row;
justify-content: space-between;
}
}
<footer class="footer">
<ul style="font-size: 10px; text-align: center; margin-left: auto; margin-right: auto; padding-left: 10px; padding-right: 10px;">
<li>Cadet Resources</li>
<li>Apply</li>
<li>Cadet Login</li>
</ul>
<ul style="font-size: 10px; text-align: center; padding-left: 10px; padding-right: 10px;">
<li>Contact Us</li>
<li>Apply</li>
<li>Cadet Login</li>
</ul>
<h1 class="logo" style="float: right;"><a style="font-size: 10px; float: right; margin-right: 25px;"> Air Cadets 2019</a></h1>
</footer>
I have cleaned up your code a little bit, to make the layout clear.
<footer class="footer">
<ul class="column-one">
<li>Cadet Resources</li>
<li>Apply</li>
<li>Cadet Login</li>
</ul>
<ul class="column-two">
<li>Contact Us</li>
<li>Apply</li>
<li>Cadet Login</li>
</ul>
<h1 class="logo"> Air Cadets 2019</h1>
</footer>
Please note that I have removed inline all inline styles, as it is considered a bad practice, mainly because of maintenance. You can read more on this here: What's so bad about in-line CSS?
footer > ul.column-one {
margin-right: 10px;
}
footer > ul.column-two {
margin-left: 10px;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
footer {
position: -1%;
padding-top: 0.5em;
padding-bottom: 0.5em;
border: 1px solid #a2a2a2;
background-color: #f4f4f4;
-webkit-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
/* =================================
Media Queries
==================================== */
#media (min-width: 769px) {
footer {
display: flex;
position: relative;
justify-content: center;
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
footer > h1 {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
margin: 0;
font-size: 1.45em;
}
}
#media (min-width: 1025px) {
}
As you can see you can set margins between the inner columns by applying a left and a right margin to each item individually.
Your picture made clear that you want to position the columns in the center of the footer, regardless of the logo.
That's why I have taken out the logo from the flow by making it an absolute element. This way the element can be positioned without disturbing the positions of the centered columns.
Also you cant mix flex and floats:
3. Flex Containers: the flex and inline-flex display values
A flex container establishes a new flex formatting context for its
contents. This is the same as establishing a block formatting context,
except that flex layout is used instead of block layout.
For example, floats do not intrude into the flex container, and the
flex container’s margins do not collapse with the margins of its
contents.
float and clear do not create floating or clearance of flex item, and
do not take it out-of-flow.
You can find a working example of your code here:
https://codepen.io/anon/pen/dLJqey
Is this what you are looking for?
ul {
margin: 0;
padding: 0;
list-style: none;
}
h2,
h3,
a {
color: #34495e;
}
a {
text-decoration: none;
}
.logo {
margin: 0;
font-size: 1.45em;
}
.main-nav {
margin-top: 5px;
}
.logo a,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
.footer {
position: -1%;
padding-top: .5em;
padding-bottom: .5em;
border: 1px solid #a2a2a2;
background-color: #f4f4f4;
-webkit-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
display: flex;
justify-content: center;
}
/* =================================
Media Queries
==================================== */
#media (min-width: 769px) {
.footer,
.main-nav {
display: flex;
}
.footer {
flex-direction: column;
align-items: center;
.footer {
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
#media (min-width: 1025px) {
.footer {
flex-direction: row;
justify-content: space-between;
}
}
<footer class="footer">
<ul style="font-size: 10px; text-align: center; margin-left: auto; margin-right: auto; padding-left: 10px; padding-right: 10px;">
<li>Cadet Resources</li>
<li>Apply</li>
<li>Cadet Login</li>
</ul>
<ul style="font-size: 10px; text-align: center; padding-left: 10px; padding-right: 10px;">
<li>Contact Us</li>
<li>Apply</li>
<li>Cadet Login</li>
</ul>
<h1 class="logo" style="float: right;"><a style="font-size: 10px; float: right; margin-right: 25px;"> Air Cadets 2019</a></h1>
</footer>

Centering a navigation bar CSS

I have a nav bar at the top of each page on my site. Here are the HTML and CSS:
HTML
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Shifts</li>
<li>Part Five</li>
<li>Background</li>
</ul>
CSS
ul {
z-index: 100;
position: fixed;
list-style-type: none;
width: 80em;
height: 3em;
margin-left: auto;
margin-right: auto;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding-top: 1em;
padding-bottom: 1em;
width: 20em;
margin-right: auto;
margin-left: auto;
text-decoration: none;
overflow: hidden;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #87372c;
box-shadow: 0px 0px 50px #87372c;
color: #000000;
font-weight: 800;
text-shadow: 0 0 10px gold, 0 0 20px gold, 0 0 30px gold, 0 0 40px gold;
}
I've also set up a CodePen here: https://codepen.io/njpbray/pen/Rerabv
The bar isn't centered at all and it has an extra hanging portion to the left that doesn't react to hovering.
I'm not sure what's going on here. I thought that making something of width 80em and settings left and right margins to auto would make it rest center. I also thought an 80em width bar with 4 subdivision of 20em would be equally divided, but there's that bit on the left.
I would prefer to keep the bar fixed at the top though if possible. Some pages are long, and I want the user to be able to access the nav bar anywhere on the page.
To centralise the links, remove the float: left from li and set it to display: inline-block. Then simply set text-align: center on the <ul>.
The above is enough to centralise the blocks, but your content is still offset to the right of the page. To correct this, significantly shrink your width values. em is based on the font size, which is a good policy for text, but a poor choice for width. You can use percentages for responsiveness, or alternatively go with a fixed px unit depending on how 'indented' you want the links to be. I've gone with 100px for the links in my example.
And as you're making use of a <ul> element, you'll also want to remove the default padding, by setting padding: 0 on ul. This removes the left 'offset' you're seeing.
Finally, don't forget to set margin: 0 on body to get rid of that 8px of whitespace around the edges.
This can all be seen in the following:
body {
margin: 0;
}
ul {
z-index: 100;
position: fixed;
list-style-type: none;
width: 100%;
height: 3em;
margin-left: auto;
margin-right: auto;
background-color: #333;
text-align: center;
padding: 0;
}
li {
display: inline-block;
}
li a {
display: block;
color: white;
text-align: center;
padding-top: 1em;
padding-bottom: 1em;
width: 100px;
margin-right: auto;
margin-left: auto;
text-decoration: none;
overflow: hidden;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #87372c;
box-shadow: 0px 0px 50px #87372c;
color: #000000;
font-weight: 800;
text-shadow: 0 0 10px gold, 0 0 20px gold, 0 0 30px gold, 0 0 40px gold;
}
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Shifts</li>
<li>Part Five</li>
<li>Background</li>
</ul>
You have the position set to fixed in your code. What you want is to set it to center.
ul {
z-index: 100;
position: center;
list-style-type: none;
width: 80em;
height: 3em;
margin-left: auto;
margin-right: auto;
background-color: #333;
}
https://codepen.io/anon/pen/dgGMva
I think you might be interested in going through the CSS tutorials at w3shcools. You will benefit immensely from this:
https://www.w3schools.com/Css/
The better way to handle what you want to achieve is to wrap you top bar in an element which take the entire width 100% of the browser with it position property set to fixed and add the list as a sub element.
And the space at the left of the first link it's due to the fact that by default the body tag have some margin and padding. You must remove it. the ul element have also same space padding and margin
html, body {
margin: 0;
padding: 0;
}
header {
width: 100%;
position: fixed;
background-color: blue;
}
ul {
z-index: 100;
list-style-type: none;
width: 80em;
height: 3em;
margin: 0 auto;
padding: 0;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding-top: 1em;
padding-bottom: 1em;
width: 20em;
margin-right: auto;
margin-left: auto;
text-decoration: none;
overflow: hidden;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #87372c;
box-shadow: 0px 0px 50px #87372c;
color: #000000;
font-weight: 800;
text-shadow: 0 0 10px gold, 0 0 20px gold, 0 0 30px gold, 0 0 40px gold;
}
<header>
<ul>
<li><a class="" href="index.html">Home</a></li>
<li>Shifts</li>
<li>Part Five</li>
<li>Background</li>
</ul>
</header>
It's better with css3 and display:flex instead of float:left and inline-block
<header>
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Shifts</li>
<li>Part Five</li>
<li>Background</li>
</ul>
</header>
<main>
</main>
body {
margin: 0;
padding: 0;
}
header {
display: flex;
justify-content: center;
}
ul {
background-color: #333;
display: flex;
list-style-image: none;
list-style-type: none;
margin: 0;
padding: 0;
position: fixed;
z-index: 100;
}
li a {
align-items: center;
color: white;
display: flex;
justify-content: center;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
width: 20em;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #87372c;
box-shadow: 0px 0px 50px #87372c;
color: #000000;
font-weight: 800;
text-shadow: 0 0 10px gold, 0 0 20px gold, 0 0 30px gold, 0 0 40px gold;
}
main {
height: 1500px;
}
https://codepen.io/anon/pen/qJbZMv
As mentioned before: CSS3 and flex-box is supported by almost all relevant web-browsers. Use that instead. Here is a link for learning.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Creating a responsive nav bar on lower width dimension without javascript

I've been trying to create a nav bar thats responsive for basic sizes, but I'm not entirely sure how to have the nav links change into a menu button which can be expanded to show the nav options.
I current have the options just stack and be centered under 769px, but what I am looking for is more along the lines of this nav bar.
This is what I currently have:
header {
background-color: #666;
padding: 30px;
text-align: center;
font-size: 35px;
color: white;
}
body {
font-family: 'Montserrat', sans-serif;
line-height: 1.6;
margin: 0;
min-height: 100vh;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
h2,
h3,
a {
color: #34495e;
}
a {
text-decoration: none;
}
.active {
background-color: #d3d3d3;
border-radius: 40px;
}
.logo {
margin: 0;
font-size: 1.45em;
}
.main-nav {
margin-top: 5px;
}
.logo,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
.header {
padding-top: .5em;
padding-bottom: .5em;
border: 1px solid #a2a2a2;
background-color: #f4f4f4;
-webkit-box-shadow: 0px 0px 14px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 14px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 14px 0px rgba(0,0,0,0.75);
-webkit-border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-bottom-left-radius: 5px;
-moz-border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#media (min-width: 769px) {
.header,
.main-nav {
display: flex;
}
.header {
flex-direction: column;
align-items: center;
.header{
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
#media (min-width: 1025px) {
.header {
flex-direction: row;
justify-content: space-between;
}
}
<nav class="header">
<h2 class="logo">Logo</h2>
<ul class="main-nav">
<li><a class="active">Home</a></li>
<li>Destinations</li>
<li>Experiences</li>
<li>Travel Guides</li>
<li>About</li>
<li>References</li>
</ul>
</nav>

How to set navigation links to same height as logo?

I'm working on a nav menu, seen below.
/*
Variables
*/
body {
font: 100% "Lato", sans-serif;
margin: 0;
}
#container {
width: 100%;
margin-top: 47px;
}
/*
Navigation menu
*/
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
position: fixed;
top: 0;
width: 100%;
/*box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);*/
border-bottom: solid 3px #21ce99;
z-index: 1;
}
nav ul li {
float: left;
}
nav ul li a {
display: block;
color: #21ce99;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
nav ul li a:hover {
background-color: #F2F2F2;
}
/*
Layout
*/
section {
position: relative;
float: left;
width: 60%;
background-color: white;
}
aside {
position: relative;
float: right;
width: 40%;
clear: right;
}
footer {
clear: both;
background-color: #21ce99;
height: 500px;
}
/*
Styling
*/
h1 {
color: rgba(0, 0, 0, 0.87);
font: 300% "Lato", sans-serif;
padding: 30px;
}
p {
color: rgba(0, 0, 0, 0.54);
font-size: 1.3em;
margin: 20px;
}
a#logo {
font: 300% 'Wire One', sans-serif;
}
img {
width: 100%;
max-width: 600px;
margin: 10px;
}
table, th, td {
border: solid .13em #16a085;
border-radius: .3em;
font-size: 15px;
padding: 10px;
border-collapse: collapse;
}
/*
Widgets
*/
.btn {
padding: 1em 1em;
display: inline-block;
border-radius: .38em;
border: .12em solid #21ce99;
text-decoration: none;
color: #21ce99;
margin: 20px;
}
.btn:hover {
background-color: #21ce99;
color: white;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<link href='https://fonts.googleapis.com/css?family=Wire+One|Lato:100,100italic,300,300italic,400italic,400,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<title>methusela</title>
</head>
<body>
<nav>
<ul>
<li><a id="logo" href="index.html">methusela</a></li>
<li>Discover</li>
<li>Buy</li>
<li>Yes</li>
<li>Contact</li>
</ul>
</nav>
<div id="container">
<section>
<h1></h1>
<a href="#" class="btn">
Learn more
</a>
</section>
<aside>
<img src="" />
</aside>
<footer>
</footer>
</div>
</body>
</html>
All the links were originally vertically in the middle of the nav box, but after I added a logo that uses different size text. All the menu links are no longer in the middle.
Is there a way to have the dimensions of menu links automatically fill the entire box to align with the largest item? Or is there a way to just vertically center the links within the box?
Thank you so much for any help.
Display your ul as flex and use align-items: center and justify-content: center properties to put them on the center of your box, both vertically and horizontally respectively.
nav ul {
display: flex;
align-items: center;
justify-content: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
position: fixed;
top: 0;
width: 100%;
/*box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);*/
border-bottom: solid 3px #21ce99;
z-index: 1;
}
JSFiddle.
When you use align-items: center you center your elements vertically inside your flex container.
When you use justify-content: center you center your elements horizontally inside your flex container.