I am trying to build a nav bar. So here is the thing. What I want to do is to change both the color of menu icon and the word "menu" when hovering over their container.
I use background color to build this icon, so I cannot simply change background color to change the icon. Otherwise, the background of the whole container would be blue.
.nav-item{
display: inline-block;
vertical-align: middle;
height: 60px;
margin: 5px;
}
#primary-logo{
height: 50px;
}
.navbar{
border-top: 1px solid gray;
border-bottom: 1px solid gray;
}
.nav-list{
list-style-type: none;
padding-left: 0px;
display: flex;
align-items: center;
padding-bottom: 5px;
gap: 24px;
}
.menu-line{
width: 34px;
height:5px;
background-color: black;
margin: 6px 0px;
}
.menu-item{
display: inline-block;
vertical-align: middle;
}
.menu-sec:hover{
color: rgb(39, 42, 202);
cursor: pointer;
}
.menu-line:hover{
width: 34px;
height:5px;
background-color: rgb(39, 42, 202);
margin: 6px 0px;
}
<nav>
<div class="nav-item">
<img
id="primary-logo"
src="800px-The_Economist_Logo.svg.png"
alt="Economist Logo"
/>
</div>
<div class="navbar nav-item">
<ul class="nav-list">
<li class="menu-sec">
<div class="menu-item"> <!-- menu icon -->
<div class="menu-line"></div>
<div class="menu-line"></div>
<div class="menu-line"></div>
</div>
<div class="menu-item">Menu</div>
</li>
<li>Weekly edition</li>
<li>Search</li>
</ul>
</div>
</nav>
You can do it as below. I added this line .menu-sec:hover .menu-line {background-color: rgb(39, 42, 202)}. I also removed some duplicated lines.
.nav-item {
display: inline-block;
vertical-align: middle;
height: 60px;
margin: 5px;
}
#primary-logo {
height: 50px;
}
.navbar {
border-top: 1px solid gray;
border-bottom: 1px solid gray;
}
.nav-list {
list-style-type: none;
padding-left: 0px;
display: flex;
align-items: center;
padding-bottom: 5px;
gap: 24px;
}
.menu-line {
width: 34px;
height: 5px;
background-color: black;
margin: 6px 0px;
}
.menu-item {
display: inline-block;
vertical-align: middle;
}
.menu-sec:hover {
color: rgb(39, 42, 202);
cursor: pointer;
}
.menu-sec:hover .menu-line {
background-color: rgb(39, 42, 202);
}
<nav>
<div class="nav-item">
<img id="primary-logo" src="800px-The_Economist_Logo.svg.png" alt="Economist Logo" />
</div>
<div class="navbar nav-item">
<ul class="nav-list">
<li class="menu-sec">
<div class="menu-item">
<!-- menu icon -->
<div class="menu-line"></div>
<div class="menu-line"></div>
<div class="menu-line"></div>
</div>
<div class="menu-item">Menu</div>
</li>
<li>Weekly edition</li>
<li>Search</li>
</ul>
</div>
</nav>
Related
I have been trying to make the colour fill the entire dropdown relative to the text you are hovering but it is not filling the whole div element, only the space around the word.
I have created a Fiddle to show the issue that I am having. I'm a beginner in CSS and HTML.
As you can see I have tried to add padding but it is not filling the div element as you hover it.
THE HTML is provided below and also within the Fiddle
header {
display: flex;
justify-content: space-evenly;
align-items: center;
padding-top: 1.0rem;
}
.sub-1 {
display: none;
}
.sub-1 ul {
display: flex;
flex-direction: column;
gap: 2rem;
padding-right: 4rem;
padding-left: 1rem;
margin-left: -9.5rem;
height: 27.5rem;
font-size: 1.6rem;
background-color: white;
list-style: none;
}
.sneakers {
margin-top: 2rem;
}
.sub-1 a:link,
.sub-1 a:visited {
color: black;
text-decoration: none;
}
.sub-1 a:hover {
padding: 10px;
background-color: blue;
}
li:hover .sub-1 {
display: block;
position: absolute;
margin-left: -2rem;
box-shadow: 1px 1px 10px grey;
}
.search-txt {
border: none;
outline: none;
padding-top: 1.0rem;
padding-left: 1.0rem;
font-size: 1.5rem;
color: black;
}
.search-nav {
display: flex;
font-size: 1.6rem;
list-style: none;
gap: 2.0rem;
margin-left: -7.0rem;
margin-top: -0.5rem;
caret-color: transparent;
}
<header class="header">
<body>
<div class="navbar">
<ul class="search-nav">
<li><a class="main-nav-link" href="#browse">Browse</a>
<div class="sub-1">
<ul class="">
<li class="sneakers">Sneakers
</li>
<li>Apparel</li>
<li>Electronics</li>
<li>Trading Cards</li>
<li>Collectibles</li>
<li>Accessories</li>
<li>NFTs</li>
</ul>
</div>
</li>
<li><a class="main-nav-link" href="#news">News</a></li>
<li><a class="main-nav-link" href="#help">About</a>
</li>
<li><a class="main-nav-link" href="#account">My Account</a></li>
<li><a class="main-nav-link sell" href="#sell">Sell</a></li>
</ul>
</div>
</header>
Fiddle
if i understand correctly the wrapper div with the sub-1 class is unnecessary. If you remove that div and add that class to the ul below it
<li><a class="main-nav-link" href="#browse">Browse</a>
<ul class="sub-1">
<li class="sneakers">Sneakers
</li>
<li>Apparel</li>
<li>Electronics</li>
<li>Trading Cards</li>
<li>Collectibles</li>
<li>Accessories</li>
<li>NFTs</li>
</ul>
Then in your css add a background-color
li:hover > .sub-1{
display: block;
position: absolute;
margin-left: -2rem;
box-shadow: 1px 1px 10px grey;
background: red;
}
I hope this helps, cheers!
so I've tried a few different things out. But ultimately no success. I'm trying to change the colour of the "Home" link to stay a different colour than the rest when we are specifically on the homepage. So for example, say I'm on the homepage, I specifically want that colour to be orange for the home link, and then when I click on About link, about link changes to orange and the home goes to default white
Html:
<!--Header-->
<header class="header-main">
<!--Navigation menu-->
<nav class="navigation">
<!--Bakingwithwill Logo-->
<img class="logo" src="imgs/bww.png" alt="Bakingwithwill" />
<!--Navigation links-->
<div class="nav-links">
<!--Unordered list of navigation items-->
<ul class="nav-menu">
<li id="active-home" class="nav-items">Home</li>
<li class="nav-items">About</li>
<li class="nav-items">Order</li>
<li class="nav-items">Contact</li>
<li class="nav-items">Cart</li>
</ul>
</div>
<div class="footer-nav">
<!--Footer portion of the side navbar-->
<div class="nav-social">
<!--Navigation of Bakingwithwill social media accounts-->
<ul class="nav-social-list">
<li class="social-icons">
<i class="fab fa-facebook"></i>
</li>
<li class="social-icons">
<i class="fab fa-instagram"></i>
</li>
</ul>
</div>
<p class="copyright">Copyright Bakingwithwill</p>
<!--Copyright-->
</div>
</nav>
<img class="header-banner" src="imgs/bww-home-banner.jpg" alt="Bakingwithwill bread banner"/>
<!--Main image-->
<div class="main">
<!--Contents outside the side navbar representing header page-->
<h2 class="baking-heading">Bakingwithwill</h2>
<h1 class="welcome-heading">Welcome!</h1>
<h2 class="intro-heading">Get a slice of the best bread in<br>
Chatham-Kent!</h2>
</div>
</header>
CSS:
/*Base styles*/
body {
font-family: 'Oswald', sans-serif;
}
h1 {
font-family: 'Satisfy', cursive;
}
/*Home styles*/
header {
width: 100%;
height: 585px;
}
/*Side bar navigation menu*/
.navigation {
height: 100%;
width:160px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #3D3732;
overflow-x: hidden;
padding-top: 20px;
opacity: 90%;
}
.navigation a {
text-decoration: none;
}
.logo {
border-radius: 50%;
height: 70px;
width: 70px;
margin-top: 10px;
margin-left: 45px;
}
#active-home:link, #active-home:visited {
color:#E88F2A !important;
}
.navigation li, p {
text-decoration: none;
color: #FFFFFF;
display: block;
text-align: center;
}
.navigation .nav-items {
padding-right: 30px;
padding-top: 10px;
text-align: center;
}
.navigation .social-icons {
list-style-type: none;
text-align: center;
display: inline;
font-size: 15px;
padding: 5px;
margin-top: 50px;
color: #FFFFFF;
margin-left: 15px;
text-decoration: none;
}
.navigation li:hover {
color: #E88F2A;
}
.navigation p {
font-size: 10px;
text-align: center;
padding: 6px 8px 6px 16px;
}
.main {
margin-left: 160px;
padding: 0px 10px;
}
.footer-nav {
margin-top: 200px;
}
/*Social media icons*/
.navigation i {
text-decoration: none;
color: #FFFFFF;
}
.navigation i:hover {
color: #E88F2A;
}
/*Text overlaying the image*/
.baking-heading {
color: #E88F2A;
font-family: 'Satisfy', cursive;
position: relative;
margin-top: 40px;
padding-left: 50px;
font-size: 50px;
}
.welcome-heading, .intro-heading {
font-family: 'Oswald', sans-serif;
position: relative;
}
.welcome-heading, .baking-heading {
transform: rotate(-13deg);
}
.welcome-heading {
padding-left: 130px;
font-size: 50px;
color: #FFFFFF;
}
.intro-heading {
padding-top: 200px;
font-size: 50px;
text-align: center;
color: #FFFFFF;
}
.header-banner {
/*Image styles*/
margin-top: -40px;
position: absolute;
width: 100%;
height: 585px;
}
So for example, say I'm on the homepage, I specifically want that
colour to be orange for the home link, and then when I click on About
link, about link changes to orange and the home goes to default white
One CSS-only approach is to:
add a class to the <body> element of each page
add classes to each of your links (or to the list-items containing the links)
Home Page:
<body class="home-page">
<ul class="nav-menu">
<li class="nav-items home">Home</li>
<li class="nav-items about">About</li>
<li class="nav-items order">Order</li>
<li class="nav-items contact">Contact</li>
<li class="nav-items cart">Cart</li>
</ul>
About Page:
<body class="about-page">
<ul class="nav-menu">
<li class="nav-items home">Home</li>
<li class="nav-items about">About</li>
<li class="nav-items order">Order</li>
<li class="nav-items contact">Contact</li>
<li class="nav-items cart">Cart</li>
</ul>
Then you can change the color of the relevant link on each page:
.nav-items a {
color: white;
}
.home-page .nav-items.home a,
.about-page .nav-items.about a {
color: orange;
}
You need to add a class to the active link and #id is not recommended for styling. Also, the pseudo classes that you're using is blocking your desired outcome. Try changing :
#active-home:link,
#active-home:visited {
color: #e88f2a !important;
}
to:
.active {
color: #e88f2a !important;
}
Afterwards, place the .active class into your link code for each page. So for home it would be:
<li class="nav-items active">Home</li>
and for your about page:
<a href="#">
<li class="nav-items">Home</li>
</a>
<a href="about.html">
<li class="nav-items active">About</li>
</a>
and so on...
I am a fresh newcomer and I have been studying and practising flexbox and CSS, just now I was trying to move my float elements into flexbox, but for a reason, I don't know my menu is broken I see the drop-down menu items upper the hamburger button, I would be happy if someone could explain what I am doing bad, thank you in advance. Here is the code:
.header {
background-color: #fff;
position: fixed;
text-align: center;
height: 50px;
width: 100%;
max-width: 480px;
box-shadow: 1px 1px 4px 0 rgba(0, 0, 0, .1);
z-index: 3;
display: flex;
flex-direction: row-reverse;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center;
}
.header ul {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: #fff;
display: flex;
flex-direction: column;
flex: 1;
}
.header .logo {
/*float: right; */
display: block;
font-size: 1em;
padding: 20px 20px;
color: #000;
display: inline-block;
}
.header .logo img {
height: 12px;
width: 12px;
}
.header .mail {
/* float: right; */
display: block;
font-size: 1em;
padding: 20px 20px;
color: #000;
display: inline-block;
}
.header .mail img {
height: 15px;
width: 19px;
}
.header .menu-item {
font-size: 1em;
color: #000;
padding-top: 30px;
line-height: 2.5em;
}
.header .menu-sub-item {
font-size: 1em;
color: #c4c0bf;
line-height: 2.5em;
}
.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
display: flex;
}
<header class="header">
<img src="" alt="">
<img src="" alt="">
<input class="menu-btn" type="checkbox" id="menu-btn">
<label class="menu-icon" for="menu-btn"><span class="nav-icon"></span></label>
<ul class="menu">
<li class="menu-item"><span></span></li>
<li class="menu-sub-item">
</li>
<hr>
<li class="menu-item"><span></span></li>
<li class="menu-sub-item">
</li>
<li class="menu-sub-item">
</li>
<li class="menu-sub-item">
</li>
<li class="menu-sub-item">
</li>
<hr>
<li class="menu-item"><span></span></li>
<li class="menu-sub-item">
</li>
<li class="menu-sub-item">
</li>
<li class="menu-sub-item">
</li>
</ul>
</header>
[as you see, the menu has reduced his size and the drop down went up after moving all elements into flexbox, before the menu cover his width and drop down cover all the background]
I'm looking to distribute the space between the links evenly, so each take up 1/3 of the space of the containing div. The whole reason they are within this div is because I want to line it up with the banner, and I'm unsure how to it otherwise.
Here is a fiddle:
https://jsfiddle.net/yuy84gmq/13/
.bruceBanner img {
border: 2px solid black;
height: 172px;
width: 553px;
display: block;
margin: 0 auto;
}
.navLinks li {
border: 1px solid black;
display: inline;
font-size: 25px;
}
#navBar {
border: 1px solid black;
width: 553px;
margin: 0 auto;
}
<div class="bruceBanner">
<a href="#">
<img border="0" alt="XYZ Banner" src="http://bit.ly/1QSpdbq" width="553" height="172">
</a>
</div>
<nav id="navBar">
<ul class="navLinks">
<li><a href='#'>About</a>
</li>
<li><a href='#'>Hours</a>
</li>
<li><a href='#'>Contact</a>
</li>
</ul>
</nav>
<!--#navBar-->
Use flexbox and set justify-content to space-between or space-around:
space-between
Flex items are evenly distributed in the line. [...]
space-around
Flex items are evenly distributed in the line, with half-size spaces on either end. [...]
.navLinks {
display: flex;
justify-content: space-around;
}
.bruceBanner img {
border: 2px solid black;
height: 172px;
width: 553px;
display: block;
margin: 0 auto;
}
.navLinks li {
border: 1px solid black;
display: inline;
font-size: 25px;
}
#navBar {
border: 1px solid black;
width: 553px;
margin: 0 auto;
}
.navLinks {
display: flex;
padding: 0;
justify-content: space-around;
}
<div class="bruceBanner">
<a href="#">
<img border="0" alt="XYZ Banner" src="http://bit.ly/1QSpdbq" width="553" height="172">
</a>
</div>
<nav id="navBar">
<ul class="navLinks">
<li><a href='#'>About</a></li>
<li><a href='#'>Hours</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</nav>
I see a flexbox solution has been posted, so I'll post the table/table-cell solution. It's a simple but effective, and you don't have to worry about browser discrepancies.
.bruceBanner img {
border: 2px solid black;
height: 172px;
width: 553px;
display: block;
margin: 0 auto;
}
#navBar {
border: 1px solid black;
width: 553px;
margin: 0 auto;
}
/* set the container to act like a table */
.navLinks {
display: table;
table-layout: fixed; /* evenly space all elements */
/* remove default styling */
width: 100%;
margin: 0;
padding: 0;
}
.navLinks li {
display: table-cell;/* set to a table-cell */
text-align: center;
font-size: 25px;
padding: 10px;
}
.navLinks a {
border: 1px solid black;
}
<div class="bruceBanner">
<a href="#">
<img border="0" alt="XYZ Banner" src="http://bit.ly/1QSpdbq" width="553" height="172">
</a>
</div>
<nav id="navBar">
<ul class="navLinks">
<li><a href='#'>About</a>
</li>
<li><a href='#'>Hours</a>
</li>
<li><a href='#'>Contact</a>
</li>
</ul>
</nav>
<!--#navBar-->
Try This code
is working for me
.bruceBanner img {
border: 2px solid black;
height: 172px;
width: 553px;
display: block;
margin: 0 auto;
}
.navLinks{
padding: 0px;
}
.navLinks li {
border: 1px solid black;
display: inline-block;
font-size: 25px;
width:32%;
}
#navBar {
border: 1px solid black;
width: 553px;
margin: 0 auto;
}
<div class="bruceBanner">
<a href="#">
<img border="0" alt="XYZ Banner" src="http://bit.ly/1QSpdbq" width="553" height="172">
</a>
</div>
<nav id="navBar">
<ul class="navLinks">
<li><a href='#'>About</a>
</li>
<li><a href='#'>Hours</a>
</li>
<li><a href='#'>Contact</a>
</li>
</ul>
</nav>
hi xD
your css:
.bruceBanner img {
border: 2px solid black;
height: 172px;
width: 553px;
display: block;
margin: 0 auto; /*After setting a width this will make object sit centrally within parent container. Auto sets left and right margins equally. 0 denotes no top or bottom margin */
}
.li1 {
border: 1px solid black;
display:inline-block;
margin-right: 15%;
float: left;
}
.li2 {
border: 1px solid black;
display:inline-block;
margin-right: 17%;
margin-left: 20%;
}
.li3 {
border: 1px solid black;
display:inline-block;
float: right;
margin-right: 8%;
}
/* Adjust left/right margin as appropriate */
#navBar {
border: 1px solid black;
width:553px;
margin: 0 auto;
}
your html:
<body>
<div class="bruceBanner">
<a href="#">
<img border="0" alt="XYZ Banner" src="http://bit.ly/1QSpdbq" width="553" height="172">
</a>
</div>
<nav id="navBar">
<ul class="navLinks">
<li class="li1"><a href='#'>About</a></li>
<li class="li2"><a href='#'>Hours</a></li>
<li class="li3"><a href='#'>Contact</a></li>
</ul>
</nav> <!--#navBar-->
</body>
So i have navigation that is width: 78.8%; and i need to put text inside like this on fiddle: https://jsfiddle.net/cj8c7mhr/
But how can i set with automatic so that i can put longer words.
<div class="nav-wrapp">
<div class="nav-box">
<nav class="navbar navbar-default pull-left">
<ul class="nav navbar-nav ">
<li>O Revicon</li>
<li>Konzalting</li>
<li>Seminar i savjetovanja</li>
<li>Časopisi</li>
<li>Izdavaštvo</li>
<li>Kontakt</li>
</ul>
</nav>
</div>
</div>
I want that they be next each other...
CSS Tables would seem to be the answer here:
ul.nav.navbar-nav {
width: 100%;
display: table;
}
ul.nav.navbar-nav li {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.nav-wrapp {
float: left;
border-top: 3px solid #C20C0C;
border-bottom: 1px solid #ccc;
width: 78.8%;
}
.nav-box {
float: left;
width: 100%;
}
.nav-wrapp .navbar-default {
background-color: #fff;
border: 0px;
margin-bottom: 0px;
height: 100%;
font-family: 'PT_Sans_Caption_Bold';
font-size: 16px;
width: 100%;
}
ul.nav.navbar-nav {
width: 100%;
display: table;
}
ul.nav.navbar-nav li {
display: table-cell;
text-align: center;
vertical-align:middle;
}
.nav-wrapp .nav.navbar-nav>li {
border-right: 1px solid #ccc;
min-height: 55px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="nav-wrapp">
<div class="nav-box">
<nav class="navbar navbar-default pull-left">
<ul class="nav navbar-nav ">
<li>O Revicon
</li>
<li>Konzalting
</li>
<li>Seminar i savjetovanja
</li>
<li>Časopisi
</li>
<li>Izdavaštvo
</li>
<li>Kontakt
</li>
</ul>
</nav>
</div>
</div>