<ul> <li> centered, not moving down.. unsure why / how to fix - html

The <nav> should be aligned to the left, below the logo and slogan. However, despite attempting to do so with both margin and padding it remains above the logo and centered on the page. Any help with how to rectify this is greatly appreciated.
HTML
<header>
<div id="logo">
<img src="img/logo.png" alt="GEC logo" />
</div>
<div id="slogan">
<h1>Revolutionizing Potential</h1>
</div>
<nav>
<ul>
<li>Home</li>
<li>About Us</li>
<li>Coaching Services</li>
<li>Resources</li>
<li>Events</li>
<li>Contact Us</li>
</ul>
</nav>
</header>
CSS
/* Header */
header {
margin-top: 95px;
}
#logo {
float: left;
}
#slogan {
float: right;
margin-top: 90px;
}
nav ul li {
display: inline;
float: left;
}
nav ul li a {
padding-right: 20px;
}
nav ul li:last-child {
padding-right: 0;
}

To your CSS add:
nav {
clear:both;
}
jsFiddle example

First off what I always do is to give all elements default widths and hights.
The nav is an inline element and not a block.
to refrain from using clear fixes you should put a div element around the logo and the slogan.
like this:
HTML
<header>
<div id="header_top">
<div id="logo">
<img src="img/logo.png" alt="GEC logo" />
</div>
<div id="slogan">
<h1>Revolutionizing Potential</h1>
</div>
</div>
<nav>
<ul>
<li>Home</li>
<li>About Us</li>
<li>Coaching Services</li>
<li>Resources</li>
<li>Events</li>
<li>Contact Us</li>
</ul>
</nav>
</header>
Now you can just give the header_top div a display block and a overlfow:hidden.
That will give make the header_top div grow with its content.
Now giv you nav a display:block style and it is done
I tested it local on my notebook and it worked like a charm :)
add:
CSS
#header_top{
display: block;
overflow: hidden;
}
nav{
display: block;
}

Related

How should I properly implement a .png logo as part of a center-justified navigation bar?

I am using Apple's navigation toolbar as my design aesthetic/goal as everything is center justified and the logo included as part of that justification.
Here's how I have it setup currently...
<body>
<header>
<div class="logo"><img src="Images/Logo.png" alt="DIVINITAL"width="35" height="35"></div>
<nav>
<ul class="menu">
<li>Home</li>
<li>Shop</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
<li>User</li>
</ul>
</nav>
<div class="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i></div>
</header>
</body>
This, however, proves difficult for me to properly edit the logo alongside the ul items on the navbar. For some reason when I begin to style them accordingly, both widths have to be set to 100% for the alignment to workout but that obviously isn't allowed as they just move to two separate lines (the logo and the ul items on the nav bar...
So is there a better way to handle this? Thank you!
Welcome to StackOverflow.
You can easily do it using flex. There's a good tutorial that explains how to use flex..
Look at the following example, and see for yourself how flex can easily achieve what you're looking for:
header {
background-color: rgba(0,0,0,0.8);
display: flex;
justify-content: center;
align-items: center;
height: 44px;
}
.logo > img {
width: 35px;
height: 35px;
margin: auto 20px;
}
nav {
flex: 1
}
nav > ul {
color: white;
display: flex;
padding: 0;
list-style: none;
justify-content: space-between;
margin: auto 20px;
}
nav > ul > li {
}
nav a {
color: inherit
}
<header>
<div class="logo">
<img src="https://cdn4.iconfinder.com/data/icons/black-icon-social-media/512/099310-feedburner-logo.png" alt="DIVINITAL">
</div>
<nav>
<ul class="menu">
<li>Home</li>
<li>Shop</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
<li>User</li>
</ul>
</nav>
<div class="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i></div>
</header>
The most important rules I used here were (flex rules):
display: flex
justify-content
align-items

Trying to make a footer with buttons floated to the left and right

I would like this code to resemble the bottom of Google's homepage. It is still listing vertically, even with "inline". I want each three "lists" to be next to each other horizontally on the left and right side of the screen.
#HTML
<footer>
<div class="footer">
<ul style="width:10%; float:left;list-style-type:none;">
<li>Advertising</li>
<li>Business</li>
<li>About</li>
</ul>
<ul style="width:10%; float:right;list-style-type:none;">
<li>Privacy</li>
<li>Terms</li>
<li>Settings</li>
</ul>
</div>
</footer>
#CSS
.footer li{
display:inline;
}
You should remove the width on your uls. See this codepen. Floating elements will take the width of all their children. By wrapping them in an element that take 10% of the width, they don't have enough space to stay on the same row.
You could use display: flex; on the .footer DIV, with settings as below
.footer ul {
list-style-type: none;
padding: 0;
}
.footer li {
display: inline-block;
}
.footer {
display: flex;
justify-content: space-between;
}
<footer>
<div class="footer">
<ul>
<li>Advertising</li>
<li>Business</li>
<li>About</li>
</ul>
<ul>
<li>Privacy</li>
<li>Terms</li>
<li>Settings</li>
</ul>
</div>
</footer>

