I have this HTML code
<div id="navbar">
<ul>
<li>Page1</li>
<li>page2</li>
<li id="NavItem">
page3
<div id="PopOver">
<div class="ow-button">
xnewPage1
xnewPage2
xnewPage3
</div>
</div>
</li>
<li>page4</li>
</ul>
</div>
CSS code
#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; }
#PopOver {
position:absolute;
border:2px solid #07B1F1;
width:170px;
height:auto;
padding:15px 5px 10px 5px;
display:none;
top:30px;
left:229px;
background-color:#FFFFFF;
border-radius:8px;
-moz-border-radius:8px;
-webkit-border-radius:8px;
}
#NavItem:hover #PopOver {display:block}
.ow-button a {
display: block;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
width: 160px;
height: 28px;
font-family: Arial, "Nimbus Sans L", "FreeSans";
font-size: 14px;
font-weight: bold;
color: #FFFFFF;
text-align: center;
line-height: 28px;
text-shadow: 1px 1px 1px #6A6A6A;
text-decoration:none;
margin: 0px 5px 10px 5px;
background: #28A9FF;
}
.ow-button a:hover {
background: #48B6FF;
}
The problem:
"#navbar li a" will hide:
font-family: Arial, "Nimbus Sans L", "FreeSans";
font-size: 14px;
color: #FFFFFF;
text-shadow: 1px 1px 1px #6A6A6A;
Which "ow-button a" have..and will enable its own.
And I don't want that... How do I enable the full "ow-button a" CSS code?
The quick and dirty solution is to add !important to your ow-button a which will override #navbar li a.
The better solution is to use better scoped CSS. Use selectors like > to specify exactly the element you want to. In your case, it should look like this:
#navbar > ul > li > a
I made a jsFiddle for you: http://jsfiddle.net/6NrWF/.
Related
I need to make the following dropdown menu:
CSS dropdown menu SOLUTION.
My code just doesn't do the job right:
My (wrong) SOLUTION
My code at the moment:
.parent-menu li {
display: block;
text-transform: uppercase;
border-bottom:none;
border-top:none;
padding:10px;
border-right:none;
}
.sub-menu-caption, .upper-menu{
border:1px solid red;
}
.parent-menu{
width:100%;
}
.sub-menu {
font-style: italic;
display: none;
width:170px;
height:90px;
position:absolute;
background:black;
margin:10px 0 0 -11px;
font-size:1em;
}
.sub-menu li{
border-bottom:1px solid red;
z-index: 1;
}
.sub-menu li:last-child {
border-bottom: none;
}
.sub-menu-caption{
left:auto;
right:auto;
text-align:center;
}
.sub-menu-caption:hover .sub-menu {
display: block;
border:solid red 1px;
border-top:none;
padding-bottom:5%;
}
<nav id="main-menu" class="section">
<ul class="parent-menu">
<li class="sub-menu-caption">Automobiles
<ul class="sub-menu">
<li>812 Superfast</li>
<li>GTC4Lusso</li>
<li>488 GTB</li>
<li>488 Spider</li>
</ul>
</li>
<li class="upper-menu">services</li>
<li class="upper-menu">pre-owned</li>
<li class="upper-menu">Find a dealer</li>
<li class="upper-menu">my ferrari</li>
</ul>
</nav>
There is an slight offset to the right with the dropdown menu and borders aren't going all the way through :(
What could be the problem? And how could i fix it? And no, i don't work for Ferrari :D
Thank you!
Nevermind. Tweaked the CSS code a bit differently and found the right solution.
.parent-menu {
overflow: hidden;
background-color: black;
}
.parent-menu > li{
padding: 10px;
padding-left: 16px;
padding-right: 16px;
float: left;
color: rgba(255,255,255,0.7);
border-right: 1px solid rgba(255,0,0,0.5);
}
.parent-menu > :first-child {
color: red;
padding-left: 18px;
padding-right: 18px;
border-left: 1px solid rgba(255,0,0,0.5);
}
.sub-menu li{
display: none;
position: absolute;
z-index:1;
}
.sub-menu {
display:block;
color: blue;
float: left;
text-align:left;
}
.sub-menu-caption:hover .sub-menu{
display: block;
position: absolute;
top: 30px;
left: 0px;
}
.sub-menu-caption:hover .sub-menu li{
display: block;
position: static;
background-color: black;
width: 100%;
border: 1px solid rgba(255,0,0,0.5);
border-top: 0;
font-style: italic;
font-size: 1em;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 3px;
}
.sub-menu-caption:hover .sub-menu :last-child{
border-radius: 0px 0px 4px 4px;
}
.sub-menu-caption:hover .sub-menu :first-child{
padding-top: 12px;
}
.sub-menu-caption:hover .sub-menu li a:hover{
color: red;
}
#main-menu {
top: 0;
text-transform: uppercase;
position: sticky;
z-index:1;
margin-bottom: 30px;
}
article {
position: relative;
width: 90%;
margin: auto;
}
article.main-container > :first-child {
font-variant: small-caps;
}
.parent-menu a:link {
text-decoration: none;
font-weight: 400;
color: rgba(255,255,255,0.7);
}
.parent-menu a:visited {
text-decoration: none;
font-weight: 400;
color: rgba(255,255,255,0.7);
}
.parent-menu a:hover {
text-decoration: underline;
font-weight: 400;
color: rgba(255,255,255,0.7);
}
.parent-menu a:active {
text-decoration: none;
font-weight: 400;
color: rgba(255,255,255,0.7);
}
li.right-menu.upper-menu {
background-color: rgba(255,0,0,0.5);
float: right;
background-clip: padding-box;
}
I'm attempting to create a navigation menu that shows a border when an item is hovered over. While it currently looks fine, the other menu items are pushed out of the way when one item is hovered over. How would I go about making them stay put?
I've tried a few methods that were answered here but none of them have worked.
I've included a fiddle below.
nav {
float: left;
width: 100%;
}
ul {
float: left;
list-style:none;
padding: 0;
position: relative;
left: 50%;
text-align: center;
}
ul li {
display: block;
float: left;
list-style: none;
position: relative;
right: 50%;
margin: 0px 0px 0px 1px;
padding: 5px 40px;
color: white;
line-height: 1.3em;
}
li a:hover {
border: solid 1px black;
padding: 5px 10px;
}
a {
color: black;
font-family: 'Quicksand', sans-serif;
text-decoration: none;
}
<nav>
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>MUSIC</li>
<li>STORE</li>
<li>LIVE</li>
<li>CONTACT</li>
</ul>
</nav>
View on JSFiddle
Because you are adding padding on hover. Move the padding from hover to anchor.
li a:hover {
border: solid 1px black;
}
a {
color: black;
font-family: 'Quicksand', sans-serif;
text-decoration: none;
border: solid 1px transparent;
padding: 5px 10px;
}
Here is the fiddle.
Move the padding property from 'li a: hover' to 'a'.
a {
color: black;
font-family: 'Quicksand', sans-serif;
text-decoration: none;
padding: 5px 10px;
}
I have a piece of code enclosed with div tags and containing some sub elements:
<div class="menu">
<ul>
<li>A hurr</li>
<li>A durr</li>
<li>A murrmurr</li>
</ul>
</div>
Now in the tutorial I am reading, in the CSS file he does:
#menu {
width: 550px;
height: 35px;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
text-align: center;
text-shadow: 3px 2px 3px #333333;
background-color: #8AD9FF;
border-radius: 8px;
}
And then:
#menu ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
To change the appearance of the ul element.
I assume that this is an older version of CSS since we now use .menu not #menu and now it doesn't seem to work to type menu ul { blabla }
How do I change the appearance of sub element ul in todays CSS?
#menu {
width: 550px;
height: 35px;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
text-align: center;
text-shadow: 3px 2px 3px #333333;
background-color: #8AD9FF;
border-radius: 8px;
}
#menu ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
<div class="menu">
<ul>
<li>A hurr</li>
<li>A durr</li>
<li>A murrmurr</li>
</ul>
</div>
if i understand your question, you can do this :
.menu ul li {
//properties
}
You just have to replace your #menu by .menu , because you put it as a class in the html code.
HTML:
<ul id="menu">
<li>Categories 1
<ul id="cat1">
<li class="first">temp1</li>
<li>temp2</li>
<li>temp3</li>
</ul>
</li>
</ul>
CSS:
#menu {
background-color: #0000FF;
height: 20px;
padding: 15px 0 10px;
margin: 5px;
font: 12px Tahoma;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
box-shadow: inset 0px 0px 10px #000;
text-align: center;
}
#menu > li{
display: inline;
}
li a {
color: #fff;
text-decoration: none;
}
.first{
margin-top: 12px;
}
#cat1 > li{
display: block;
background-color: #0000FF;
width: 150px;
margin-right: auto;
}
#cat1 > li > a{
display: block;
padding: 10px;
box-shadow: inset 0px 0px 2px #000;
}
When i use margin-left: auto in #cat > li it is woring properly. margin-right:auto on the other hand doesn't get the full margin, and I don't understand why this is.
Here's my fiddle: http://jsfiddle.net/ZfN7t/25/
Thank you for any and all help!
Mayb you should set <li> inline-block , maybe text-align:center and reset margin/padding of <ul> second level too :)
http://jsfiddle.net/ZfN7t/26/
ul {
margin:0 auto;
padding:0;
}
#menu > li {
display: inline-block;
}
Remove the default padding for html elements and it should work like expected.
ul,li
{
margin:0;padding:0;
}
FIDDLE
I want to make a drop down menu for my wordpress blog.
But there is a problem.
I want when the user puts their mouse over the <ul></ul>, the sub-category to appear.
I want to solve the problem with CSS only.
Notice: I've changed the direction of the page because I am using an Arabic language.
#menu-body {
border:dotted 1px #FFFFFF;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
background: #2C2C2C;
height:35px;
width:inherit;
color:#fff;
padding-right:15px;
padding-top:0px;
padding-bottom:0px;
font-family:Tahoma , Arial;
font-size:13px;
}
#menu-body ul {
float:right;
list-style:none;
margin:0px 0px 0px 0px;
padding:10px;
cursor:pointer; position:relative;
}
#menu-body ul:hover {
background-color:#FFFFFF;
color:#2C2C2C;
}
#menu-body ul a {
text-decoration:none;
color:#fff;
outline:0;
}
.dropdown_1column { margin:4px auto;
position:absolute;
left:-999em; /* Hides the drop down */
text-align:right;
padding:10px 5px 10px 5px;
border:1px solid #777777;
border-top:none;
/* Gradient background */
background:#F4F4F4;
background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));
/* Rounded Corners */
-moz-border-radius: 0px 5px 5px 5px;
-webkit-border-radius: 0px 5px 5px 5px;display:block;
border-radius: 0px 5px 5px 5px;}
.dropdown_1column {width: 140px;}
#menu-body ul:hover a {
color:#000;}
<div id="menu-body"><ul>Home</ul>
<ul>Category 1</ul>
<ul>Category 2</ul>
<ul>Category 3
<li>Sub-Cat 1</li>
<li>Sub-Cat 2</li>
<li>Sub-Cat 3</li></ul>
<ul>Category 4</ul></div>
Try with this css & html :
body {
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar * {
transition: 0.3s;
}
.navbar a {
float: right;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: right;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.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;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="navbar">
Home
Category 1
<div class="dropdown">
<button class="dropbtn">Category 2
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
Category 3
Category 4
</div>
</body>
</html>
You can have more exemple on https://www.w3schools.com/howto/howto_css_dropdown_navbar.asp