I have a site header created with floating divs using this structure:
nav {
height:inherit;
width:100%;
margin:0 auto;
position:relative;
z-index:10;
text-align: center;
}
#nav-wrap {
min-width: 100%;
width: auto !important;
width:100%;
white-space:nowrap;
}
nav ul#nav-left, #nav-right {
list-style-type:none;
display:inline-block;
margin:0;
padding:0;
width:auto;
height:100%;
}
nav img {
display:inline-block;
padding:0;
margin:0;
max-height:225px;
vertical-align:top;
}
nav ul li {
display:inline-block;
text-align:center;
font-family: 'Oswald',helvetica,arial,sans-serif;
font-size:1.8rem;
font-weight:400;
padding:0 30px;
margin-top:30px;
}
<nav>
<div id="nav-wrap">
<ul id="nav-left">
<li>Option1</li>
<li>Option2</li>
<li>Option3</li>
</ul>
<img src="assets/img/img.png" />
<ul id="nav-right">
<li>Option4</li>
<li>Option5</li>
<li>Option6
</li>
</ul>
</nav>
Updated
I've been playing with layout and the floats were making things tough. So, it's all displayed as inline-block without floats, but the center logo still isn't resizing and I can't figure out what I'm doing wrong. Take a look at the staged site linked below to see what I'm going for. The logo overlap is intentional.
Staged site
I appreciate any help or suggestions. I'd like to avoid using display:table if possible.
#media queries is the thing you needed.
#media (max-width: 700px) {
nav ul li {
font-size:1.3rem;
padding:0 10px;
}
}
#media (max-width: 1200px) {
nav ul li {
font-size:1.5rem;
padding:0 20px;
}
}
#media (min-width: 1201px) {
nav ul li {
font-size:1.8rem;
padding:0 30px;
}
}
#media (max-width: 400px) {
nav ul li {
/*For this you need to use mobile friendly menu **/
}
}
Related
I'm trying to center align my menu that goes onto 2 lines.
I'm using ul li. not sure if this is the best option. I've trued everything from posts posted on SO, but nothing doing :(
I would like it to go onto 2 lines and still be centered
Here is s screen shot of what it looks like:
CSS:
#media only screen and (min-width: 300px) and (max-width: 480px) {
.header-links-mobile {
display:inline-block;
width:80%;
position:absolute;
top:60px;
left:0%;
text-align:center;
}
.header-links-mobile ul {
width:90%;
margin:auto;
padding:0;
display: flex;
justify-content: center;
}
.header-links-mobile ul li {
color:#fff;
padding:5px 5px 0 5px;
display: inline;
text-align: center;
}
.header-links-mobile ul li a {
color:#fff;
}
.header-links-mobile ul li a:hover {
color:#fff;
}
}
HTML
<div class="header-links-mobile">
<ul>
<li>
Admin Panel
</li>
<li>
asheenk#cyphernet.co.za
</li>
<li>
Log out
</li>
<li class="ico-account-wrapper">
My account
</li>
<li>
<a href="/mass-supply-live/cart" class="ico-cart" id="topcartlink">
<span class="cart-label">Shopping cart</span>
<span class="cart-qty">(54 ITEM)</span>
</a>
</li>
</ul>
</div>
Please add the following style
.header-links-mobile, .header-links-mobile ul {
width :100%;
}
.header-links-mobile ul {
flex-wrap: wrap;
}
Check this fiddle
So I've been desperately trying out every method I can find online for centering my nav bar links.
However whatever I do, they seem to either line horizontally (like I want) but to the left of the page (not what I want), or they line vertically (not what I want) but to the center of the page (what I want).
It seems no matter what margin, float, display settings I use in the CSS it never renders the navbar links in a horizontal line, in the center of the page.
My code is:
HTML:
<body>
<div class="maincontent">
<div class="navbar">
<div>
<h1>Tom Love</h1>
<ul>
<li> Home </li>
<li> About </li>
<li> Portfolio </li>
<li> Contact </li>
</ul>
</div>
</div>
</div>
</body>
CSS:
h1 {font-family:'Roboto Slab',sans-serif;
font-size:250%;
font-weight:300;
color:black;
text-align:center;
line-height:32px;
}
h1 span {font-size:60%;
font-family:'Roboto Slab',sans-serif;
}
.navbar {
clear:both;
margin:0 auto;
overflow:hidden;
padding:0;
text-align:center;
width:100%;
}
.navbar div {
float:center;
position:relative;
}
.navbar ul {
list-style-type: none;
text-align:center;
padding:10px;
margin:auto;
}
.navbar ul li {
padding:10px;
float:center;
}
.navbar ul li a {
text-decoration:none;
color:black;
margin:10px;
display:inline;
width:80px;
height:30px;
}
.navbar ul li a:hover {
text-decoration:none;
color:white;
background:black;
}
Apologies for any glaring mistakes in the code, it's my first attempt at building something outside of codeacademy and YouTube tuts.
Thanks in advance :)
Just add
display: inline;
to your .navbar ul li
Remove float:center (it does not exist)
Add display: inline or display: inline-block to .navbar ul li
If you want everything centered then place margin: 0 auto; on .maincontent and give it a width.
The differences between display values are listed here on the MDN.
It could be worth considering a CSS Reset or Normalise. (Do some research on the two options)
Have an example!
CSS
.maincontent {
margin: 0 auto;
width: 800px;
}
h1 {font-family:'Roboto Slab',sans-serif;
font-size:250%;
font-weight:300;
color:black;
text-align:center;
line-height:32px;
}
.navbar ul {
list-style-type: none;
text-align:center;
padding:10px;
}
.navbar ul li {
padding:10px;
display: inline;
}
.navbar ul li a {
text-decoration:none;
color:black;
margin:10px;
}
.navbar ul li a:hover {
text-decoration:none;
color:white;
background:black;
}
My issue is that the first element in my nav bar which is "home" has more spacing than the rest of the elements. I can't seem for the life of me to figure out what it is. All I wanted was to have a centered evenly spaced out navigation bar but it's seeming harder than I thought.
CSS
.container {
width: 1060px;
background: #FFF;
padding: 50px;
margin: 0 auto;
}
#top_nav {
position:fixed;
background:#343642;
font-family: Impact, Charcoal, sans-serif;
}
#top_nav ul {
list-style:none;
width:100%;
margin:0 auto;
padding:0;
text-align:center;
overflow:hidden;
}
#top_nav ul li {
margin:0 56px 0 0;
padding: 0;
font-size:1.7em;
text-transform:uppercase;
display: inline-block;
font-weight:bold;
}
#top_nav ul li a {
color:#fef6e9;
text-decoration:none;
display: block;
}
#top_nav ul li a:hover {
color:#ed7163;
text-decoration:none;
}
.content { padding: 10px 0;}
.content-outer { width:100%; overflow:visible; }
.content-outer .content-inner { width:100%; margin:0 auto; overflow:visible; position:relative; }
HTML
<div class="content-outer" id="top_nav">
<ul>
<li>Home<li>
<li>Digital</li>
<li>Film</li>
<li>Timeline</li>
<li>Contact</li>
</ul>
</div>
</div>
That is because you are not properly closing the first li in your list.
<li>Home<li>
should be
<li>Home</li>
Consider running your code through a mark up validator like W3C mark up validator when you are having formatting problems. Many times its something small like a mismatched tag or not properly closing a tag such as in this case.
I have an 8 item menu, to get it evenly spaced across IE, Chrome Firefox and when viewed using an ipad I've had to use extraneous padding within the stylesheet which works but is so messy. Not helping is the fact each menu item is a different width.
Having spent several hours on google I've achieved absolutely nothing. If possible looking for a much cleaner solution, HTML and CSS below
<nav>
<ul>
<li>Home</li>
<li>Shop</li>
<li>Convertible Roofs</li>
<li>Contact Us</li>
<li>Gallery</li>
<li>Customer Comments</li>
<li class="active">Buyers Guide</li>
<li>Leather Care</li>
</ul>
</nav>
nav ul {
margin:0;
padding:0;
background:rgba(0,0,0,.2);
}
nav ul li {
display:inline-block;
border-right:1px solid rgba(255,255,255,.2);
margin-right:-3px;
}
nav ul li:last-child {
border-right:none;
}
nav ul li a {
display:inline-block;
padding:14px 21.3px;
text-align:center;
text-decoration:none;
text-transform:uppercase;
font-size:0.938em;
outline:0;
color:#fff;
}
#media screen and (-webkit-min-device-pixel-ratio:0) {
nav ul li a {
padding:14px 20.7px;
}
}
#media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
nav ul li a {
padding:14px 21.3px;
}
}
#-moz-document url-prefix() {
nav ul li a {
padding:14px 20.7px;
}
}
nav ul li a:hover,nav li.active a {
color:#fff;
background:rgba(0,0,0,.4);
}
See if you can follow this as is; if not, I'll do you a fiddle ...
The basic premise is to make the elements behave like table cells so you don't need the padding. I did a quick edit in Firebug - see if it works for you:
nav {
display: table;
height: 50px;
width: 100%;
}
nav ul {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0.2);
display: table-row;
margin: 0;
padding: 0;
width: 100%;
}
nav ul li {
border-right: 1px solid rgba(255, 255, 255, 0.2);
display: table-cell;
line-height: 50px;
}
nav ul li a {
color: #fff;
display: block;
font-size: 0.938em;
outline: 0 none;
padding: 0;
text-align: center;
text-decoration: none;
text-transform: uppercase;
}
You can remove the rule that adds the padding (line 170).
Disclaimer: Not tested in anything other than Firefox.
Did a bit more digging and found this answer by #Rob Lowe on this page how to make a ul li css menu with variable space between items, very close to your method #Jayx so thanks again.
nav {
width:960px;
display:table;
background:rgba(0,0,0,.2);
border-collapse:collapse;
margin:0;
padding:0;
}
nav ul {
display:table-row-group;
list-style:none;
margin:0;
padding:0;
}
nav li {
display:table-cell;
border-right:1px solid rgba(255,255,255,.2);
vertical-align:middle;
}
nav li a {
display:block;
padding:12px 15px;
text-align:center;
text-decoration:none;
text-transform:uppercase;
font-size:0.938em;
outline:0;
color:#fff;
}
I've done designing for desktop screen but it doesn't work for mobile phone. I'm wondering whats the problem. Here is my coding.
HTML
<div id="nav">
<span id="nav-icon"> <img src="assets/images/icon/navigation.png" alt="nav-menu"> </span>
<ul>
<li> LINK </li>
<li> LINK </li>
<li> LINK </li>
<li> LINK </li>
<li> LINK </li>
</ul>
<div class="navimage">
<img src="facebook-icon.png" alt="facebook-icon" />
<img src="twitter-icon.png" alt="twitter-icon" />
</div>
</div>
style.css
#nav {
border-bottom:1px solid #FFF;
margin-bottom:20px;
padding:0;
text-align:center;
max-width:95%;
margin:0 auto;
}
#nav #nav-icon img {
display:none;
}
#nav li {
display:inline;
}
#nav a {
display:inline-block;
padding:15px;
font-family: 'alegreya_sansregular', sans-serif;
font-weight:bold;
font-size:15px;
margin:15px 0;
}
#nav a:hover {
color:#DEB887;
text-decoration:none;
}
.navimage img {
width:30px;
height:30px;
border-radius:50%;
-webkit-border-radius:50%;
-moz-border-radius:50%;
-ms-border-radius:50%;
-o-border-radius:50%;
}
.imgnav img {
margin-left:-25px;
}
.navimage {
float:right;
margin-top:-80px;
}
responsive.css
#media only screen and (min-width: 480px) and (max-width: 767px) {
#nav {text-align:left;}
#nav-icon img {display:inline-block;height:40px;}
#nav ul, #nav:active ul {display:none;position:absolute;padding: 20px;background:#fff;border: 3px solid #DEB887;left:35px;top:70px;width:20%;border-radius:0 0 3px 3px;z-index:9999;}
#nav:hover ul {display:block;}
.navimage {margin-top:-300px;}
#nav li {text-align:center;display:block;}
#nav ul li a {color:#000;padding:0;}
}
The problem is
1. The image (navigation menu) is not showing at all.
2. Facebook and twitter logo cannot be seen.
3. I hover my mouse somewhere within a site but navigation bar randomly showed up (There wasn't any picture of navigation menu)
Here is the JSFIDDLE..
All for mobile screen (min-width: 480px and max-width: 767px). Any ideas?