centering nav text within a grid

I am trying to equally place my 8 nav links across my nav bar.
Here is my nav HTML:
<nav>
<ul class="nav">
<li>Home</li>
<li>Destinations</li>
<li>Culture</li>
<li>Attractions</li>
<li>History</li>
<li>Media</li>
<li>Contact</li>
<li>Links</li>
</ul>
</nav>
I am using a basic grid and am trying to place each of the 8 links equally into 1/8 of the nav.
My css for the grid :
.col-1-8 {
width:12.5% }
I am applying this class to each of the 8 li, but can't seem to get them all centered equally.
If someone could help me out here, i'd be very happy!
thanks
Tim
This code does exactly what you want to obtain, I think that you didn't apply box-sizing border-box or text-align center.
http://codepen.io/anon/pen/WQVQGr
HTML:
<nav>
<ul>
<li>Home</li>
<li>Destinations</li>
<li>Culture</li>
<li>Attractions</li>
<li>History</li>
<li>Media</li>
<li>Contact</li>
<li>Links</li>
</ul>
</nav>
CSS:
*{
box-sizing: border-box;
}
nav ul {
background-color:yellow;
overflow:auto;
list-style:none;
padding: 0;
margin: 0;
width: 800px;
}
nav ul>li {
float:left;
width: 12.5%;
text-align: center
}
You can use flex for this.
.nav {
display: flex;
justify-content: space-around;
/* justify-content: space-between; */
background: yellow;
margin: 0;
padding: 0;
list-style: none;
}
<nav>
<ul class="nav">
<li>Home</li>
<li>Destinations</li>
<li>Culture</li>
<li>Attractions</li>
<li>History</li>
<li>Media</li>
<li>Contact</li>
<li>Links</li>
</ul>
</nav>

Trying to center an unordered list

On my website, I want a horizontal menu, which is centered on the page. So, the whole menu should be centred.
At this moment, I can create a horizontal list, but the list still stays at the left side. I want it centered.
Can someone please tell me what to change in my code to center it?
My HTML:
<div class=menu>
<ul>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
My CSS:
ul {
text-align: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
div.menu{
display: table;
}
div.menu a {
display: block;
margin-left: auto;
margin-right: auto;
width: 60px;
color: navy;
background-color: #FF0000
}
li{
float: left;
}
Add margin:auto to your div.menu to accomplish this
div.menu{
display: table;
margin:auto;
}
JSFiddle: http://jsfiddle.net/0xb7j9zc/
Check out this fiddle http://jsfiddle.net/ByShine/33sz6nrt/4/
HTML
<div class="menu">
<ul>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
CSS
ul {
text-align: center;
}
ul li {
display: inline-block;
}
I'm assuming you wish to center the menu (align it to the middle of the page). One approach, and I'm sure there's a few out there, is to wrap the 'menu' div into another div tag and set the align attribute to center, like so:
<div align="center">
<div class=menu>
<ul>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
Here's an example: http://jsfiddle.net/q9ae01qe/

Vertical center menu in navigation bar

I'm struggling with this problem for over an hour and can't get it right, I know these are basics but none solution from google helped, I don't understand what's the problem. I got that navigation bar and I want to vertically center logo and list elements inside it:
<nav id="mainMenu">
<img class="logo" src="images/logo.png" alt="logo" />
<ul id="menu">
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
css:
http://klaunfizia.pl/damian/style.css
Here's the demo: http://klaunfizia.pl/damian/
#edit:
When I put margin-top:50% for #menu why it refers to entire body instead of nav element?
Notice - the class name are different. From your existing style, remove: #mainmenu, #menu, and #menu li. Here is an example the code -> DEMO
Here is your new html:
<ul class="nav"> <img class="logo" src="images/logo.png" alt="logo" />
<li>Home
</li>
<li>About me
</li>
<li>Portfolio
</li>
<li>Contact
</li>
Here is your new CSS:
.nav {
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
background-color:red;
}
.nav li {
display:inline;
}
.nav a {
display:inline-block;
padding:10px;
text-decoration: none;
color: #000000;
}
Since your "nav" element is fixed try wrapping your "ul" element in a div and setting the css of the margin to the distance you desire.
<div style="margin-top:20px">
<ul id="menu">
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
The vertical spacing of block elements can be a bit tricky as they were never intened to behave that way. So some tricks are always required.
You can center them to the middle by making the list and the logo's position relative, than giving them a 50% top and a negative margin with the half of their height. So just add these properties to the existing ones:
.logo {
position: relative;
top: 50%;
margin-top: -25px;
}
#menu {
position: relative;
top: 50%;
margin-top: -10px;
}
use this:
#mainMenu {
height: 80px;
width: 100%;
background-color: #F00;
position: fixed;
line-height: 80px; /* added */
}
#menu {
float: right;
margin-right: 16%;
display: inline-block; /* added */
}