I have a website home page which has a menu (with a drop down) than an image (with text overplayed). For whatever reason the image is floating above the menu, so when you hover on the drop down it hides the menu behind the image.
HTML
* {
margin: 0;
padding: 0;
}
body {
background-color: #f3f3f3;
}
nav {
width: 100%;
height: 60px;
background-color: #fff;
position: fixed;
}
nav p {
font-family: arial;
color: #222;
font-size: 22px;
line-height: 55px;
float: left;
padding-left: 20px;
}
nav ul li {
list-style: none;
float: left;
position: relative;
text-transform: uppercase;
}
nav ul li a {
display: block;
padding: 21px 14px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li img {
float: right;
width: 8px;
padding-left: 6px;
position: relative;
top: 5px;
}
nav ul li ul {
display: none;
position: absolute;
padding: 10px;
background-color: #fff;
border-radius: 0px 0px 4px 4px;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
clear: both;
width: 180px;
border-radius: 4px;
}
nav ul li ul li a {
display: block;
padding: 11px 10px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li ul li:hover {
background-color: #eee;
}
.wrapper {
padding: 0px 0px
}
.search form {
list-style: none;
float: right;
position: relative;
padding-top: 8px;
padding-right: 20px;
}
.search input[type=text] {
width: 132px;
box-sizing: border-box;
border: 0.5px solid #ccc;
border-radius: 2px;
font-size: 16px;
background-color: white;
background-image: ('img/searchicon.png');
background-position: 10px 10px;
padding: 12px 20px 12px 40px;
}
.search input[type=text]:focus {
width: 300px;
}
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
h2 span.spacer {
padding:0 5px;
} here
<header>
<nav>
<p>Website Name</p>
<ul>
<li>Home</li>
<li>Resources <img src="img/dropdown.png">
<ul>
<li>About</li>
<li>Archives</li>
<li>Contact</li>
</ul>
</li>
<li>Login</li>
</ul>
<div class="search">
<form>
<input type="text" name="search" placeholder="Search...">
</form>
</div>
</nav>
</header>
<p style="line-height:400%"> </p>
<section>
<div class="image">
<img src="img/Shome.jpg" alt="Rowing" width="100% height="500px">
<h2><span>Site Name: <br /> Portal and Online Archives</span></h2>
</div>
</section>
Use z-index for making the dropdown above the image.An element with greater z-index will be on the top of that with lower z-index
* {
margin: 0;
padding: 0;
}
body {
background-color: #f3f3f3;
}
nav {
width: 100%;
height: 60px;
background-color: #fff;
position: fixed;
}
nav p {
font-family: arial;
color: #222;
font-size: 22px;
line-height: 55px;
float: left;
padding-left: 20px;
}
nav ul li {
list-style: none;
float: left;
position: relative;
text-transform: uppercase;
}
nav ul li a {
display: block;
padding: 21px 14px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li img {
float: right;
width: 8px;
padding-left: 6px;
position: relative;
top: 5px;
}
nav ul li ul {
display: none;
position: absolute;
padding: 10px;
background-color: #fff;
border-radius: 0px 0px 4px 4px;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
clear: both;
width: 180px;
border-radius: 4px;
}
nav ul li ul li a {
display: block;
padding: 11px 10px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li ul li:hover {
background-color: #eee;
}
.wrapper {
padding: 0px 0px
}
.search form {
list-style: none;
float: right;
position: relative;
padding-top: 8px;
padding-right: 20px;
}
.search input[type=text] {
width: 132px;
box-sizing: border-box;
border: 0.5px solid #ccc;
border-radius: 2px;
font-size: 16px;
background-color: white;
background-image: ('img/searchicon.png');
background-position: 10px 10px;
padding: 12px 20px 12px 40px;
}
.search input[type=text]:focus {
width: 300px;
}
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
h2 span.spacer {
padding:0 5px;
} here
<header>
<nav>
<p>Website Name</p>
<ul>
<li>Home</li>
<li>Resources <img src="img/dropdown.png">
<ul>
<li>About</li>
<li>Archives</li>
<li>Contact</li>
</ul>
</li>
<li>Login</li>
</ul>
<div class="search">
<form>
<input type="text" name="search" placeholder="Search...">
</form>
</div>
</nav>
</header>
<p style="line-height:400%"> </p>
<section>
<div class="image">
<img src="img/Shome.jpg" alt="Rowing" width="100% height="500px">
<h2><span>Site Name: <br /> Portal and Online Archives</span></h2>
</div>
</section>
Related
I'm having trouble making a dropdown menu. My dropdown menu just won't show upon hover, but if I change my display from none to block in .submenu ul li, the dropdown is in the right place.
Can anyone please help me?
* {
padding: 0;
margin: 0;
text-decoration: none;
list-style: none;
box-sizing: border-box;
}
body {
font-family: 'montserrat';
}
.container {
height: 80px;
width: 100%;
background: #34495e;
display: block;
float: right;
}
h1.logo {
font-size: 35px;
font-weight: bold;
color: white;
padding: 0 40px;
line-height: 80px;
float: left;
width: auto;
/* border: 1px red solid; */
}
.logo span {
color: #3498db;
}
nav ul {
float: right;
margin-right: 40px;
/* border: 1px red solid; */
}
nav li {
display: inline-block;
margin: 0 5px;
line-height: 80px;
text-align: center;
/* border: 1px red solid; */
}
nav a {
color: white;
font-size: 18px;
text-transform: uppercase;
padding: 7px 10px;
border-radius: 3px;
}
a.active,
a:hover {
border: 1px solid white;
transition: .5s ease-in;
}
nav #icon {
color: white;
font-size: 30px;
line-height: 80px;
float: right;
margin-right: 40px;
cursor: pointer;
background: #34495e;
border: none;
}
#media (min-width: 980px) {
h1.logo {
font-size: 32px;
padding-left: 60px;
}
nav ul {
margin-right: 20px;
}
nav a {
font-size: 17px;
}
nav #icon {
display: none;
}
div button {
display: none;
}
}
#media(max-width:980px) {
nav #icon {
display: block;
}
nav ul {
position: fixed;
width: 100%;
height: 100vh;
background: #2f3640;
top: 80px;
left: -100%;
text-align: center;
transition: all .5s ease-in;
}
.submenu ul {
top: 100%;
}
nav li {
display: block;
margin: 50px 0;
line-height: 30px;
}
nav a {
font-size: 20px;
text-align: center;
}
a.active,
a:hover {
border: none;
color: #3498db;
}
#btn1:hover {
border: none;
color: #3498db;
}
#btn2:hover {
border: none;
color: #3498db;
}
#btn3:hover {
border: none;
color: #3498db;
}
nav ul.show {
left: 0;
}
}
body {
background-image: url('../images/workout.jpg');
background-size: cover;
height: calc(100vh-80px);
}
div .connect {
background: #2f364e;
display: inline-block;
width: auto;
height: auto;
}
#btn1 {
background: #2f364e;
padding: .5em .7em;
border: none;
font-size: 20px;
color: white;
margin: 0 5px;
}
#btn2 {
background: #2f364e;
padding: .5em .7em;
border: none;
font-size: 20px;
color: white;
margin: 0 5px;
}
#btn3 {
background: #2f364e;
color: white;
padding: .5em .7em;
border: none;
font-size: 20px;
margin: 0 5px;
}
.submenu ul li {
display: none;
background: #34495e;
border-radius: 6px;
padding: 0 2px;
text-align: center;
opacity: 0.9;
transition: .5s ease-in;
}
.submenu ul {
margin: 0;
padding: 0;
}
.submenu li a {
margin: 0;
padding: .5em;
}
.main-nav li :hover .submenu {
display: block;
}
<header>
<nav class="container">
<h1 class="logo">Fitness Fir<span>st</span></h1>
<nav class="navbar">
<div class="main-nav">
<ul>
<li><a class="active" href="#">Home</a></li>
<li>About</li>
<li>Services
<div class="submenu">
<ul>
<li>Membership</li>
<li>Coaching</li>
</ul>
</div>
</li>
<li>Timetables</li>
<li>Contact</li>
<div class="connect" class="button">
<button id="btn1"><i class="fa fa-facebook"></i></button>
<button id="btn2"><i class="fa fa-instagram"></i></button>
<button id="btn3"><i class="fa fa-twitter"></i></button>
</div>
</ul>
<button id="icon"><i class="fa fa-bars" style="font-size:36px"></i></button>
</div>
</nav>
</nav>
</header>
Issue
In your CSS file, you have only hidden the li elements in your submenu:
.submenu ul li {
display: none;
background: #34495e;
border-radius: 6px;
padding: 0 2px;
text-align: center;
opacity: 0.9;
transition: .5s ease-in;
}
But here, you're trying to display the .submenu class, rather than the lis inside. In addition, the :hover selector is not attached to the li
.main-nav li :hover .submenu {
display: block;
}
Fix
To fix this we can change the above selector to the below, so that it is now un-hiding the submenu's lis, when you hover over the parent li (Services button)
.main-nav li:hover .submenu li {
display: block;
}
I already did some search on some questions here on stack overflow and tested some solutions mentioned but it did not fix my problem. I'm new in coding.
I also did some research online but haven't found answers that fixed my problem.
-FIRST PROBLEM SOLVED-
-NEW PROBLEM DESCRIBED BELOW-
Edit: Dropdown menu positioning fixed, it is now on vertical. But the new problem is dropdown menu items quickly disappears before I hover on it. And it seems my login form was not attached inside the nav. Please check if the is a conflict or problem with my css and code. Can't fix it
Here is my code:
/*MY CSS CODE*/
* {
text-decoration: none;
box-sizing: border-box;
}
main {
padding-top: 100px;
}
header {
position: fixed;
top: 0;
right: 0;
left: 0;
background-color: #ffcce6;
width: 100%;
height: 100px;
}
header .header-brand {
font-family: Catamaran;
font-size: 24px;
font-weight: 900;
color: #111;
text-transform: uppercase;
display: block;
margin: 0 auto;
text-align: center;
padding: 20px 0px;
}
header nav ul {
display: block;
margin: 0 auto;
width: fit-content;
}
header nav ul li {
display: inline-block;
float: left;
list-style: none;
padding: 0 16px;
}
header nav ul li a {
font-family: Catamaran;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.dropdown {
float: left;
overflow: hidden;
font-family: Catamaran;
font-size: 16px;
color: #111;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #ffe6f3;
flex-direction: column;
/* <--- here add this line */
padding: 0;
/* <--- this will fix the alignment */
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
padding: 12px 8px;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: hotpink;
}
.dropdown:hover .dropdown-content {
display: flex;
/* <-- replace 'block' by 'flex' */
}
/*NAVBAR LOGIN FORM*/
header nav .login-container {
float: right;
padding-top: 20px;
}
header nav .login-container form {
display: inline;
}
header nav input[type=text],
header nav input[type=password] {
padding: 6px;
margin-top: 8px;
font-family: 'New Tegomin', serif;
font-size: 17px;
border: 1px solid #ddd;
border-radius: 5px;
width: 180px;
color: #333;
}
header nav .login-container button {
position: relative;
float: right;
padding: 6px 10px;
margin-top: 8px;
margin-left: 6px;
margin-right: 50px;
background-color: deeppink;
color: white;
font-family: 'New Tegomin', serif;
font-size: 17px;
border: none;
border-radius: 5px;
width: 80px;
cursor: pointer;
}
header nav .login-container button:hover {
background-color: hotpink;
}
header .header-brand {
margin: 31px 0;
text-align: left;
line-height: 38px;
padding: 0 20px 0 40px;
border-right: 3px solid #111;
float: left;
}
header nav ul {
margin: 20px 0px 0px 20px;
float: left;
}
header nav ul li a {
line-height: 60px;
}
<body>
<header>
Team-Rocket
<nav>
<ul>
<li>Home</li>
<li>Products</li>
<li class="dropdown">
<a class="dropbtn">Legit Check
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-content">
<li>Search by ID</li>
<li>Search by Username</li>
</ul>
</li>
<li class="dropdown">
<a class="dropbtn">Member List
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-content">
<li>Regional Distributors</li>
<li>Provincial Distributors</li>
<li>City Distributors</li>
<li>Reseller</li>
<li>Sub-Reseller</li>
</ul>
</li>
</ul>
<div class="login-container">
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="pwd">
<button type="submit">Login</button>
</form>
</div>
</nav>
</header>
</body>
edit your .dropdown-content like this:
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
flex-direction: column; /* <--- here add this line */
padding: 0; /* <--- this will fix the alignment */
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
and edit .dropdown:hover .dropdown-content like this:
.dropdown:hover .dropdown-content {
display: flex; /* <-- replace 'block' by 'flex' */
}
This will work properly.
Here is the snippet:
* {
text-decoration: none;
box-sizing: border-box;
}
main {
padding-top: 100px;
}
header {
position: fixed;
top: 0;
right: 0;
left: 0;
background-color: #ffcce6;
width: 100%;
height: 100px;
}
header .header-brand {
font-family: Catamaran;
font-size: 24px;
font-weight: 900;
color: #111;
text-transform: uppercase;
display: block;
margin: 0 auto;
text-align: center;
padding: 20px 0px;
}
header nav ul {
display: block;
margin: 0 auto;
width: fit-content;
}
header nav ul li {
display: inline-block;
float: left;
list-style: none;
padding: 0 16px;
}
header nav ul li a {
font-family: Catamaran;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.dropdown {
float: left;
overflow: hidden;
font-family: Catamaran;
font-size: 16px;
color: #111;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #ffe6f3;
flex-direction: column;
/* <--- here add this line */
padding: 0;
/* <--- this will fix the alignment */
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
padding: 12px 8px;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: hotpink;
}
.dropdown:hover .dropdown-content {
display: flex;
/* <-- replace 'block' by 'flex' */
}
/*NAVBAR LOGIN FORM*/
header nav .login-container {
float: right;
padding-top: 20px;
}
header nav .login-container form {
display: inline;
}
header nav input[type=text],
header nav input[type=password] {
padding: 6px;
margin-top: 8px;
font-family: 'New Tegomin', serif;
font-size: 17px;
border: 1px solid #ddd;
border-radius: 5px;
width: 180px;
color: #333;
}
header nav .login-container button {
position: relative;
float: right;
padding: 6px 10px;
margin-top: 8px;
margin-left: 6px;
margin-right: 50px;
background-color: deeppink;
color: white;
font-family: 'New Tegomin', serif;
font-size: 17px;
border: none;
border-radius: 5px;
width: 80px;
cursor: pointer;
}
header nav .login-container button:hover {
background-color: hotpink;
}
header .header-brand {
margin: 31px 0;
text-align: left;
line-height: 38px;
padding: 0 20px 0 40px;
border-right: 3px solid #111;
float: left;
}
header nav > ul {
margin: 20px 0px 0px 20px;
float: left;
}
header nav ul li a {
line-height: 60px;
}
<header>
Team-Rocket
<nav>
<ul>
<li>Home</li>
<li>Products</li>
<li class="dropdown">
<a class="dropbtn">Legit Check
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-content">
<li>Search by ID</li>
<li>Search by Username</li>
</ul>
</li>
<li class="dropdown">
<a class="dropbtn">Member List
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-content">
<li>Regional Distributors</li>
<li>Provincial Distributors</li>
<li>City Distributors</li>
<li>Reseller</li>
<li>Sub-Reseller</li>
</ul>
</li>
</ul>
<div class="login-container">
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="pwd">
<button type="submit">Login</button>
</form>
</div>
</nav>
</header>
Add a new line to css
.dropdown-content li{
float:none;
}
The navbar I created overlaps when I switch my site to a mobile view.
I tried making it fit-content, but it still overlaps. The part that overlaps is the listed items
#navBar {
overflow: hidden;
text-align: center;
border-top: double black 2px;
}
#navBar ul {
padding: 0;
list-style: none;
width: fit-content;
}
#navBar li {
display: inline;
padding-top: 23px;
position: relative;
}
#navBar a {
font-size: 20px;
padding-right: 20px;
text-decoration: none;
text-align: center;
border: 4px solid lime;
padding-bottom: 10px;
padding-top: 20px;
padding-left: 10px;
font-family: American Typewriter, serif;
color: #262626;
text-transform: uppercase;
border-radius: 0px 0px 25px 25px;
}
#navBar a:hover {
color: lime;
}
#navBar a::before {
content: '';
display: block;
height: 5px;
width: 100%;
background-color: lime;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
#navBar::hover::before {
width: 100%;
}
<nav id="navBar">
<div class="bar">
<ul>
<li>Tab1</li>
<li>Tab2 </li>
<li> Tab3</li>
</ul>
</div>
</nav>
I expect the navbar items to be side by side but the actual result in them overlapping.
You can use inline-flex for that
change
#navBar ul {
padding: 0;
margin: 0; /* reset margin */
list-style: none;
width: fit-content;
}
#navBar li {
display: inline-flex; /* change to inline-flex and remove the padding */
position: relative;
}
#navBar {
overflow: hidden;
text-align: center;
border-top: double black 2px;
}
#navBar ul {
padding: 0;
margin: 0;
list-style: none;
width: fit-content;
}
#navBar li {
display: inline-flex;
position: relative;
}
#navBar a {
font-size: 20px;
padding-right: 20px;
text-decoration: none;
text-align: center;
border: 4px solid lime;
padding-bottom: 10px;
padding-top: 20px;
padding-left: 10px;
font-family: American Typewriter, serif;
color: #262626;
text-transform: uppercase;
border-radius: 0px 0px 25px 25px;
}
#navBar a:hover {
color: lime;
}
#navBar a::before {
content: '';
display: block;
height: 5px;
width: 100%;
background-color: lime;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
#navBar::hover::before {
width: 100%;
}
<nav id="navBar">
<div class="bar">
<ul>
<li>Tab1</li>
<li>Tab2 </li>
<li> Tab3</li>
</ul>
</div>
</nav>
this is my very first question! Is now a couple of days that I am facing a problementer code here with checkbox creating a slide up/down mobile first menu.
The checkbox is working perfectly but what I am unable to do after is letting the menu slide up and done when checkbox is checked.
Any hint or help for the right direction would be greately appreciated!
<!-- === MENUTOGGLE === -->
<input type="checkbox" name="checkbox" id="menuToggle" value="value">
<label for="menuToggle" class="menu-icon">☰</label>
<!-- ==== HEADER ==== -->
<header>
<div id="logo" class="brand">
<h1><img src="images/logo.png" alt="Hello"></h1>
</div>`enter code here`
<nav class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog </li>
<li>Contact</li>
</ul>
</nav>
</header>
* {
margin: 0;
padding: 0;
outline: none;
box-sizing: border-box;
}
body {
background: #eee;
color: #444;
-webkit-font-smoothing: antialiased;
font-family: Arial, sans-serif;
font-weight: 400;
height: auto !important;
height: 100%;
min-height: 100%;
text-rendering: optimizeLegibility;
}
.menu {
width: 100%;
position: absolute;
top: 66px;
}
.menu-icon {
float: right;
color: blueviolet;
cursor: pointer;
padding-top: 25px;
padding-right: 30px;
}
#menuToggle {
display: none;
}
#menuToggle:checked + .menu {
position: absolute;
top: -66px;
}
#logo {
float: none;
text-align: left;
padding-top: 7px;
padding-left: 2em;
}
header {
display: block;
background-color: #FFF;
}
nav {
text-align: center;
}
nav ul {
background-color: rgba(255, 255, 255, 0.15);
float: none;
line-height: 3.5em;
margin: 0;
}
nav ul li {
display: block;
list-style-type: none;
}
nav ul li:hover {
background-color: rgba(171, 193, 242, 0.1);
}
nav ul li a {
text-decoration: none;
color: red;
}
nav ul li a:hover {
color: aqua;
}
/*------------ MEDIUM BIG SCREEN -----------------------*/
#media screen and (min-width:600px) {
#logo {
float: left;
}
.menu {
width: 100%;
height: 70px;
position: inherit;
}
.menu-icon {
display: none;
}
header {
height: 70px;
background-color: #FFF;
margin: auto;
width: 100%;
}
nav ul {
background-color: #FFF;
float: right;
padding: 0.55em 3em 0.55em 1.5em;
height: 70px;
}
nav ul li {
display: inline-block;
}
nav ul li a {
background-color: #FFF;
padding-left: 3em;
}
I have modified few lines of your code. Just check below or https://jsfiddle.net/pr7xf32q/, if this is what you expect.
* {
margin: 0;
padding: 0;
outline: none;
box-sizing: border-box;
}
body {
background: #eee;
color: #444;
-webkit-font-smoothing: antialiased;
font-family: Arial, sans-serif;
font-weight: 400;
height: auto !important;
height: 100%;
min-height: 100%;
text-rendering: optimizeLegibility;
}
.menu {
width: 100%;
position: absolute;
top: 66px;
}
.menu-icon {
float: right;
color: blueviolet;
cursor: pointer;
padding-top: 25px;
padding-right: 30px;
}
.menu {
display: none;
}
#menuToggle:checked ~ header .menu {
display: block;
}
#logo {
float: none;
text-align: left;
padding-top: 7px;
padding-left: 2em;
}
header {
display: block;
background-color: #FFF;
}
nav {
text-align: center;
}
nav ul {
background-color: rgba(255, 255, 255, 0.15);
float: none;
line-height: 3.5em;
margin: 0;
}
nav ul li {
display: block;
list-style-type: none;
}
nav ul li:hover {
background-color: rgba(171, 193, 242, 0.1);
}
nav ul li a {
text-decoration: none;
color: red;
}
nav ul li a:hover {
color: aqua;
}
/*------------ MEDIUM BIG SCREEN -----------------------*/
#media screen and (min-width:600px) {
#logo {
float: left;
}
.menu {
width: 100%;
height: 70px;
position: inherit;
display: block;
}
.menu-icon {
display: none;
}
header {
height: 70px;
background-color: #FFF;
margin: auto;
width: 100%;
}
nav ul {
background-color: #FFF;
float: right;
padding: 0.55em 3em 0.55em 1.5em;
height: 70px;
}
nav ul li {
display: inline-block;
}
nav ul li a {
background-color: #FFF;
padding-left: 3em;
}
<input type="checkbox" name="checkbox" id="menuToggle" value="value">
<label for="menuToggle" class="menu-icon">☰</label>
<!-- ==== HEADER ==== -->
<header>
<div id="logo" class="brand">
<h1><img src="images/logo.png" alt="Hello"></h1>
</div>
<nav class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog </li>
<li>Contact</li>
</ul>
</nav>
</header>
would you know why my horizontal menu is to floating to the right despite ?
You can view it live here.
<header>
<nav>
<ul>
<li>Home</li>
<li>Work
<ul>
<li>Résumé</li>
<li>Portfolio</li>
</ul>
</li>
<li>Play
<ul>
<li>Experiments</li>
<li>Utilities</li>
</ul>
</li>
<li>Contact</li>
</ul>
</nav>
<div id="news_box" style="max-width: 400px; float: right; text-align: left;"></div>
</header>
CSS:
body {
background-color: rgb(255, 255, 255);
font-family: Helvetica;
font-size: 16px;
font-weight: 400;
line-height: 1.38;
color: rgb(21, 84, 244);
margin: 0;
margin: 0;
padding: 0;
border: 0;
}
header {
width: 100%;
height: 600px;
min-height: 300px;
margin-right: auto;
margin-left: auto;
background-image: url('http://lorempixel.com/output/nature-q-c-1020-711-1.jpg');
background-size: cover;
background-position: center center;
background-color: rgb(222, 222, 222);
}
h1 {
width: 100%;
margin-top: 39px;
margin-right: auto;
margin-left: auto;
font-size: 37px;
font-weight: 400;
line-height: 1.38;
text-align: center;
color: rgb(0,0,0);
}
.blablatext {
margin-top: 16px;
margin-right: auto;
margin-left: auto;
font-weight: 400;
line-height: 1.38;
text-align: center;
color: rgb(21, 84, 244);
}
nav {margin: 20px auto}
nav ul li {display: inline-block; margin-right: -4px; margin-left: 5px; vertical align: top}
nav a {padding: 7px 10px; text-decoration: none; color: rgba(255,255,255,0.9); background: rgba(0,0,0,0); border-radius: 5px; font-weight: 300; text-transform: uppercase; letter-spacing: 1.5px; font-size: 13px}
nav a:hover {background: rgba(0,0,0,0.25)}
.activeNav {background: rgba(0,0,0,0.25)}
nav ul li ul {position: absolute; display: block; margin-top: 5px; border-radius: 5px; border-top-left-radius: 0; background: none; padding-top: 5px}
nav ul li ul li {display: block; float: none; margin: 0; padding: 0}
nav ul li ul li a {display: block; text-align: left; color: rgba(255,255,255,0.9); text-shadow: 0 1px rgba(0,0,0,0.33); padding: 10px}
nav ul li ul li a:hover {background: rgba(20,150,220,0.5); color: white; text-shadow: 0 1px rgba(0,0,0,0.5)}
.hover a {display: block;}
.hover span { color: rgba(255,255,255,0.9); background: rgba(20,150,220,0.5); border-radius: 5px; position: absolute; display: block; margin: 5px 0 0 -57px; padding: 10px; font-size: 13px; font-weight: 300; letter-spacing: 1.5px; text-transform: uppercase; text-align: center; cursor: default;}
nav{
text-align:right;
position:relative;
}
nav ul li {
border: 1px solid;
display: inline-block;
margin-left: 5px;
margin-right: -4px;
position: relative;
z-index: 1000;
}
Give float right property to your nav in css:
nav {
margin: 20px auto;
float: right;
}
This will keep the news div below and would float right
nav {
float: right;
margin: 20px auto;
width: 100%;
}
nav ul {
float: right;
}
Result
Try adding float:right to either your nav css rule or your nav ul css rule, just did it in the console and it worked fine for me