List hovering messing with the whole nav div - hover

im very very new to coding, like days in and theres this problem thats been driving me crazy.
Whenever i hover links or anything for some reason the whole parent of that list or other elements of the list kinda like twitch and change positions. Either way what can i do to make it so when i hover one element doesnt effect other elements.
<nav id="firstnav">
<ul class="firstList">
<li Purple Buzz</li>
<li Home</li>
<li About</li>
<li Work</li>
<li Pricing</li>
<li Contact</li>
</ul>
</nav>
#firstnav{
width: 100%;
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.firstList{
list-style: none;
display: inline-flex;
}
.firstList{
margin-left: 35%;
}
li{
margin-right: 30px;
margin-left: 30px;
}
li:hover{
border: solid 1px purple;
border-radius: 80px;
padding: 10px;
}

First: you forgot the closing rafter > of the li.
The problem is the padding and the border added on hover.
The padding and hover change the initial size of your html element which causes the other elements to shift and the parent to grow in your case. To fix this, you can already set the padding initially. the border you set with a transparent color. then on hover, you simply change the color of the border.
like here below.
#firstnav{
width: 100%;
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.firstList{
list-style: none;
display: inline-flex;
}
.firstList{
margin-left: 35%;
}
li{
margin-right: 30px;
margin-left: 30px;
padding: 10px;
border: solid 1px transparent;
}
li:hover{
border-color: purple;
border-radius: 80px;
}
<nav id="firstnav">
<ul class="firstList">
<li> Purple Buzz</li>
<li> Home</li>
<li> About</li>
<li> Work</li>
<li> Pricing</li>
<li> Contact</li>
</ul>
</nav>

Related

Vote I want the rectangular less wide

Please check the below link to check the code in HTML and CSS and check the result. Please, I need the rectangular in the result to be less wide.
https://jsfiddle.net/Ahmed_abdelmeguid/6L8vbutw/5/
[enter image description here][1]
this is CSS code
.tictac_3 > ul {
width: 50%;
height: 20px;
display: flex;
flex-wrap: wrap;}
.tictac_3 > li {
width: 30%;
height: 30px;
font-size: 30px;
font-family: sans-serif;
background-color:lightblue;
margin: 5px;
list-style: none;
text-align: center;
float: left;
}
and below the HTML code
<ul class="tictac_3">
<li class=".tictac_3">X
<li class=".tictac_3">
<li class=".tictac_3">O
<li class=".tictac_3">
<li class=".tictac_3">X
<li class=".tictac_3">O
<li class=".tictac_3">X
<li class=".tictac_3">O
<li class=".tictac_3">
</ul>
you can check the code and the result that I want to modify it in the below link That I provided it in the start of my question
https://jsfiddle.net/Ahmed_abdelmeguid/6L8vbutw/5/
Problems
"Please, I need the rectangular in the result to be less wide"
OK, there are some problems with OP code that are at fundamental level:
Every <li> end tag </li> is missing
The selector: .tictac_3 > ul does not exist
height: 20px is assigned to the previously mentioned selector. If it referenced the <ul> as was intended, it would make very little sense since all of it's <li> are height: 30px
Changes
All of the classes on the <li> is removed, a single class on the <ul> is sufficient.
Added max-width: 12rem; to the <ul>
Each <li>
Changed height from an absolute value 30px to a relative value 2rem.
Changed font-size exactly as height was changed.
Decreased the margin from 5px to 1px
Added a little padding-bottom: 0.25em
.tictac {
display: flex;
flex-flow: row wrap;
width: 50%;
max-width: 12rem;
list-style: none;
}
.tictac li {
width: 30%;
height: 2rem;
font-size: 2rem;
font-family: sans-serif;
text-align: center;
margin: 1px;
padding-bottom: 0.1em;
background-color: lightblue;
}
<ul class="tictac">
<li>X</li>
<li></li>
<li>O</li>
<li></li>
<li>X</li>
<li>O</li>
<li>X</li>
<li>O</li>
<li></li>
</ul>

How do I get the navigation bar to span the width of the page?

