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.
Related
I have a navbar inside a header tag. the header tag is flex. the navbar too. in the navbar i have three a tags with the display value inline-block; and a padding in the height and width. So far so good. When i hover the links the hover effect is shown over the whole height.
The problem: If I add an image to the first link, I can't make the image higher than 10 px because the padding affects the entire navbar height. What I do not want.
Question: How can I add the image to the link without it affecting the height of the navbar?
My code
body {
margin: 0;
padding: 0;
}
header {
display:flex;
justify-content: space-between;
align-items: center;
background: green;
position: fixed;
top: 0;
overflow: hidden;
width:100%;
}
.logo {
background: yellow;
display: flex;
align-items: center;
}
.navbar {
background-color: #333;
display: flex;
align-items: center;
}
.navbar a:not(:first-child) {
display: inline-block;
}
.navbar a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 12px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.flex {
gap:10px;
display: flex;
align-items: center;
font-size: 12px;
}
.main {
margin-top: 180px;
color: color;
height:50vh;
background: black;
}
<div>
<header>
<div class="logo">
<img src="https://via.placeholder.com/40">Logo
</div>
<nav class="navbar">
<a href="#home">
<div class="flex">
<div>
<img src="https://via.placeholder.com/30">
</div>
<div>10000</div>
</div>
</a>
News
Contact
</nav>
</header>
<main class="main">
text
</main>
</div>
expected
body {
margin: 0;
pading: 0;
}
header {
display:flex;
justify-content: space-between;
align-items: center;
background: green;
position: fixed;
top: 0;
overflow: hidden;
width:100%;
}
.logo {
background: yellow;
display: flex;
align-items: center;
}
.navbar {
background-color: #333;
display: flex;
align-items: center;
}
.navbar a:not(:first-child) {
display: inline-block;
}
.navbar a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 12px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.flex {
gap:10px;
display: flex;
align-items: center;
font-size: 12px;
}
.main {
margin-top: 180px; /* Add a top margin to avoid content overlay */
color: color;
height:50vh;
background: black;
}
<div>
<header>
<div class="logo">
<img src="https://via.placeholder.com/40">Logo
</div>
<nav class="navbar">
<a href="#home">
10000
</a>
News
Contact
</nav>
</header>
<main class="main">
xca
</main>
</div>
Use flex behavior to align and stretch instead of additional markups
In the code snippet below, I removed the extra markup in the first a element that contains the img. Instead, I made all a tags display: inline-flex and removed vertical padding in the first one. Then, using the parent nav element's align-items property, I ensured each a tag has the same full height for consistent hover effect.
body {
margin: 0;
padding: 0;
}
header {
display:flex;
justify-content: space-between;
align-items: center;
background: green;
position: fixed;
top: 0;
overflow: hidden;
width:100%;
}
.logo {
background: yellow;
display: flex;
align-items: center;
}
.navbar {
background-color: #333;
display: flex;
align-items: stretch;
}
.navbar a {
display: inline-flex;
}
.navbar a {
color: #f2f2f2;
justify-content: center;
align-items: center;
padding: 14px 16px;
text-decoration: none;
font-size: 12px;
}
.navbar a:first-of-type {
padding-top:0;
padding-bottom:0;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.flex {
gap:10px;
display: flex;
align-items: center;
font-size: 12px;
}
.main {
margin-top: 180px;
color: color;
height:50vh;
background: black;
}
<div>
<header>
<div class="logo">
<img src="https://via.placeholder.com/40">Logo
</div>
<nav class="navbar">
<a href="#home">
<img src="https://via.placeholder.com/30">
10000
</a>
News
Contact
</nav>
</header>
<main class="main">
text
</main>
</div>
So, right now my header doesn´t look good on mobile. - The words overlap. They should remain in the same order... I tried to use line-height, which did not really change anything. Maybe you have some suggestions on how I can fix this problem. I am thankful for every suggestion!
[enter
.header {
width: 100%;
height: 7vh;
padding: 0 5%;
color: white;
font-size: larger;
background-color: black;
z-index:100;
position: sticky;
top: 0;
display: flex;
justify-content: space-between;
overflow: hidden;
line-height: 10px;
}
nav {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 0;
}
nav ul li {
display: inline-block;
list-style: none;
margin: 10px 30px;
}
nav ul li a {
text-decoration: none;
color: white;
}
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.Menü {
color: white;
text-decoration: none;
margin-left: 40px;
}
<div class="header" >
<nav>
<div>
<Button class="ImageButton"> <input class="ImageButton" type="image" src="/Images/Camellion Logo Website.png"></Button>
</div>
<ul>
<a class="Menü" href="/Galerie/Galerie.html">Galerie</a>
<a class="Menü" href="#Leistungen">Leistungen</a>
<a class="Menü" href="#Kontakt">Kontakt & Standort <i class="fa-solid fa-location-dot"></i></a>
</ul>
</nav>
</div>
There is a thing in CSS called media queries. With media queries you can write for example CSS that only takes effect if screen is certain size.
For example
#media only screen and (min-width: 360px) and (max-width: 800px) {
.header {
height: 60px;
}
}
Will set header height to 60px if the device that the page is opened on has screen width more then 360px and less then 800px.
Here is your code with couple adjustments
* { padding: 0; margin: 0; box-sizing: border-box; }
.header {
width: 100%;
padding: 0 20px;
color: white;
background-color: black;
position: sticky;
z-index:100;
top: 0;
}
.navigation {
margin: auto;
max-width: 1200px;
height: 80px;
display: flex;
align-items: center;
justify-content: space-between;
}
.menu-icon { /* CSS to just to simulate Icon */
height: 40px;
width: 40px;
background-color: white;
border-radius: 10px;
}
.menu {
display: flex;
align-items: center;
gap: 40px;
}
.menu-item {
color: white;
text-decoration: none;
white-space: nowrap; /* Will not let words to break to next line */
font-size: 20px;
font-weight: 700;
}
#media(max-width: 600px) {
.header { padding: 0 10px; }
.navigation { height: 60px; }
.menu { gap: 20px;}
.menu-item { font-size: 14px; }
}
#media(max-width: 400px) {
.menu { gap: 10px;}
.menu-item { font-size: 12px; }
}
<header class="header" >
<nav class="navigation">
<div class="menu-icon" title="Menu icon / hamburger icon"></div>
<div class="menu">
<a class="menu-item" href="/Galerie/Galerie.html">Galerie</a>
<a class="menu-item" href="#Leistungen">Leistungen</a>
<a class="menu-item" href="#Kontakt">Kontakt & Standort <i class="fa-solid fa-location-dot"></i></a>
</div>
</nav>
</header>
You can adjust your css even further. It's very popular to have icons with menu elements and on mobile view they become a bottom navigation bar with big icons and tiny text.
#media (max-width:767px) {
* {
box-sizing: border-box;
}
nav {
flex-direction: column;
}
nav .Menu {
margin-inline: 9px
}
}
good luck
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>
When I put in my header (i have already put in my context) it just puts the header underneath what the context is so you can't see the header.
I have already tried changing the padding and the other sizes but none work
https://jsfiddle.net/L30trdfn/1/This is the full code of my website
What should happen is that the description and avatar ECT should go under the navbar and fit
Change your CSS code Like this
.split {
width: 100%;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
width:50%;
height:50%;
flex: 0 0 50%;
max-width: 50%;
padding-top: 50px;
overflow-x: hidden;
}
.black{background-color: #f5f5f5;}
.red{background-color: #f00;}
.centered {
text-align: center;
}
Corresponding html like this
<div class="split">
<div class="col black">
<div class="centered">
<img src="avatar1.png" alt="Avatar woman">
<h2>Fortnitewinner21</h2>
<p>Co-Owner of FSX/XP11 and is the Head Website devolper</p>
</div>
</div>
<div class="col red">
<div class="centered">
<img src="avatar2.png" alt="Avatar man">
<h2>MasterPilot</h2>
<p>Owner of FSX/XP11, He plays a big part in making the server run smoothley</p>
</div>
</div>
</div>
Change the img src according to your sources
{
font-family: Arial;
color: white;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial;
padding: 10px;
background: #9099A2;
}
/* Header/Blog Title */
.header {
padding: 30px;
text-align: center;
color: white;
background: #6D7993;
}
.header h1 {
font-size: 50px;
}
/* Navbar container */
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial;
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: indianred;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Left column */
.leftcolumn {
float: left;
width: 75%;
}
/* Right column */
.rightcolumn {
float: left;
width: 25%;
background-color: #9099A2;
padding-left: 20px;
}
/* Fake image */
.fakeimg {
width: 100%;
}
/* Add a card effect for articles */
.card {
background-color: #D5D5D5;
padding: 20px;
margin-top: 20px;
box-shadow: 10px 10px 5px grey;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.split {
width: 100%;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
width:50%;
height:50%;
flex: 0 0 50%;
max-width: 50%;
padding-top: 50px;
overflow-x: hidden;
}
.black{background-color: #f5f5f5;}
.red{background-color: #f00;}
.centered {
text-align: center;
}
.centered img {
width: 150px;
border-radius: 50%;
}
<div class="header">
<h1>Welcome To FSX/XP11</h1>
<p>The Home of Flight Sim</p>
</div>
<div class="navbar">
Home
Gallery
<div class="dropdown">
<button class="dropbtn">Flight Planner
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Flight Strips
Login
Register
</div>
</div>
</div>
<div class="split">
<div class="col black">
<div class="centered">
<img src="https://mail.google.com/mail/u/0?ui=2&ik=61315df9c6&attid=0.1&permmsgid=msg-f:1648390313577802256&th=16e04241b3ffea10&view=fimg&sz=s0-l75-ft&attbid=ANGjdJ8KWZCU9VW1k7NdYrm1ZoOE30R5M9Aoeokzr0KSjzE53wP1UvEZhJkACRl5RpKmGQs8W9TlWHfQME7CgcCB3TKlJ8lpdJYRU7dwfDfGHHHJvD455hCYQa4OAos&disp=emb&realattid=ii_k26gkdq90" alt="Avatar woman">
<h2>Fortnitewinner21</h2>
<p>Co-Owner of FSX/XP11 and is the Head Website devolper</p>
</div>
</div>
<div class="col red">
<div class="centered">
<img src="img_avatar.png" alt="Avatar man">
<h2>MasterPilot</h2>
<p>Owner of FSX/XP11, He plays a big part in making the server run smoothley</p>
</div>
</div>
</div>
Use the following CSS : \
you had given fixed position in .split and also used absolute position in .centered. I hope you got your answer
.split {
height: 50%;
width: 50%;
overflow-x: hidden;
padding-top: 50px;
}
.centered {
text-align: center;
}
I am using an inline list as a nav menu, and I would like the hyperlink/list item to take up the full height of the container with the label vertically positioned in the center of the container. Here is what I have:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {} #top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>
Any other suggestions you have with any of this is greatly appreciated.
You need to add both height and line-height to the links, and also make sure they are either display: block or display: inline-block. Note that inline-block would be preferred:
#top-nav-container li a {
height: 50px;
line-height: 50px;
display: inline-block;
}
Note that on small screens, the Stuff Here... div would get cut off due to having a current width of 250px. Simply turn this down to say 50px (or however wide your container would actually be):
#top-nav-container .nav-right {
width: 50px;
}
I've created a fiddle showing this here.
Hope this helps! :)
You need to modify your CSS a little, see the following snippet:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {
/* all below rules were added*/
position: absolute;
line-height: 50px;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
#top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
/* all below rules were added*/
height: 50px;
line-height: 50px;
display: inline-block;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>