The ul with class "subnav" should be bigger. I noticed it because the background color is only shown in a small area. If i hover nav ul li the "subnav" ul is not going out of the nav. Strangely the li a inside "subnav" are shown correct and are going outside the nav just fine.
Only when I give the "subnav" a specific height it will go outside the nav.
header {
background-image: url("../images/header.jpg");
background-size: cover;
background-position: 0 -15vh;
background-repeat: no-repeat;
height: 40vh;
display: flex;
align-items: flex-end;
}
nav {
width: 100%;
height: 10vh;
background-color: rgba(255, 255, 255, 0.75);
}
nav ul {
height: 100%;
display: grid;
grid-template-columns: 3fr 1fr 1fr 1fr;
align-items: center;
}
nav ul li {
position: relative;
}
nav ul li a {
color: #1b1a5c;
}
nav ul li .far {
margin-right: 0.5em;
color: #1b1a5c;
}
nav ul li .fas {
margin-right: 0.5em;
color: #1b1a5c;
}
#logo {
height: 100%;
}
#logo img {
max-height: 100%;
}
.subnav {
display: none;
position: absolute;
background-color: #b18e4a;
width: 80%;
transform: translateX(10%);
padding: 0.8em;
z-index: 1;
}
.subnav li {
margin: 0.4em;
}
.subnav li a {
color: white;
}
.subnav li a:hover {
color: #1b1a5c;
}
nav ul li:hover .subnav {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
}
<header>
<nav>
<ul>
<li id="logo">
<img src="images/salonorchesterlogo.png" alt="Logo des Salonorchester Zürich Oberland">
</li>
<li><i class="far fa-calendar-alt"></i>Konzerte
<ul class="subnav">
<li>Kalender</li>
<li>Billette</li>
</ul>
</li>
<li><i class="far fa-newspaper"></i>News</li>
<li><i class="fas fa-info"></i>Über uns
<ul class="subnav">
<li>Orchester</li>
<li>Vorstand</li>
<li>Dirigent</li>
<li>Kontakt</li>
</ul>
</li>
</ul>
</nav>
</header>
The height: 100% property you are setting in the nav ul selector is targeting the top-level ul inside nav as well as your ul.subnav. You could either change the nav ul to nav > ul if you intend it to be specific only to the top-level ul or you could override that height in your .subnav block:
.subnav {
display: none;
position: absolute;
background-color: #b18e4a;
width: 80%;
transform: translateX(10%);
padding: 0.8em;
z-index: 1;
height: auto; /* ADD THIS TO OVERRIDE HEIGHT: 100% SET IN `nav ul` block */
}
You can see this in action in the snippet below:
header {
background-image: url("../images/header.jpg");
background-size: cover;
background-position: 0 -15vh;
background-repeat: no-repeat;
height: 40vh;
display: flex;
align-items: flex-end;
}
nav {
width: 100%;
height: 10vh;
background-color: rgba(255, 255, 255, 0.75);
}
nav ul {
height: 100%;
display: grid;
grid-template-columns: 3fr 1fr 1fr 1fr;
align-items: center;
}
nav ul li {
position: relative;
}
nav ul li a {
color: #1b1a5c;
}
nav ul li .far {
margin-right: 0.5em;
color: #1b1a5c;
}
nav ul li .fas {
margin-right: 0.5em;
color: #1b1a5c;
}
#logo {
height: 100%;
}
#logo img {
max-height: 100%;
}
.subnav {
display: none;
position: absolute;
background-color: #b18e4a;
width: 80%;
transform: translateX(10%);
padding: 0.8em;
z-index: 1;
height: auto; /* ADD THIS TO OVERRIDE HEIGHT: 100% SET IN `nav ul` block */
}
.subnav li {
margin: 0.4em;
}
.subnav li a {
color: white;
}
.subnav li a:hover {
color: #1b1a5c;
}
nav ul li:hover .subnav {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
}
<header>
<nav>
<ul>
<li id="logo">
<img src="images/salonorchesterlogo.png" alt="Logo des Salonorchester Zürich Oberland">
</li>
<li><i class="far fa-calendar-alt"></i>Konzerte
<ul class="subnav">
<li>Kalender</li>
<li>Billette</li>
</ul>
</li>
<li><i class="far fa-newspaper"></i>News</li>
<li><i class="fas fa-info"></i>Über uns
<ul class="subnav">
<li>Orchester</li>
<li>Vorstand</li>
<li>Dirigent</li>
<li>Kontakt</li>
</ul>
</li>
</ul>
</nav>
</header>
For what it is worth, I would also revisit your decision to set the positioning to absolute and then use translateX to position the element, as opposed to just using some combination of top, left, right, and bottom. I don't know that there is anything explicitly wrong with that, but I wonder if you might get some unexpected behavior by mixing your intentions there.
Here try this. I gave your .subnav class the style height: auto;. Also I removed your padding and width styles.
.subnav {
height: auto;
display: none;
position: absolute;
background-color: #b18e4a;
/*transform: translateX(10%);*/
z-index: 1;
}
add the height to nav ul li:hover .subnav
nav ul li:hover .subnav {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
height: 150px
}
Related
I'm trying to create a flex header with nav. However, my image doesn't seem to be responsive. As I'm minimizing the width the menu seems to act responsive but my logo image doesn't.
The image is a dummy one, when i set an image with these certain width and height (without adding any dimensions in property i have the same issue)
How can i solve this?
body {
margin: 0;
margin: 0;
width: 100%;
display: flex;
}
header {
width: 100%;
height: 91px;
background-color: #222222;
position: relative;
}
a {
text-decoration: none;
color: #fff;
font-size: 15px;
line-height: 17.22px;
}
ul {
list-style: none;
}
nav {
display: flex;
justify-content: space-between;
}
nav ul {
display: flex;
justify-content: center;
align-items: center;
margin-right: 280px;
}
li {
margin-left: 35px;
}
nav img {
display: flex;
margin-left: 254px;
position: relative;
}
<body>
<header>
<nav>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
<ul>
<li style="margin-left:0;">Hompage</li>
<li>About us</li>
<li>Our Services</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</header>
</body>
Preserve aspect ratio:
img {
height: 91px;
width: auto;
}
please check the code you need to add height: 91px; object-fit: contain; in logo image and set max-width for responsive you need to add media query I have mention in code so you can check it.
body {
margin: 0;
margin: 0;
width: 100%;
display: flex;
flex-direction:column;
}
header {
width: 100%;
padding: 10px 0;
background-color: #d2d2d2;
position: relative;
}
a {
text-decoration: none;
color: #000;
font-size: 15px;
}
ul {
list-style: none;
padding:0;
margin:0;
}
nav {
display: flex;
justify-content: space-between;
padding:0 5%;
}
nav ul {
display: flex;
justify-content: center;
align-items: center;
}
li {
margin-right: 35px;
}
li:last-child {
margin-right:0px;
}
nav img {
display: flex;
position: relative;
height: 91px;
object-fit: contain;
width: 100%;
max-width: 100px;
}
#media screen and (max-width:575px){
nav{flex-direction:column;}
nav ul {
display: flex;
justify-content: left;
align-items: center;
margin-top: 20px;
flex-wrap: wrap;
}
}
<body>
<header>
<nav>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
<ul>
<li style="margin-left:0;">Hompage</li>
<li>About us</li>
<li>Our Services</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</header>
</body>
I cannot seem to successfully use display: none !important; nor visibility: hidden; to hide the menu bars and close icons on a desktop. I have tried applying the code to other objects on my website as well (like the hero button) but it also didn't work on that.
You will however see the below code is only applied to the class for the close icon fa fa-times
HTML code:
<!--homepage header -->
<section class="header">
<nav>
<a href="index.html"> <!--add logo-->
<img src="" alt=""><!--add links-->
</a>
<div class="nav-links">
<div class="close-icon">
<!--menu close icon-->
<i class="fas fa-times"></i>
</div>
<ul>
<li>HOME</li><!--add links-->
<li>ABOUT</li><!--add links-->
<li>SOFTWARE</li><!--add links-->
<li>BLOG</li><!--add links-->
<li>CONTACT</li><!--add links-->
</ul>
</div>
<div class="menu-bars">
<!--menu icon-->
<i class="fas fa-bars"></i>
</div>
</nav>
CSS Code
#import url("https://kit.fontawesome.com/d68c6a086c.js")
*{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
.header{
min-height: 100vh;
width: 100%;
/* change image below */
background-image: linear-gradient(rgba(4,9,30,0.7),rgba(4,9,30,0.7)),url(images/ft-870l-500x500.jpg);
background-position: center;
background-size: cover;
position: relative;
}
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
/* nav bar comapny logo*/
nav img{
width: 150px;
}
.nav-links{
flex: 1;
text-align: right;
}
/* list style */
.nav-links ul li {
list-style: none;
display: inline-block;
padding: 8px 12px;
position: relative;
}
/* each link */
.nav-links ul li a{
color: #fff;
text-decoration: none;
font-size: 13px;
}
.nav-links ul li::after{
content: '';
width: 100%;
height: 2px;
background: #f44336;
display: block;
margin: auto;
transition: 0.5s;
}
.nav-links ul li:hover::after{
width: 100%;
}
/* Hide Menu Items for Desktop */
.close-icon {
display: none !important;
visibility: hidden;
}
#media (max-width: 700px) {
.text-box h1{
font-size: 20px;
}
.nav-links ul li {
display: block;
}
.nav-links{
position: absolute;
background: #f44336;
height: 100vh;
width: 200px;
top: 0;
right: 0;
text-align: left;
z-index: 2;
}
.close-icon {
display: block;
color: #fff;
margins: 10px;
font-size: 22px;
cursor: pointer;
}
}
```
Please try
nav {
display: none;
/*padding: 2% 6%;
justify-content: space-between;
align-items: center;*/
}
#media (max-width: 700px) {
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
}
In head section where you added CSS file add
src="folder/stye.css?v=1.1"
Change v=1.1 to 1.2 or 1.3.1 etc.. whenever you make changes in CSS file.
I have this navigation bar that works really well. It is fixed so it follows you as you scroll through the website. However, I would like for the navbar to only start in the second section (#home) and for it to not be visible in the first section (#section0).
Could I please have some help?
#section0 {
width: 100%;
height: 100vh;
background-color: blue;
}
#home {
width: 100%;
height: 100vh;
background-color: white;
display: block;
margin: 0 auto;
}
#home ul {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
z-index: 9999;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
position: -webkit-fixed;
/* Safari */
position: fixed;
top: 0;
}
#home ul li.left-menu {
display: flex;
justify-content: flex-end;
}
#home ul li.right-menu {
display: flex;
justify-content: flex-start;
}
#home li a {
display: block;
color: white;
text-align: center;
padding: 13px 20px;
text-decoration: none;
font-family: Futura;
font-size: 8px;
}
#home li a:hover {
color: #00CFFF;
}
#home .active {
color: #00CFFF;
}
#secondpage {
height: 100vh;
width: 100%;
background-color: orange;
}
<section id="section0">
</section>
<section id="home">
<ul>
<li class="left-menu">
<a class="active" href="#home">HOME</a>
HOW IT WORKS
WHY CHOOSE US
</li>
</li>
<li class="right-menu">
SERVICES
OUR GALLERY
CONTACT US
</li>
</section>
<section id="secondpage">
</section>
Just set a higher z-index for the first section.
body {
margin: 0;
padding: 0;
}
#section0 {
width: 100%;
height: 100vh;
background-color: blue;
z-index: 99999;
position: relative;
}
#home {
width: 100%;
height: 100vh;
background-color: white;
display: block;
margin: 0 auto;
}
#home ul {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
z-index: 9999;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
position: -webkit-fixed;
/* Safari */
position: fixed;
top: 0;
}
#home ul li.left-menu {
display: flex;
justify-content: flex-end;
}
#home ul li.right-menu {
display: flex;
justify-content: flex-start;
}
#home li a {
display: block;
color: white;
text-align: center;
padding: 13px 20px;
text-decoration: none;
font-family: Futura;
font-size: 8px;
}
#home li a:hover {
color: #00CFFF;
}
#home .active {
color: #00CFFF;
}
#secondpage {
height: 100vh;
width: 100%;
background-color: orange;
}
<section id="section0">
</section>
<section id="home">
<ul>
<li class="left-menu">
<a class="active" href="#home">HOME</a>
HOW IT WORKS
WHY CHOOSE US
</li>
</li>
<li class="right-menu">
SERVICES
OUR GALLERY
CONTACT US
</li>
</section>
<section id="secondpage">
</section>
Note:
I have added position: relative to first section (.section0) for z-index to work.
I have remove margin and padding from <body> only to make this snippet clean.
Edit: As you said, the previous example makes the navigation bar slide out from under the first section, you can try this example using position: sticky.
I'll explain what I did here.
I took the navigation bar (<ul>) out of home section.
I have wrapped the element <ul>, home and secondpage in an element and gave it a class called wrapper.
The first section remains out of the wrapper.
I have applied position: sticky; to navigation (<ul>) and added a top value at which the navigation should stay fixed.
I have also added position: relative; to wrapper class for the sticky element to work.
This means the navigation bar (<ul>) stays fixed inside the wrapper class.
Working Example:
body {
margin: 0;
padding: 0;
}
#section0 {
width: 100%;
height: 100vh;
background-color: blue;
position: relative;
}
#home {
width: 100%;
height: 100vh;
background-color: white;
display: block;
margin: 0 auto;
}
ul {
background: #fff;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
z-index: 9999;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
position: -webkit-fixed;
/* Safari */
/*position: fixed;*/
position: sticky;
top: 0;
}
ul li.left-menu {
display: flex;
justify-content: flex-end;
}
ul li.right-menu {
display: flex;
justify-content: flex-start;
}
ul li a {
display: block;
color: white;
text-align: center;
padding: 13px 20px;
text-decoration: none;
font-family: Futura;
font-size: 8px;
}
li a:hover {
color: #00CFFF;
}
.active {
color: #00CFFF;
}
#secondpage {
height: 100vh;
width: 100%;
background-color: orange;
}
.wrapper {
position: relative;
}
<section id="section0">
</section>
<div class="wrapper">
<ul>
<li class="left-menu">
<a class="active" href="#home">HOME</a>
HOW IT WORKS
WHY CHOOSE US
</li>
<li class="right-menu">
SERVICES
OUR GALLERY
CONTACT US
</li>
</ul>
<section id="home">
</section>
<section id="secondpage">
</section>
</div>
I've been trying to make a navbar but I haven't quite been succesful. The navbar div has a height of 60px, however, I can't seem to be able to increase the height of the inside elements in any way. (except padding) What am I doing wrong?
What I'm getting
What I'm trying to get
#navbar {
width: 100vw;
height: 60px;
background: #deff00;
box-shadow: 0 0 50px black;
z-index: 2;
position: relative;
top: 85px;
}
#navbar ul {
height: 100%;
list-style: none;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.navbar-link {
text-decoration: none;
color: black;
height: 60px;
padding: 0 20px;
}
.navbar-link:hover {
background: #adc703;
}
<div id="navbar">
<ul>
<li>
<a href="#" style="font-weight: bold;" class="navbar-link"
>ÚVODNÍ STRÁNKA</a
>
</li>
<li>
ŠKOLA
</li>
<li>STUDIUM</li>
<li>FOTOGALERIE</li>
<li>KONTAKT</li>
</ul>
</div>
Thanks!
Try this:
#navbar {
width: 100vw;
height: 60px;
background: #deff00;
box-shadow: 0 0 50px black;
z-index: 2;
position: relative;
top: 85px;
}
#navbar ul {
height: 100%;
list-style: none;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
#navbar li {
display: table;
}
.navbar-link {
text-decoration: none;
color: black;
height: 60px;
padding: 0 20px;
vertical-align: middle;
display: table-cell;
}
.navbar-link:hover {
background: #adc703;
}
Just added display: table; for the li, and vertical-align: middle;display: table-cell for the a tag, sometimes this old technics fit perfect)
Codepen: https://codepen.io/Liveindream/pen/mdyXmxj?editors=1100
If I'm understanding this question correctly, you want to raise the elements in height. The thing that is constricting you from doing that is inside of your CSS
#navbar ul {
height: 100%;
list-style: none;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
Remove align-items: center; from #navbar ul
So that it looks like this:
#navbar ul {
height: 100%;
list-style: none;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
Now you should be able to increase and/or decrease it in height to correctly align it onto your div tag the way you'd like.
I have a navigation, with fixed height, that use the flexbox layout module. It have two items (ul elements) where in one I want that its li tags take all the height of the nav and the other one I want that its li tags behave normally. I tought that assigning display:block to the li tags that I want they take all the height of the nav would work, but it behaves as a display:inline-block.
nav {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #000;
height: 65px;
}
nav ul {
list-style-type: none;
padding-left: 0;
}
nav ul li {
float: left;
}
nav ul.item1 li {
display: block;
background-color: red;
}
nav ul.item2 li {
display: inline-block;
background-color: green;
}
<nav>
<ul class="item1">
<li>#1</li>
<li>#2</li>
<li>#3</li>
</ul>
<ul class="item2">
<li>#4</li>
<li>#5</li>
<li>#6</li>
</ul>
</nav>
Short answer is to use nested flexbox.
Remove align-items: center; from nav, so that flex items can stretch (default behavior) to the same height as the container.
Reset the margin by adding ul { margin: 0; }, so that no top and bottom margins.
Remove all the float and inline-block, you don't need it in flexbox layout.
Apply display: flex; to all - nav, ul, and li.
Finally add align-items: center; to the li to center the text vertically.
nav {
display: flex;
justify-content: space-between;
background-color: black;
height: 65px;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
}
nav li {
display: flex;
align-items: center;
}
nav ul.item1 li {
background-color: red;
}
nav ul.item2 li {
background-color: green;
}
<nav>
<ul class="item1">
<li>#1</li>
<li>#2</li>
<li>#3</li>
</ul>
<ul class="item2">
<li>#4</li>
<li>#5</li>
<li>#6</li>
</ul>
</nav>
Update
Modified version for just the left side fully stretches to height, and the right side behaves as inline elements.
nav {
display: flex;
justify-content: space-between;
background-color: black;
height: 65px;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
}
nav li {
display: flex;
}
nav ul.item1 li {
align-items: center;
background-color: red;
}
nav ul.item2 {
align-items: center;
}
nav ul.item2 li {
background-color: green;
}
<nav>
<ul class="item1">
<li>#1</li>
<li>#2</li>
<li>#3</li>
</ul>
<ul class="item2">
<li>#4</li>
<li>#5</li>
<li>#6</li>
</ul>
</nav>
Just add height: 100% to both the ul and li.
nav {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #000;
height: 65px;
}
nav ul {
list-style-type: none;
padding-left: 0;
height: 100%;
display: flex;
align-items: center;
}
nav ul li {
float: left;
display: flex;
align-items: center;
}
nav ul.item1 li {
background-color: red;
height: 100%;
}
nav ul.item2 li {
background-color: green;
}
<nav>
<ul class="item1">
<li>#1</li>
<li>#2</li>
<li>#3</li>
</ul>
<ul class="item2">
<li>#4</li>
<li>#5</li>
<li>#6</li>
</ul>
</nav>