I have looked a few questions so far that are very similar to this one, but still can't find the answer to my question. (Please note that I am new to HTML and that this is my first post).
I want to have a navigation bar that spans the width of the page no matter the width of the screen that it is being viewed on. I tried making the 's width 100%, but it still did not do anything.
The code for the navigations bar is here:
<!DOCTYPE html>
<html>
<head>
<style>
nav {
width: 100%;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
a {
display: block;
width: 60px;
background-color: #dddddd;
border-color: #ffffff;
text-align: center;
text-decoration: none;
padding: 10px;
margin: 3px;
border-radius: 4px;
}
a:hover {
font-weight: bold;
background-color: #9b9b9b;
}
a:active {
color: #ff0000;
}
</style>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</nav>
</body>
</html>
Can you please help me to find a way to make the navigation bar span the width of the page?
Thanks!
If you want to expand the li to be the same size and fill the width of the ul, flexbox can do that.
Modern Browsers - Flexbox
nav {
width: 100%;
background: #333;
margin-bottom: 1em;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
display: flex;
}
li {
flex:1 0 auto;
}
a {
display: block;
/*width: 60px;*/
background-color: #dddddd;
border-color: #ffffff;
text-align: center;
text-decoration: none;
padding:10px 0;
margin: 3px;
border-radius: 4px;
}
a:hover {
font-weight: bold;
background-color: #9b9b9b;
}
a:active {
color: #ff0000;
}
<nav>
<ul>
<li>Home
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
</ul>
</nav>
<nav>
<ul>
<li>Home
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
<li>Home
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
</ul>
</nav>
Alternative Solution: Old Browsers - CSS Tables
nav {
width: 100%;
background: #333;
margin-bottom: 1em;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
display: table;
width: 100%;
table-layout: fixed;
}
li {
display: table-cell;
}
a {
display: block;
/*width: 60px;*/
background-color: #dddddd;
border-color: #ffffff;
text-align: center;
text-decoration: none;
padding: 10px;
margin: 3px;
border-radius: 4px;
}
a:hover {
font-weight: bold;
background-color: #9b9b9b;
}
a:active {
color: #ff0000;
}
<nav>
<ul>
<li>Home
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
</ul>
</nav>
<nav>
<ul>
<li>Home
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
<li>Home
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
</ul>
</nav>
You have already given your nav a width of 100%. Now try adding a width to your LI element in your CSS to evenly distribute them across the 100% width of the nav.
li {
float: left;
width:25%;
}
nav is already 100% width,with this css configuration.Give it some background you will be able to see it.
So right how, the navigation bar is spanning the width of the page, however the objects inside aren't large enough to fill the gap. This can be seen if you add a background color to the navigation bar. What you might consider is center-aligning the objects within the nav bar or expanding the width of each object to near 25%
Are you trying to make the nav tag expand from window edge to window edge?
If so you will want to remove the margin on your body:
body {
margin: 0;
}

Stretch a sub nav bar across the width of the page on hover

I have a navigation menu on a wordpress website with a sub menu on certain elements.
<nav>
<div class="nav_container">
<ul id="menu-header-menu" class="menu">
<li id="menu-item-36" class="menu-item menu-item-type-post_type menu-item-object-page current-page-ancestor current-menu-ancestor current-menu-parent current-page-parent current_page_parent current_page_ancestor menu-item-has-children menu-item-36">
Cottages
<div id="sub_menu_container">
<ul class="sub-menu">
<li id="menu-item-51" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-46 current_page_item menu-item-51">
Cottage 1
</li>
<li id="menu-item-50" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-50">
Cottage 2
</li>
</ul>
</div>
</li>
...more li elements etc
</ul>
</div>
</nav>
The menu elements are centred on the page, but the background of the nav stretches across the page width.
The problem I am having is the design of the nav is such that the sub menu elements appear directly under the first nav, with the menu elements directly under the parent menu element, but with the background also stretching across the width of the page.
Given that I am using relative and absolute positions and given that the main menu elements are centred on the page, while their background stretches across the width of the page (i do this using a div with a certain width) the sub menu, when it has a width of 100% is only ever the width of the div that is centring the main menu elements.
It's probably also worth saying that I managed to achieve the desired look without using position relative and absolute but it meant the sub menu was not 'attached' to the main menu and the mouse left the hover area when trying to reach the sub menu, which then disappeared, so it couldn't be reached before it disappeared.
I have attached an image of what I am after to make it more clear and I also attach below the current css I have.
.nav_container
{
margin-left: auto;
margin-right: auto;
padding-top: 10px;
width: 1055px;
}
nav
{
width: 100%;
height: 40px;
background: #685c53;
-moz-box-shadow: inset 0 0 3px 3px #37332e;
-webkit-box-shadow: inset 0 0 3px 3px #37332e;
box-shadow: inset 0 0 3px 3px #37332e;
position: relative;
}
nav ul
{
margin: 0;
padding: 0;
display: inline;
}
nav li
{
display: inline;
padding: 8px 9px;
}
#sub_menu_container
{
display: none;
float: left;
position: absolute;
top: 0;
padding-top: 40px;
width: 100%;
}
nav ul .sub-menu
{
text-align: center;
width: 100%;
height: 30px;
background: #b3a797;
-moz-box-shadow: inset 0 0 3px 3px #685c53;
-webkit-box-shadow: inset 0 0 3px 3px #685c53;
box-shadow: inset 0 0 3px 3px #685c53;
}
nav ul li:hover > #sub_menu_container
{
display: block;
}
.sub-menu li
{
display: inline-block;
margin-top: 0px;
padding-bottom: 2px;
margin-bottom: 0px;
padding-top: 5px;
padding-left: 10px;
border-right: 1px solid #000;
}
Update
Having changed my css to:
I then get back to the original problem, in that the background highlights my problem that the sub menu must be 'attached' to the element from which you mouse hover over so you can move your mouse from the main menu to the sub menu without the menu disappearing.
make the following changes. I think this is what you were looking for.
#sub_menu_container
{
display: none;
float: left;
position: absolute;
top:;
left:0px;
padding-top: 10px;
width: 100%;
background-color:black;/*this is for testing purposes*/
}
please comment for further info or telling me if this is what you wanted. Hope it helps Pippa Rose Smith. thanks
I believe having the unordered list and the sub-menu container equal rather than one nested in the other would simplify things. Here's a full example of how I would do it, note #sub.
<nav>
<ul>
<li>Cheeses
<div id='sub'></div>
<ul>
<li>Opt1</li>
<li>Opt2</li>
<li>Opt3</li>
</ul>
</li>
<li>Paper clips
<div id='sub'></div>
<ul>
<li>Opt1</li>
<li>Opt2</li>
<li>Opt3</li>
</ul>
</li>
<li>Swords
<div id='sub'></div>
<ul>
<li>Opt1</li>
<li>Opt2</li>
<li>Opt3</li>
</ul>
</li>
</ul>
</nav>
*{
margin:0px;
padding:0px;
}
nav{
background:green;
}
ul{
display:flex;
}
li{
display:inline;
margin:auto;
}
li>ul{
display:none;
position:absolute;
}
li:hover>ul{
display:inline;
}
#sub{
background:blue;
display:none;
height:1.5em;
left:0px;
position:absolute;
width:100vw;
}
li:hover>#sub{
display:block;
}
try this...
.sub-menu li
{
display: inline-block;
margin-top: 0px;
padding-bottom: 0px;
margin-bottom: 0px;
padding-top: 0px;
padding-left: 10px;
border-right: 1px solid #000;
}
Please comment back if this is not what you would like. Check fiddle at http://jsfiddle.net/gq2fM/

