I want my nav bar to have the navigation buttons on the left & my signup/login to the right. I've managed to have a main nav bar, and a separated navbar for the login/signup, but that messes with my code.
I've tried to do something with the ':last-child' but it doesn't seem to work...
.nav-wrapper ul {
float: left;
padding-left: 50px;
}
.nav-wrapper ul li {
display: inline-block;
}
.nav-wrapper ul li:not(:first-child) {
margin-left: 36px;
}
.nav-wrapper ul li:last-child {
margin-right: 18px;
float: right;
}
.nav-wrapper ul li a {
display: inline-block;
outline: none;
color: #333333;
text-transform: uppercase;
text-decoration: none;
font-size: 14px;
letter-spacing: 1.24px;
font-family: 'Montserrat', sans-serif;
font-weight: 800;
font-style: normal;
}
<nav class="nav-bar">
<input type="checkbox" id="nav" class="hidden">
<label for="nav" class="nav-btn">
<i></i>
<i></i>
<i></i>
</label>
<div class="logo">
"logo"
</div>
<div class="nav-wrapper">
<ul class="list">
<li>Home</li>
<li>Collections</li>
<li>Contact</li>
<li>Log In</li>
<li>Sign Up</li>
</ul>
</div>
</nav>
in my opinion you can have a header element (the topbar), with two nav inside, each with its own alignment
<header class="topbar">
<div class="logo">
My logo
</div>
<nav class="navigation">
<ul>
<li>Home</li>
<li>Collections</li>
<li>Contact</li>
</ul>
</nav>
<nav class="user">
<ul>
<li>Log In</li>
<li>Sign Up</li>
</ul>
</nav>
</header>
and then
header.topbar {
position: relative;
display: block;
float: left;
width: 100%;
}
.logo {
position: relative;
display: block;
float: left;
}
nav.navigation {
position: relative;
display: block;
float: left;
}
nav.user {
position: relative;
display: block;
float: right;
}
nav ul {
position: relative;
display: block;
float: left;
list-style: none;
}
nav ul li {
position: relative;
display: block;
float: left;
margin: 0px 12px;
}
You can use flexbox on your ul element and move its last child element to the right by applying margin-left: auto to it (no floats needed in this case):
.nav-wrapper ul {
display: flex;
padding-left: 50px;
list-style: none;
}
.nav-wrapper ul li:not(:first-child) {
margin-left: 36px;
}
.nav-wrapper ul li:last-child {
margin-right: 18px;
margin-left: auto;
}
.nav-wrapper ul li a {
display: inline-block;
outline: none;
color: #333333;
text-transform: uppercase;
text-decoration: none;
font-size: 14px;
letter-spacing: 1.24px;
font-family: 'Montserrat', sans-serif;
font-weight: 800;
font-style: normal;
}
<nav class="nav-bar">
<input type="checkbox" id="nav" class="hidden">
<label for="nav" class="nav-btn">
<i></i>
<i></i>
<i></i>
</label>
<div class="logo">
"logo"
</div>
<div class="nav-wrapper">
<ul class="list">
<li>Home</li>
<li>Collections</li>
<li>Contact</li>
<li>Log In</li>
<li>Sign Up</li>'
</ul>
</div>
</nav>
Regarding your code, it will work if you remove float: left; from .nav-wrapper ul.
In my opinion, it is more intuitive to use CSS grid, and divide your ul into two logical units (main ul for the left side, and secondary ul for the right side):
.nav-wrapper {
display: grid;
grid-template-columns: 1fr max-content;
}
.nav-wrapper ul.list {
display: flex;
list-style-type: none;
padding: 0;
}
.nav-wrapper ul li:not(:first-child) {
margin-left: 36px;
}
.nav-wrapper ul li a {
display: inline-block;
outline: none;
color: #333333;
text-transform: uppercase;
text-decoration: none;
font-size: 14px;
letter-spacing: 1.24px;
font-family: 'Montserrat', sans-serif;
font-weight: 800;
font-style: normal;
}
<div class="nav-wrapper">
<ul class="list list-main">
<li>Home</li>
<li>Collections</li>
<li>Contact</li>
</ul>
<ul class="list list-secondary">
<li>Log In</li>
<li>Sign Up</li>
</ul>
</div>
Related
Hi, if you look at the above screenshot you can see I have added in code to make a small bar transition across when hovering over items in the navigation bar.
However, this bar also appears when I hover over items in the drop down menu. For example, when hovering over "Stock 1" the bar appears and obviously looks awful.
How can I make it so that this bar only appears on the items in the main menu and NOT in the drop down menu's.
Please see HTML code below:
<header>
<div class="container-fluid">
<div class="logo">
<img src="images/japan_flag.gif" alt="" height="31" width="41">
</div>
<div class="container">
<nav role="navigation">
<ul class="mainmenu">
<li>Home</li>
<li>About Us</li>
<li>Stock
<ul class="dropdown">
<li>Stock 1</li>
<li>Stock 2</li>
</ul>
</li>
<li>Enquiries</li>
<li>Contacts</li>
</ul>
</nav>
</div>
<div id="mobile-menu-wrap"></div>
</div>
</header>
Please see CSS below:
nav a {
text-decoration: none;
text-transform: uppercase;
font-family: "Oswald", sans-serif;
}
nav {
font-family: monospace;
}
nav ul {
list-style: none;
margin: 0;
margin-top: 30px;
padding-left: 45%;
}
nav ul li {
color: #fff;
display: block;
float: left;
padding: 1rem;
position: relative;
text-decoration: none;
transition-duration: 0.5s;
}
nav ul li a {
color: #fff;
}
nav ul li a:hover {
cursor: pointer;
color: rgb(199, 50, 13);
transition-duration: 0.3s;
}
nav ul li ul {
visibility: hidden;
background: rgb(199, 50, 13);
opacity: 0;
min-width: 100%;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
display: block;
min-width: 100%;
white-space: nowrap;
z-index: 100;
padding: 9% 9%;
text-align: left;
line-height: 10px;
padding-top: 8px;
}
nav ul li:hover > ul,
nav ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
nav ul li ul li a:hover {
color: black;
}
nav ul li ul li {
clear: both;
width: 100%;
}
nav ul li a::after {
content: '';
display: block;
height: 5px;
background-color: rgb(199, 50, 13);
position: relative;
bottom: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav ul li a:hover::after {
width:100%;
}
Any help with this would be hugely appreciated as I have tried for ages to research and figure this out. I am very new to HTML, CSS and any sort of coding in general so apologies.
You can give class to <a> on which you want to apply style..
You can do like this.
<header>
<div class="container-fluid">
<div class="logo">
<img src="images/japan_flag.gif" alt="" height="31" width="41">
</div>
<div class="container">
<nav role="navigation">
<ul class="mainmenu">
<li><a class="abc" href="#">Home</a></li>
<li><a class="abc" href="#">About Us</a></li>
<li><a class="abc" href="#">Stock</a>
<ul class="dropdown">
<li>Stock 1</li>
<li>Stock 2</li>
</ul>
</li>
<li>Enquiries</li>
<li>Contacts</li>
</ul>
</nav>
</div>
<div id="mobile-menu-wrap"></div>
</div>
And in css file you can do like this:
.abc:hover{
cursor: pointer;
color: rgb(199, 50, 13);
transition-duration: 0.3s;
}
I have a unordered list in my HTML with 5 lists that all had with links on them that were working fine. It was working fine until I added another unordered list, but i have no links inside it. I even gave it a separate class.
Here is my markup/CSS:
ul {
margin: 0;
list-style-type: none;
color: white;
diplay: block;
padding-top: 20px;
padding-left: 350px;
font-family: "Economica", sans-serif;
font-size: 28px;
text-decoration: none;
}
ul li {
padding-left: 45px;
padding-right:45px;
display: inline;
text-decoration: none;
}
ul li a:hover {
font-weight:bold;
color:grey;
}
a {
text-decoration: none;
color:white;
}
<div id="mainPage" >
<img src="http://xoio.de/al_by_xoio1.jpg" alt="concert stadium" style="width:100%; position:absolute; padding-top:70px; height:930px">
<div id="navBar">
<div id="Logo">
<h1 style="font-weight:bold;"> Ice Arena </h1>
</div>
<ul id="select">
<li>
<a style="color:#ffe700;" href="#">Home</a>
</li>
<li>
Gallery
</li>
<li>
Order Form
</li>
<li>
The Arena
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
I've only added the code regarding the list and area of my problem.
Add position: relative; to ul, otherwise other elements are above it and prevent the link behavior.
ul {
margin: 0;
list-style-type: none;
color: white;
diplay: block;
padding-top: 20px;
padding-left: 350px;
font-family: "Economica", sans-serif;
font-size: 28px;
text-decoration: none;
/* added */
position: relative;
}
ul li {
padding-left: 45px;
padding-right: 45px;
display: inline;
text-decoration: none;
}
ul li a:hover {
font-weight: bold;
color: grey;
}
a {
text-decoration: none;
color: white;
}
<div id="mainPage">
<img src="http://xoio.de/al_by_xoio1.jpg" alt="concert stadium" style="width:100%; position:absolute; padding-top:70px; height:930px">
<div id="navBar">
<div id="Logo">
<h1 style="font-weight:bold;">Ice Arena</h1>
</div>
<ul id="select">
<li><a style="color:#ffe700;" href="#">Home</a></li>
<li>Gallery</li>
<li>Order Form</li>
<li>The Arena</li>
<li>Contact Us</li>
</ul>
</div>
</div>
Try deleting the CSS property (position:absolute;) in line 3.
I'm having trouble vertically aligning the links and the logo inside the list any idea what i can to fix it?
Here is the code in codepen.
http://codepen.io/tacoxlegendary/pen/VjXqkA?editors=1100
<body>
<nav>
<div class="wrapper ">
<ul class="cf">
<li id="logo">LOGO</li>
<li>SIGN IN</li>
<li>LOCTION</li>
<li>TEAM</li>
<li>ABOUT</li>
</ul>
</div> <!-- wrapper end -->
</nav>
.wrapper {
max-width: 1120px;
margin: 0 auto;
}
nav {
background-color: #F7FDFE;
}
nav ul li {
display: inline-block;
color: #45494D;
float: right;
padding: 10px;
font-size: 14px;
}
nav ul #logo {
float: left;
font-size: 30px;
}
Add padding:0 to nav ul #logo
.wrapper {
max-width: 1120px;
margin: 0 auto;
}
nav {
background-color: #F7FDFE;
}
nav ul li {
display: inline-block;
color: #45494D;
float: right;
padding: 10px;
font-size: 14px;
}
nav ul #logo {
float: left;
font-size: 30px;
padding:0;
}
<nav>
<div class="wrapper ">
<ul class="cf">
<li id="logo">LOGO</li>
<li>SIGN IN</li>
<li>LOCTION</li>
<li>TEAM</li>
<li>ABOUT</li>
</ul>
</div> <!-- wrapper end -->
</nav>
a simple way to center the navbar and logo in the center of navbar is to set a height to navbar and give the same value as line-height to li
like
nav {
height: 70px;
}
ul.cf {
line-height: 70px;
}
I am building a horizontal menu using unordered lists. 4 items are links and then there's an image in the center. Currently the links are centered on the middle of the image, but the I would rather the text vertically align lower than middle. The image is 140px tall and I would like the text to be at 50px. I've tried playing with vertical-align and line-height, but no joy. Padding doesn't work. I'm sure this is obvious and I'm just missing it. Any help would be appreciated.
Code:
.menu {
text-align: center;
}
.menu ul {
display: inline-table;
}
.menu ul li {
display: inline;
line-height: 0px;
}
.menu .link {
padding: 15px;
}
.menu a {
text-decoration: none;
font-size: 17px;
font-weight: 400;
color: #131313;
}
.menu a:hover {
color: #330000;
}
<div class="container">
<div class="row menu">
<ul>
<li class="link">MENU
</li>
<li class="link">ABOUT
</li>
<li class="link">
<a href="index.html">
<img class="center logo" src="https://placehold.it/140x140" />
</a>
</li>
<li class="link">BLOG
</li>
<li class="link">CONTACT
</li>
</ul>
</div>
</div>
Using bootstrap 3.3.6 as well.
You mean like this fiddle?
.menu { text-align:center; }
.menu ul { display:inline-table;}
.menu ul li {display:inline; line-height:0px;}
.menu .link {
padding: 15px;
}
img{
width: auto;
height: 140px;
vertical-align: -50px;
}
.menu a {
text-decoration: none;
font-size: 17px;
font-weight: 400;
color: #131313;
}
.menu a:hover {
color: #330000;
}
<div class="container">
<div class="row menu">
<ul>
<li class="link">MENU</li>
<li class="link">ABOUT</li>
<li class="link"><img class="center logo" src="https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300"/></li>
<li class="link">BLOG</li>
<li class="link">CONTACT</li>
</ul>
</div>
Give the text LI's a different class, and then apply vertical-align: 50px.
.menu {
text-align: center;
}
.menu ul {
display: inline-table;
}
.menu ul li {
display: inline;
line-height: 0px;
}
.menu .link {
padding: 15px;
}
.menu .link.align {
vertical-align: 50px;
}
.menu a {
text-decoration: none;
font-size: 17px;
font-weight: 400;
color: #131313;
}
.menu a:hover {
color: #330000;
}
<div class="container">
<div class="row menu">
<ul>
<li class="link align">MENU
</li>
<li class="link align">ABOUT
</li>
<li class="link">
<a href="index.html">
<img class="center logo" src="https://placehold.it/140x140" />
</a>
</li>
<li class="link align">BLOG
</li>
<li class="link align">CONTACT
</li>
</ul>
</div>
</div>
Not sure if you want the text to be vertical-align: top or vertical-align: middle but you can adjust it as you please with this codepen!
I made the li's inline-block which enables them to be adjusted by the vertical-align property and still be horizontal across your navigation.
I gave the background some color so that the stock image wouldn't blend in as much and you'd be able to see the alignment.
HTML:
<div class="container">
<div class="row menu">
<ul>
<li class="link">MENU</li>
<li class="link">ABOUT</li>
<li class="link"><img class="center logo" src="http://lorempixel.com/140/200/"/></li>
<li class="link">BLOG</li>
<li class="link">CONTACT</li>
</ul>
</div>
CSS:
body {
background: #BBB;
}
.menu {
text-align:center;
}
.menu ul {
display:inline-table;
}
.menu ul li {
display: inline-block;
vertical-align: middle;
}
.menu .link {
padding: 1em;
}
.menu a {
text-decoration: none;
font-size: 3.125em;
color: #131313;
}
.menu a:hover {
color: #330000;
}
I'm trying to create a basic drop down menu. I'm having issues with the alignment. How can I get sub menu items to be directly underneath one another? For example, I am trying to get twitter, instagram, and facebook underneath "Social".
Thanks.
https://jsfiddle.net/xalxnder/ostaqgyk/
HTML
<body>
<ul class="main-nav">
<li>Home</li>
<li>Projects</li>
<li class="dropdown">
Social
<ul class="sub">
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</li>
</ul>
</body>
CSS
body {
background: #000000;
color: white;
}
.main-nav {
float: left;
}
.main-nav li {
font-size: 10px;
display: inline;
padding-right: 10px;
}
.main-nav .sub {
color: pink;
float: none;
z-index: -200;
}
//** .sub{display: none;
}
.dropdown:hover > .sub {
display: block;
position: absolute;
}
Here's the basics of it.
JSFiddle
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: black;
}
ul {
list-style-type: none;
color: white;
}
.main-nav >li {
display: inline-block;
position: relative;
padding-right: 10px;
}
.sub {
position: absolute;
top: 100%;
left: 0;
color: pink;
/* display:none */ /* disabled for demo */
}
.dropdown:hover .sub {
display:block;
}
<ul class="main-nav">
<li>Home</li>
<li>Projects</li>
<li class="dropdown">
Social
<ul class="sub">
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</li>
</ul>
Since block-level elements take up their own line, this rule should hold you:
.sub li {
display: block;
}
Add to .main-nav .sub:
position: absolute;
padding: 0;
body {
background: #000000;
color: white;
}
.main-nav {
float: left;
}
.main-nav li {
font-size: 10px;
display: inline-block;
padding-right: 10px;
}
.main-nav .sub {
position: absolute;
padding: 0;
color: pink;
float: none;
z-index: -200;
}
.sub li {
display: block;
}
<body>
<ul class="main-nav">
<li>Home</li>
<li>Projects</li>
<li class="dropdown">
Social
<ul class="sub">
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</li>
</ul>
</body>