For my website I am designing a navigation bar and the goal is to position each element at the same height. This is the code I have so far:
body {
display:block;
margin:8px;
}
li, a {
font-family: "Open Sans", sans-serif;
font-size:14px;
text-decoration:none;
font-weight:600px;
color:black;
}
header {
display:flex;
justify-content:space-between;
align-items:center;
padding:10px 10%;
}
.Nav_links {
list-style: none;
}
.Nav_links li {
display: inline-block;
padding: 0px 20px;
}
.Nav_links li, a:hover {
transition: 400ms;
color:grey;
}
#Login_nav {
display:flex;
justify-content: space-around;
}
<header>
<img class="logo" src="images/logo_image.svg" alt="logo">
<nav>
<ul class="Nav_links">
<li><a href="#">Features <i class="fa-solid fa-angle-down"></i></a</li>
<li>Pricing</li>
<li>Contact Us</li>
</ul>
</nav>
<div id="Login_nav">
Login
<button id="Demobutton">Get demo</button>
</div>
</header>
I assume I did something wrong with the styling of the elements in CSS, because whenever I remove the CSS formatting of my id "#Login_nav" the login and get demo button do stand next to each other in the correct fashion, but still located too closely to each other.
Add a { gap: 1rem } and { align-items: center } on Login_nav, and I think you will get what you want, like so:
body {
display:block;
margin:8px;
}
li, a {
font-family: "Open Sans", sans-serif;
font-size:14px;
text-decoration:none;
font-weight:600px;
color:black;
}
header {
display:flex;
justify-content:space-between;
align-items:center;
padding:10px 10%;
}
.Nav_links {
list-style: none;
}
.Nav_links li {
display: inline-block;
padding: 0px 20px;
}
.Nav_links li, a:hover {
transition: 400ms;
color:grey;
}
#Login_nav {
display:flex;
align-items:center;
gap:1rem;
}
<header>
<img class="logo" src="images/logo_image.svg" alt="logo">
<nav>
<ul class="Nav_links">
<li><a href="#">Features <i class="fa-solid fa-angle-down"></i></a</li>
<li>Pricing</li>
<li>Contact Us</li>
</ul>
</nav>
<div id="Login_nav">
Login
<button id="Demobutton">Get demo</button>
</div>
</header>
Related
I am new to the front-end designing world and for my webpage I want to import an SVG file to display my company logo. I used Figma in order to export my design as an SVG file, however it doesn't appear to be showing up on my live server.
I used Codepen to display my SVG, and Codepen does display my SVG. But whenever I start up the Live Server, all I see is my alternative logo text and a logo pictogram. I tried renaming my SVG file to make sure the src location is right, but nothing seems to work.
#import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght#600;626&display=swap');
body {
display:block;
margin:8px;
}
li, a {
font-family: "Open Sans", sans-serif;
font-size:14px;
text-decoration:none;
font-weight:600px;
color:black;
}
header {
display:flex;
justify-content:space-between;
align-items:center;
padding:10px 10%;
}
.Nav_links {
list-style: none;
}
.Nav_links li {
display: inline-block;
padding: 0px 20px;
}
.Nav_links li, a:hover {
transition: 400ms;
color:grey;
}
#Login_nav {
display:flex;
align-items:center;
gap:1rem;
}
.switchIconRotate {
transform-origin: center;
transition: 0.2s;
}
.fa-angle-down {
color:#6161F2
}
.iconUp .fa-solid {
transform-origin: center;
transform: rotate(180deg);
}
#Demobutton {
cursor:pointer;
background-color: #4EC843;
border-radius:34px;
border:none;
color: white;
width:130px;
height:35px;
font-family:"Open Sans", sans-serif;
font-weight:600px;
font-size:14px;
}
#Demobutton:hover {
background-color: #20D62C;
transition:800ms;
}
#Navbarline {
width:80%;
border-width:1.5px;
opacity:15%;
}
<body>
<header>
<img class="logo" src="/logo.svg" alt="logo">
<nav>
<ul class="Nav_links">
<li><a class="switch" href="#">Features <i class="fa-solid fa-angle-down switchIconRotate"></i></a></li>
<li>Pricing</li>
<li>Contact Us</li>
</ul>
</nav>
<div id="Login_nav">
Login
<button id="Demobutton">Get demo</button>
</div>
</header>
<hr id="Navbarline"></hr>
<script src="/script.js"></script>
</body>
Whenever I hover mouse on that ul the background color must be changed for both list item <i> and <a> tags.
CSS
.mainlist {
list-style: none;
margin-top: 50px;
margin-left: 15px;
}
.submenu {
list-style: none;
display: list-item;
margin: 0px;
padding: 0px;
width: 15px;
}
.submenu li {
margin-top: 10px;
float: left;
display: inline;
margin: 5px;
text-align: center;
}
.submenu li i {
font-size: 25px;
color: white;
}
.submenu li a {
margin-top: 20px;
font-size: 20px;
color: white;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
HTML
<div style="float:left;margin-left:-250px;width:200px;background-color:dimgray;">
<nav id="sidenav">
<ul class="mainlist">
<ul class="submenu">
<li><i class="fa fa-home"></i></li>
<li>Home</li>
</ul>
</ul>
</nav>
</div>
How can I do that? I want something like this:
To change children's appearance on hover do something like this:
.submenu:hover li {
background:red;
}
UPDATE:
Added a snippet to show the effect you want.
.mainlist {
list-style: none;
display:block;
background:#35414f;
position:relative;
width:200px;
padding:50px;
margin:0;
}
.mainlist li {
display: block;
text-align: center;
color: #808b97;
width:100%;
padding:10px 0;
cursor:pointer;
border-bottom:1px solid #3a4654;
}
.mainlist li:hover {
background:#1eae9a;
color:white;
}
.mainlist li:hover .submenu li a {
color:white;
}
.submenu {
list-style: none;
display: list-item;
margin: 0;
padding: 0;
}
.submenu li {
display:block;
color: #808b97;
margin: 10px 0 0;
padding:0;
border:none;
}
.submenu li i {
display:inline-block;
font-size: 25px;
color:inherit;
}
.submenu li a {
color: inherit;
text-decoration:none;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<div>
<nav id="sidenav">
<ul class="mainlist">
<li>Lorem Ipsum</li>
<li>
Lorem Ipsum
<ul class="submenu">
<li><i class="fa fa-home"></i> Home</li>
<li><i class="fa fa-home"></i> Home</li>
</ul>
</li>
</ul>
</nav>
</div>
NOTE: Make sure to always wrap your submenu list into another li tag.
<ul class="mainmenu">
<li>
<ul class="submenu"></ul>
</li>
</ul>
UPDATE 2: CSS change + added Icon font
Use css :hover selector
.submenu:hover li{
background-color: black /* or any color you want */;
}
Also, is not correct to place a ul element as a child of another ul element
Check this:
correct semantics for ul in ul
You will have to use the pseudo class :hover, like this
.submenu:hover li{
background-color:green;
}
And for the text to change color too
.submenu:hover li > a{
color:black;
}
Here is jsfiddle
Consider this markup:
<nav>
<div id="logo"><img src="logo.png" height="44PX"/></div>
<ul id="navItems">
<li>Link1</li>
<li>Link2</li>
</ul>
</nav>
I used this css code for styling:
#navItems
{
display:flex;
z-index:1;
position:fixed;
top:0;
background-color:#333;
width:92%;
height:44px;
list-style-type:none;
}
How to place the logo on the left, just next to the navbar?
If you're using display:flex, can't you just use display:inline-flex?
#logo {
display: inline-flex;
}
#navItems
{
display:inline-flex;
z-index:1;
position:fixed;
top:0;
background-color:#333;
width:92%;
height:44px;
list-style-type:none;
}
<nav>
<div id="logo"><img src="logo.png" height="44PX"/></div>
<ul id="navItems">
<li>Link1</li>
<li>Link2</li>
</ul>
</nav>
I made you the simplest possible navbar
DEMO
html,
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
ul img {
height: 50px;
float: left;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
li a:hover {
background-color: #111;
}
<nav>
<ul>
<img src="http://doc.jsfiddle.net/_downloads/jsfiddle-logo.png" alt="">
<li>Link1
</li>
<li>Link2
</li>
</ul>
</nav>
I'm trying to make a simple responsive navigation but i can't seem to eliminate the spaces inbetween the links. Any help would greatly be appreciated.
This is my code:
css:
.nav{
width:100%; text-align:centre; margin:0 auto;max-width:1010px;
}
.nav ul{
line-height:50px;
}
.nav li{
display:inline; list-style-type: none;border-right:#333333 1px solid;
}
.nav li:hover{
}
.nav a{
text-decoration:none; padding:10px; color:#000; font-family: sans-serif;
}
.nav a:hover{
color:#c00;background:#999999;
}
html:
<div class="nav"><!-- nav -->
<span class="menu-button"></span>
<ul class="clearfix menu">
<li>Home</li>
<li>About Us</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div><!--/nav-->
With CodeRomeos answer, most of the spacing/padding was removed but there was still some spacing between the links. From your request to eliminate the spacing between the links then the below solution will completely remove spacing (although it would look better IMO with at least some padding between links).
.nav {
width: 100%;
text-align: centre;
margin: 0;
max-width: 1010px;
}
.nav ul {
line-height: 16px;
}
.nav li {
display: inline;
list-style-type: none;
border-right: #333333 1px solid;
margin: 0;
padding: 0;
float: left;
}
.nav a {
text-decoration: none;
color: #000;
font-family: sans-serif;
font-size: 16px;
margin: 0;
padding: 0;
}
.nav a:hover {
color: #c00;
background: #999999;
}
<div class="nav">
<span class="menu-button"></span>
<ul class="clearfix menu">
<li>
Home
</li>
<li>
About Us
</li>
<li>
Portfolio
</li>
<li>
Contact
</li>
</ul>
</div>
I just switched your css a bit from display: inline to float: left for the li tags. Hope it helps, though float may not be the best approach here.
.nav li {
display: inline;
}
to
.nav li {
float: left;
}
http://codepen.io/anon/pen/OyVLOK
As in your css there is padding defined 10px.
.nav a{
text-decoration:none; padding:10px 5px; color:#000; font-family: sans-serif;
}
set it to
.nav a{text-decoration:none; padding:10px 2px; color:#000; font-family: sans-serif;}
Hope this help you.!
I used this video https://www.youtube.com/watch?v=QPO9HJjUktk to create a CSS dropdown menu with submenus.
I got everything to look right and I have tried linking the list items in the submenus to other .html files and actual websites, but nothing works. When I click on the submenu item to go to whatever page, nothing loads and it just stays on the current page with the submenu open.
HTML:
'<nav class="nav-main">
<div class="logo">Kudler Fine Foods</div>
<ul>
<li> Departments
<div class="nav-content">
<div class="nav-sub">
<ul>
<li>Bakery</li>
<li>Meat & Seafood</li>
<li>Produce</li>
<li>Cheese & Dairy</li>
<li>Wine</li>
</ul>
</div>
</div>
</li>
</ul>
<ul>
<li> Information
<div class="nav-content">
<div class="nav-sub">
<ul>
<li>News</li>
<li>About</li>
<li>Locations</li>
</ul>
</div>
</div>
</li>
</ul>
<ul>
<li> Other
<div class="nav-content">
<div class="nav-sub">
<ul>
<li>Surveys</li>
<li>Terms & Conditions</li>
</ul>
</div>
</div>
</li>
</ul>
</nav>'
CSS:
#charset "utf-8";
/* CSS Document */
body, html {
margin: 0;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
}
.content {
padding:30px;
}
.nav-main {
width:100%;
background-color:#FF6700;
height:70px;
color:#fff;
}
.nav-main .logo {
float:left;
height:40px;
padding:15px 30px;
font-size:1.4em;
line-height:40px;
}
.nav-main > ul {
margin:0;
padding:0;
float:left;
list-style-type:none;
}
.nav-main > ul > li {
float:left;
}
.nav-item {
display: inline-block;
padding: 15px 20px;
height: 40px;
line-height:40px
color: #fff;
text-decoration: none;
color: #FFFFFF;
}
.nav-tem:hover {
background-color:#444;
}
.nav-content {
position:absolute;
top:70px;
overflow:hidden;
background-color:#222;
color:#fff;
max-height:0;
}
.nav-content a {
color:#fff;
text-decoration:none;
}
.nav-content a:hover {
text-decoration:underline;
}
.nav-sub {
padding:20px;
}
.nav-sub ul {
padding:0;
margin:0;
list-style-type:none;
}
.nav-sub ul li a {
display:inline-block;
padding:5px 0;
}
.nav-item:focus {
background-color:#444;
}
.nav-item:focus ~ .nav-content {
max-height:400px;
-webkit-transition:max-height 400ms ease-in;
-moz-transition:max-height 400ms ease-in;
transition:max-height 400ms ease-in;
}