CSS border bottom has missing corners

I would like to have a long border underneath my menu UL, but the "border-bottom" property on the list items does not work well:
#headermenu {
height: 40px;
background: #f47a20;
position: relative;
}
#headermenu .menu {
background: #F47B20;
float: left;
border: 1px solid #D66C1C;
padding: 0.6em 1em;
margin-top: 0.5em;
list-style-type: none;
}
#headermenu-left {
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 70%;
margin: 0;
}
#headermenu-left .menu {
border-bottom: 4px solid #004B8D;
}
<body>
<div id="headermenu">
<ul id="headermenu-left">
<li class="menu">
Link 1
</li>
<li class="menu">
Link 2
</li>
<li class="menu">
Link 3
</li>
<li class="menu">
Link 4
</li>
<li class="menu">
Link 5
</li>
<li class="menu">
Link 6
</li>
</ul>
</div>
</body>
The border is interrupted at the corners by -I guess- the border-left and border-right properties not being there?
I can't put it on the <ul> element, because then the line runs too long.
You can put it on the UL if you get rid of the width on it. Remove your last rule and use this:
#headermenu {
height: 40px;
background: #f47a20;
position: relative;
}
#headermenu .menu {
background: #F47B20;
float: left;
border: 1px solid #D66C1C;
padding: 0.6em 1em;
margin-top: 0.5em;
list-style-type: none;
}
#headermenu-left {
padding: 0;
position: absolute;
top: 0;
left: 0;
margin: 0;
border-bottom: 4px solid #004B8D;
}
<body>
<div id="headermenu">
<ul id="headermenu-left">
<li class="menu">
Link 1
</li>
<li class="menu">
Link 2
</li>
<li class="menu">
Link 3
</li>
<li class="menu">
Link 4
</li>
<li class="menu">
Link 5
</li>
<li class="menu">
Link 6
</li>
</ul>
</div>
</body>
The problem, as you suggest, is the missing left and right borders, which have a width, but no color, so this distorts the appearance of the bottom border with the illusion of a missing notch.
To solve this you can simply define border-width: 0 for the element, and allow the border-bottom property to override that setting.
#headermenu {
height: 40px;
background: #f47a20;
position: relative;
}
#headermenu .menu {
background: #F47B20;
float: left;
border: 1px solid #D66C1C;
padding: 0.6em 1em;
margin-top: 0.5em;
list-style-type: none;
}
#headermenu-left {
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 70%;
margin: 0;
}
#headermenu-left .menu {
border-width: 0;
border-bottom: 4px solid #004B8D;
}
<body>
<div id="headermenu">
<ul id="headermenu-left">
<li class="menu">
Link 1
</li>
<li class="menu">
Link 2
</li>
<li class="menu">
Link 3
</li>
<li class="menu">
Link 4
</li>
<li class="menu">
Link 5
</li>
<li class="menu">
Link 6
</li>
</ul>
</div>
</body>
Unfortunately this is how borders work. Those are the ends of your border-left, and border-right. Here's a work around though, I added a div to the bottom of your list:
(I also removed your width:70%; from your list)
#bluebar {
position:absolute;
bottom:0px;
width:100%;
height:5px;
background-color:blue;
}
http://jsfiddle.net/BjGvp/6/

