I am new to web design and I have created simple menu using HTML + CSS and you can see coding below. When I test this in web browser, there is a unexpected margin / empty space on left (green clour circle in screenshot) when I hovering over on the first list item (menu item).
I would appreciate if someone can describe the reason and tell me how to get rid of this issue. Thanks in advance.
Please click this link to see the screenshot
http://screenshot.net/zvjw4in
HTML:
<div id="nav">
<ul class="menuUl">
<li>Home</li>
<li>Youtube</li>
<li>facebook</li>
<li>Map</li>
<li>Lets Connect</li>
</ul>
</div><!--nav-->
CSS:
#nav {
height:50px;
width:700px;
background-color:rgba(0,0,0,0.5);
margin-left:auto;
margin-right:auto;
}
.menuUl {
list-style-type:none;
}
.menuUl li {
width:132px;
height:42px;
float:left;
text-align:center;
font-size:24px;
color:rgba(255,255,255,1);
padding-top:8px;
}
.menuUl li:hover {
background-color:rgba(0,51,255,1);
}
The ul has a default padding.. remove it with padding:0;
#nav {
height: 50px;
width: 700px;
background-color: rgba(0, 0, 0, 0.5);
margin-left: auto;
margin-right: auto;
}
.menuUl {
list-style-type: none;
padding:0;
}
.menuUl li {
width: 132px;
height: 42px;
float: left;
text-align: center;
font-size: 24px;
color: rgba(255, 255, 255, 1);
padding-top: 8px;
}
.menuUl li:hover {
background-color: rgba(0, 51, 255, 1);
}
<div id="nav">
<ul class="menuUl">
<a href="index.html">
<li>Home</li>
</a>
<a href="Youtube.html">
<li>Youtube</li>
</a>
<a href="facebook.html">
<li>facebook</li>
</a>
<a href="map.html">
<li>Map</li>
</a>
<a href="contactus.html">
<li>Lets Connect</li>
</a>
</ul>
</div>
<!--nav-->
Related
When I hover a Media, E-sport, Community I want to see <li> under them. I get it with the rgb opacity. But it's a pity that when I hover AN <li> element which is opacity 0 it appears. I only want to do it when I hover ol li a. Someone know's the answer?
Here's my code (Menu with lists)
.Menu ol {
display: inline-block;
padding: 0;
margin: 0;
line-height: 1;
}
.Menu ol>li>ul>li>a {
margin-left: 0;
padding: 0;
}
.Menu ol>li {
float: left;
padding: 0;
list-style-type: none;
}
.Menu ol>li>ul>li>a {
color: rgba(55, 255, 255, 0);
transition: .5s ease-in-out;
}
.Menu ol>li:hover>ul>li>a {
color: rgba(55, 255, 255, 1);
transition: .5s ease-in-out;
background-color: rgb(0, 0, 205, 1);
}
.Menu ol>li>ul>li {
clear: both;
margin-left: 90px;
}
.Menu ol>li>ul>li {
clear: both;
margin: 0;
list-style-type: none;
padding: 0;
}
.Menu ol>li>ul>li>a {
padding-left: 0;
margin: 0;
}
Article {
width: 1920px;
height: 957px;
}
<div class="Menu">
<ol>
<li>Media
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
<li>E-sport
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
<li>Community
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
</ol>
</div>
To be honest I find the whole ".Menu ol>li:hover>ul>li>a.. " and so on pure madness, its messy and unclear, much better effects you will get when using pure divs and classes, also use display: none, so it actually takes away the elements unless you set it to something, here is the code:
Edited: Use opacity: 0 and overflow: hidden, it works with transtition
Edit2: Actually simple height: 0 + overflow hidden will give you nice transtition in AND out, it got to have fixed height on hover thou.
<div class="Menu">
<div class="Menu-item-container">
Media
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
<div class="Menu-item-container">
E-sport
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
<div class="Menu-item-container">
Community
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
</div>
<style>
.Menu {
display: flex;
justify-content: space-around;
width: 300px;
}
a {
text-decoration: none;
}
.hover-items {
transition: .5s ease-in-out;
height: 0;
overflow: hidden;
}
.Menu-item-container {
width: 100px;
text-align: center;
}
.Menu-item-container:hover .hover-items{
height: 100px;
}
</style>
Codepen: https://codepen.io/Raitar/pen/QOZgoV?editors=1100
Dude i'm sorry but your code is madness. why combine ol and ul.
here i give you free mine :
body{
width:100%;
height:100%;
margin:0;
}
ul{
list-style:none;
padding:0;
}
a{
text-decoration:none;
}
.menu {
width:100%;
height: 33px;
background: #000;
position:relative;
}
.menu ul:not(.sub-menu):not(.micro){
margin:auto;
display:flex;
}
.menu ul li{
position:relative;
flex:1;
}
.menu a{
text-align:center;
display:block;
line-height: 33px;
margin-right: 40px;
color:#fff;
padding: 0 15px;
}
.sub-menu{
width:100%;
display:none;
position: absolute;
transform:translateY(0);
background: #ccc;
transition: all 300ms;
z-index:2;
}
.sub-menu a{
margin:10px 0;
}
.micro{
top:-10px;
width:100%;
opacity:0;
transform: translate(100%, 0);
position: absolute;
background: orangered;
z-index:1;
transition: all 300ms;
}
.micro a{
color:#fff;
}
.menu ul li a:hover + ul.sub-menu {
display:block;
}
.sub-menu:hover{
transform:translateY(5%);
display:block;
}
.sub-menu a:hover + ul.micro {
opacity:1;
}
.micro:hover{
opacity:1;
}
<div class="menu">
<ul>
<li>MEDIA
<ul class="sub-menu">
<li>FACEBOOK
<ul class="micro">
<li>TWITTER</li>
<li>TWITTER</li>
<li>TWITTER</li>
</ul>
</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
<li>E-SPORT
<ul class="sub-menu">
<li>FACEBOOK</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
<li>COMMUNITY
<ul class="sub-menu">
<li>FACEBOOK</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
</ul>
</div>
i was wondering if any of you could help me out, i have started to create a drop down menu for my blog it was going well in my perspective until i realized that the dropdown menu would disapear once i hovered over it with my cursor, the link is fine, but when i hover my cursor over the dropdown menu it disappears.
Source Code:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Yeti™</title>
<link rel="stylesheet" href="main.css" />
<style type="text/css">
body
{
background-image:url(img.jpg);
background-repeat:no-repeat;
}
a:link{color:yellow;
text-decoration:none;}
a:visited{color:yellow;}
a:hover{background-color:none;
color:green;
text-decoration:bold;
text-decoration:underline;
font-weight:bold;}
#footer {position: absolute;
width: 1500px;
height: 80px;
bottom: 1px;
left: 0px;}
#main {position: absolute;
width: 600px;
height: 200px;
top: 160px;
left: 0px;}
</style>
</head>
<ul id="nav">
<div id="Title">
<p> Yeti Corporation™ </p>
--------------------------------------------------> ( This is the drop down menu )--------
<div id="wrapper">
<div id="navMenu">
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
--------------------------------------------------> ( This is the drop down menu )--------
</div>
<body>
<div id="video">
<video src="csgo.mp4" width="540" height="380" poster="csgo.jpg" controls></video>
</div>
<div id="main">
<div id="yeti">
<p> <div id="play">
</div></P>
</div>
<p>There is never enough to what you can do with programming</p>
<p> a Small Indie Development company Consisting of 4 people that works on Video games and Websites, as well as many other project we hope to get to in the future. Originally we where two separate companies, but when we realised the potential we had together we decided to merge to create Yeti Corp™.
If you are interested in Hiring a web developer go to the web development page. If you want to check up on the newest games and software updates, go to the game development page. a Small Indie Development company Consisting of 4 people that works on Video games and Websites, as well as many other project we hope to get to in the future. Originally we where two separate companies, but when we realised the potential we had together we decided to merge to create Yeti Corp™.
If you are interested in Hiring a web developer go to the web development page. If you want to check up on the newest games and software updates, go to the game development page. </p>
</div>
</div>
<div id="footer">
<a href="#" />Contact Us|</a>
<a href="#" />Web Dev|</a>
<a href="#" />Game Dev|</a>
<a href="#" />Graphic Designer|</a>
<a href="#" />Twitter Page|</a>
<a href="#" />FaceBook Page|</a>
<a href="#" />Gmail Page</a>
<p> All Rights Reserver Yeti LTD. 2014 Created by Head Web Developer, Hamza Issa</P>
</div>
</body>
</html>
CSS:
#body{
background: white;
}
#wrapper{
font:20px Tahoma;
}
--------------------------------------------------> ( This is the drop down menu )--------
#navMenu{
margin:0;
padding:30;
}
#navMenu ul {
margin:0;
padding:0;
line-height:30px;
}
#navMenu li {
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
background:#999;
}
#navMenu li ul a {
text-align:center;
text-decoration:none;
font:20px Tahoma;
height:30px;
width:130px;
display:block;
color: blue;
border:1px solid black;
}
#navMenu ul ul {
position:absolute;
visibility:hidden;
top:30px;
}
#navMenu ul li:hover ul {
display: block;
visibility:visible;
display: block;
}
--------------------------------------------------> ( This is the drop down menu )--------
#Title{
font: 30px Candara;
-webkit-box-shadow:rgba(110,110,110,.4) 10px 10px 10px;
padding-top: 5px;
padding-left: 100px;
color: orange;
}
#Search{
margin-left: 200px;
padding-bottom: 10px;
}
#Links{
padding-left: 400px;
font: bold 20px Tahoma;
padding-bottom: 30px;
}
#Links a:hover{
color: green;
}
#sign{
color: white;
font:20px Tahoma ;
padding-right: 100px;
padding-top: px;
}
#Sign_up{
padding-left: 400px;
padding-bottom: 200px;
}
#main{
font: 14px Courier ;
color: white;
width: 650px;
padding-left: 100px;
}
#yeti{
font: 45px Candara ;
}
#footer{
background: #E6EAEE;
color: black;
font: 20px impact;
text-align: center;
padding-bottom: 20px;
padding-right: 60px;
width: 1300px;
}
#video{
padding-left: 850px;
padding-top: 50px;
}
So I made a simplified version of your code (In the future you should do this first) and was able to narrow down the problem. The positioning of your #main section is messing with the drop downs and it appears on top of them. So the simple thing I did was add z-index to the drop downs
#navMenu ul li ul {
position:absolute;
visibility:hidden;
top:30px;
z-index: 1;
}
#navMenu ul li:hover ul {
// display: block;
visibility:visible;
// display: block;
}
a:link {
color:yellow;
text-decoration:none;
padding: 10px;
}
a:visited {
color:yellow;
}
a:hover {
background-color:none;
color:green;
text-decoration:bold;
text-decoration:underline;
font-weight:bold;
}
#Title {
font: 30px Candara;
-webkit-box-shadow:rgba(110, 110, 110, .4) 10px 10px 10px;
padding-top: 5px;
padding-left: 100px;
color: orange;
}
#wrapper {
font:20px Tahoma;
}
#navMenu {
margin:0;
padding:30;
}
#navMenu ul {
margin:0;
padding:0;
line-height:30px;
}
#navMenu li {
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
background:#999;
}
#navMenu li ul a {
text-align:center;
text-decoration:none;
font:20px Tahoma;
height:30px;
width:130px;
display:block;
color: blue;
border:1px solid black;
}
#navMenu ul li ul {
position:absolute;
visibility:hidden;
top:30px;
z-index: 1;
}
#navMenu ul li:hover ul {
visibility:visible;
}
#main {
font: 14px Courier;
color: red;
padding-left: 100px;
position: absolute;
width: 600px;
height: 200px;
top: 160px;
left: 0px;
}
<div id="Title">
<p>Yeti Corporation™</p>
<div id="wrapper">
<div id="navMenu">
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
<ul>
<li>top
<ul>
<li>Recipes</li>
<li>Recipes</li>
<li>Recipes</li>
</ul>
</li>
</ul>
</div>
<div id="main">
<p>There is never enough to what you can do with programming</p>
</div>
</div>
</div>
This is a double part fragment of dropdown menu with double part the issue is that I cannot make the two div be aside each other unless I use the div width to any ration.
the CSS code what I want is a method to display the two div below aside each other without using the width property in the html code.
.navbar ul li a{
text-decoration: none;
color: black;
padding: 16.2px;
display: block;
}
.navbar{
width: 100%;
height: 50px;
position: relative;
margin: 0;
padding: 0;
background-color: #c7ffff;
border:1px solid black;
}
.dropnavbar{
position: absolute;
margin: 0;
padding: 0;
height: 60px;/*can be negliacted if the default is auto*/
}
.active{
float: left;
text-align: center;
list-style: none;
width: 100px;
font-size: 15px;
}
.subnavbar{
display:none;
padding: 0;/*if forgotten the size of the dropdown nav will be greater than it's parrent*/
margin: 0;
}
.navbar li:hover .subnavbar{
display: block;
}
.navbar li:hover li,.navbar li:hover{
background-color:#e0ffff;
}
.subnavbar>li>a:hover{
background-color: aqua;
}
.subnavbar>li:nth-child(n+2){
border-top: 1px solid black;
}
<!DOCTYPE html>
<html>
<head>
<link href="navbar.css" rel="stylesheet">
<title>DropDown NavBar Trial 3</title>
</head>
<body>
<header>
<div class="navbar">
<ul class="dropnavbar">
<li class="active">About
</li>
<li class="active">Branches
<ul class="subnavbar">
<li class="active">Egypt
</li>
<li class="active">USA
</li>
<li class="active">UAE
</li>
<li class="active">France
</li>
</ul>
</li>
<li class="active">Categories
<div style="width:auto;">
<div style="float:left; width:10%;">
<ul class="subnavbar">
<li class="active">Books
</li>
<li class="active">Electronic Devices
</li>
<li class="active">House Gadgets
</li>
<li class="active">Sport Equipments
</li>
</ul>
</div>
<div style="float:right;width:10%;">
<ul class="subnavbar">
<li class="active">Books
</li>
<li class="active">Electronic Devices
</li>
<li class="active">House Gadgets
</li>
<li class="active">Sport Equipments
</li>
</ul>
</div>
</div>
</li>
<li class="active">Paying
</li>
</ul>
</div>
</header>
</body>
</html>
I hope this example will help you out!!!!
* {
margin:0;
padding:0;
}
#nav {
list-style:none;
height:2em;
}
#nav li {
position:relative;
float:left;
width:192px;
background:#999;
text-align:center;
}
#nav li:hover {
background:#777;
}
#nav a {
display:block;
color:#000;
text-decoration:none;
line-height:2em;
}
/* --------- Drop Down -------- */
#nav ul {
position:absolute;
left:-999em;
top:2em;
list-style:none;
}
#nav li:hover ul {
left:0;
top:auto;
}
<ul id="nav">
<li>Link1</li>
<li>Link2
<ul>
<li>Drop1</li>
<li>Drop2</li>
<li>Drop3</li>
</ul>
</li>
<li>Link3</li>
</ul>
i created a navigation bar, and while hovering i made the font larger.
but when i hover the other menu items seem to move from its position , how do i lock them in their position. Also, just started html and css, if anyone would help me, thank you :)
html:
<div class="header">
<div class="container">
<div class="header-left">
<a href="index.php">
<img src="images/hawa.png" style="width:200px;height:60px;">
</a></div>
<div class="header-right">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact Us</li>
<li>Sign Up</li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
CSS:
.header{
background-color: #003399;
width: 100%;
height: 83px;
position: fixed;
}
.container{
width:1200px;
background-color:#003399;
margin:auto;
height:83px;
}
.header-left{
float:left;
padding: 10px;
}
.header-right{
float:right;
width:900px;
height:83px;
}
.header-right ul{
margin: 0;
padding: 0;
}
.header-right li{
list-style: none;
}
.header-right li a{
text-decoration: none;
float:left;
display: block;
padding: 35px;
color:#FFFFFF;
text-transform: uppercase;
font-size: 18px;
font-family: sans-serif;
}
.header-right li a:hover{
font-size: 20px;
display: block;
}
You can add a class on your list items and set the width for these items. For example:
html:
<ul>
<li class="nav-cells">Home</li>
<li class="nav-cells">About</li>
<li class="nav-cells">Services</li>
<li class="nav-cells">Contact Us</li>
<li class="nav-cells">Sign Up</li>
</ul>
css:
.nav-cells {
width: 100px;
display: inline;
}
Screenshot of the header that's needing this work:
As you can see, the menu is below the logo. I was wanting the menu beside it, to the right of the logo. I don't know if it's possible, but if it is, I could use some help, please.
Here's the code for everything, separated for your convenience.
The menu and logo in their divs:
<div id="wrapper">
<div id="body-wrapper">
<div class="head">
<div class="head-wrapper">
<div class="logo">
<img src="http://i.imgur.com/sDnntOE.png">
<ul>
<li>Home</li>
<li>About Us
<ul>
<li>The Team</li>
<li>History</li>
</ul>
</li>
<li>Products
<ul>
<li>Chaotix Browser</li>
<li>Useful Beta 1.7.5</li>
<li>Chaotix Cleaner 1.4</li>
<li>Forum</li>
<li>CDev</li>
<li>Infinite-PVP</li>
<li>Ulta-Craft</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>E-Mail</li>
<li>News Letter</li>
<li>Social Mediar</li>
</ul>
</li>
<li>Divisions
<ul>
<li>Gaming</li>
<li>Films</li>
</ul>
</li>
<li>Chaotix! Forum</li>
<li>Partnerships
<ul>
<li>GameFanShop</li>
<li>Forumotion</li>
</ul>
</li>
</ul>
The CSS:
<style>
*{
background-image:url('http://i.imgur.com/0u7sBsT.png');
background-color:#999999;
font-family:Tahoma;color:white;
}
div.head{
text-align:Center;
padding-top:10px;
}
div.body{
padding-top:100px;
padding-left:300px;
padding-right:300px;
text-align:center;
}
div.logo{
float:left;
}
a{
color:white;
}
a:hover{
color:gray;
}
/* Main menu
------------------------------------------*/
ul{
font-family: Lato,Tahoma,Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
padding-left:25px;
}
ul li{
display: block;
position: relative;
float: left;
}
li ul{
display: none;
}
ul li a{
display: block;
text-decoration: none;
color: #FFFFFF;
border-top: 1px solid #000000;
padding: 5px 15px 5px 15px;
background: #000000;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover{
background: #999999;
}
li:hover ul{
display: block;
position: absolute;
}
li:hover li{
float: none;
font-size: 11px;
}
li:hover a{
background: #000000;
}
li:hover li a:hover{
background: #999999;
}
</style>
Add your css
.logo img
{
float:left;
}
.logo ul
{
float:left;
}
It working ok. Hope this help!