CSS floating text Bar

I have this HTML code:
<div id="navbar">
<ul>
<li>Home</li>
<li>Forum</li>
<li>Contact Us</li>
</ul>
</div>
CSS:
#navbar { position: relative; margin: 3px; }
#navbar ul { padding: 0; margin: auto; background: #f0f0f0 url(../images/1px.png) repeat-x 0 -441px; padding: 4px 0 4px 0; }
#navbar li { display: inline; margin-right: 80px; }
#navbar li a { font-family: EqualSansDemo; font-size: 1.6em; color: #555555; text-shadow: 1px 1px 0px #fff; }
#navbar li a:hover { color: #0071e4; }
And it's will be like that:
All I need to do is:
I really tried many of things and waste three hours without any success... I think it's easy but I'm not good with CSS. Any idea please?
What you want is a Suckerfish Dropdown what you'll have to do is this:
<ul>
<li>Home</li>
<li>Forum
<ul class="children">
<li>Some link</li>
<li>Another link</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
By default of course the children shouldn't be shown so add in your CSS:
.children{display:none;}
And when the forum element is hovered you should show them, so:
li:hover .children{display:block;}
Of course you'll need to add some position styling so they're nicely below the forum element and don't break your design. So make sure you take the children class out of the flow with position:absolute;
You can read more about suckerfish dropdowns here: http://alistapart.com/article/dropdowns