I integrated html boilertemplate with the help of the initializr on my side.
Now, i tried to add sub ul elements to the navigation in form of a dropdown, that got created by the initializr with pure css3, but i can't get it to work.
The css from boilertemplate created for the nav element is the following:
nav ul {
margin: 0;
padding: 0;
}
nav a {
display: block;
margin-bottom: 10px;
padding: 15px 0;
text-align: center;
text-decoration: none;
font-weight: bold;
color: white;
background: green;
}
nav a:hover,
nav a:visited {
color: white;
}
nav a:hover {
text-decoration: underline;
}
#media only screen and (min-width: 480px) {
/* ====================
INTERMEDIATE: Menu
==================== */
nav a {
float: left;
width: 13%;
margin: 0 1.7%;
padding: 10px 2%;
margin-bottom: 0;
}
nav li:first-child a {
margin-left: 0;
}
nav li:last-child a {
margin-right: 0;
}
/* ========================
INTERMEDIATE: IE Fixes
======================== */
nav ul li {
display: inline;
}
.oldie nav a {
margin: 0 0.7%;
}
}
#media only screen and (min-width: 768px) {
nav {
float: left;
width: 100%;
}
}
The solution i tried did not work with css3 from:
http://line25.com/tutorials/how-to-create-a-pure-css-dropdown-menu
How can i add sub elements / sub ul's to the navigation , so that they are displayed in a drop down to the hovered element?
In the end, i hoped it would have worked like in their example:
http://line25.com/wp-content/uploads/2012/css-menu/demo/index.html
Regards
You are missing some key CSS rules. Specifically:
nav ul li:hover > ul {
display: block;
}
Also, what is your html? Can't you simply copy and paste the code from the example you have linked to?
EDIT: Taken from the link you have provided, this should give you the desired effect; change values as needed.
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 25px 40px;
color: #757575; text-decoration: none;
}
nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a; position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
nav ul ul li a:hover {
background: #4b545f;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
Related
How could I make these styles responsive to all mobile devices?
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #0066cc;
background: linear-gradient(top, #0066cc 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #0066cc 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #0066cc 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 0.001px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #0066cc;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 25px 15px;
color: #000000; text-decoration: none;
}
nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a {
padding: 15px 15px;
color: #fff;
}
nav ul ul li a:hover {
background: #0066cc;
}
Thanks for everything.
You Need Bootstrap for making it responsive.You can learn it here: http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-responsive-layout.php
I have a nav bar with following HTML:
<nav id="menu-bar">
<ul>
<li><a href='http://sunilpatro1985.blogspot.in/' >Home</a></li>
<li><a href='http://sunilpatro1985.blogspot.in/search/label/SeleniumTesting'>Selenium</a>
<ul>
<li><a href='http://sunilpatro1985.blogspot.in/2015/04/selenium-testng.html'>TestNG</a></li>
<li><a href='http://sunilpatro1985.blogspot.com/2015/03/selenium-result-report-testng-ant.html'>ANT Reporting</a></li>
</ul>
</li>
<li><a href='http://sunilpatro1985.blogspot.in/search/label/SoftwareTesting'>TestingConcepts</a></li>
<li><a href='http://sunilpatro1985.blogspot.in/search/label/BasicJava' >JavaBasics</a></li>
<li><a href='http://sunilpatro1985.blogspot.in/search/label/WindowsOS' >Windows</a></li>
<li><a href='http://sunilpatro1985.blogspot.in/p/demo.html' >Demo</a></li>
</ul></nav>
and the CSS I used:
#menu-bar {position: fixed; top: 0px; left: 0px; z-index: 999;height:0px;}
#menu-bar,#menu-bar a {
text-align: center;
margin: 0px 0px;
border:none;
}
#menu-bar ul ul {
display: none;
}
#menu-bar ul li:hover > ul {
display: block;
}
#menu-bar ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 7px;
list-style: none;
position: relative;
display: inline-table;
overflow:visible;
}
#menu-bar ul:after {
content: ""; clear: both; display: block;
}
#menu-bar ul li {
float: left;
}
#menu-bar ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
#menu-bar ul li:hover a {
color: #fff;
}
#menu-bar ul li a {
display: block; padding: 15px 30px;
color: #757575; text-decoration: none;
}
#menu-bar ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
#menu-bar ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
#menu-bar ul ul li a {
padding: 15px 30px;
color: #fff;
}
#menu-bar ul ul li a:hover {
background: #4b545f;
}
#menu-bar ul ul ul {
position: absolute; left: 100%; top:0;
}
This above menu bar only covers 80% of my desktop screen. How can I make it full width? I tried some options as mentioned in other Stack Overflow answers, but nothing helped completely. Please help me make menu bar full width on screen.
It doesn't look like you're actually setting the nav element to be 100% of the width in the CSS. Try adding this:
#menu-bar { width: 95%;}
#menu-bar > ul {width: 100% }
That worked in jsFiddle but you may need to adjust the percentage for menu-bar (the first line).
Try this code:
#menu-bar{width:100%}
#menu-bar ul{width:100%}
Just add right: 0 to #menu-bar:
#menu-bar {
position: fixed;
top: 0;
left: 0;
right: 0; /* <-- here */
z-index: 999;
height: 0; /* why is the height "0"? */
}
This is my CSS code. I can't seem to get it centered. I've tried using display: inline-block and float: left. I've also tried using margins but it ends up messing up the dropdown box. I've tried editing everything but I can't get it right. I'm sorta new to this kinda thing. I would appreciate the help
body {
background-image:url('andromedagalaxy.jpg');
}
h1 {
text-align:center;
color: white;
}
p {
text-align:center;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #0099CC;
background: linear-gradient(top, #0099CC 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #0099CC 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #0099CC 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-block;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif;
text-align: center;
}
nav ul:after {
content: ""; clear: both; display: block; text-align:center;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #000066;
background: linear-gradient(top, #000066 0%, #000066 40%);
background: -moz-linear-gradient(top, #000066 0%, #000066 40%);
background: -webkit-linear-gradient(top, #000066 0%, #000066 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 15px 30px;
color: #000099; text-decoration: none;
}
nav ul ul {
background: #000066; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #000066;
border-bottom: 1px solid #000066;
position: relative;
}
nav ul ul li a {
padding: 15px 20px;
color: #fff;
}
nav ul ul li a:hover {
background: #006699;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
Since you are using this:
nav ul {
display: inline-block;
}
To center that ul you can use text-align on the parent, try this:
nav {
text-align:center;
}
You can check this link http://jsfiddle.net/eb2Zd/6/ to review the demo file.
You can use this on the nav
nav {
text-align:center;
}
After providing us with a JsFiddle i have 2 examples for you.
Example 1:
You should give your nav a width and margin:0 auto; Like in the example down here.
nav { width:505px; margin: 0 auto}
DEMO 1
Example 2:
nav { text-align:center; }
DEMO 2
body {
background-image:url('andromedagalaxy.jpg');
}
h1 {
text-align:center;
color: white;
}
p {
text-align:center;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #0099CC;
background: linear-gradient(top, #0099CC 0%);
background: -moz-linear-gradient(top, #0099CC 0%);
background: -webkit-linear-gradient(top, #0099CC 0%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-block;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans- serif;
text-align: center;
}
nav ul:after {
content: ""; clear: both; display: block; text-align:center;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #000066;
background: linear-gradient(top, #000066 0%);
background: -moz-linear-gradient(top, #000066 0%;)
background: -webkit-linear-gradient(top, #000066 0%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 15px 30px;
color: #000099; text-decoration: none;
}
nav ul ul {
background: #000066; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #000066;
border-bottom: 1px solid #000066;
position: relative;
}
nav ul ul li a {
padding: 15px 20px;
color: #fff;
}
nav ul ul li a:hover {
background: #006699;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
nav{
text-align:center;
}
}
http://jsfiddle.net/u8V9R/
On the html, place inside a which must be centered.
On the CSS file, center by placing this
.center {position: relative;
margin-left:auto;
margin-right:auto;
text-align:center;
}
I am referring to a CSS code from here. I have created a sample html and CSS file as shown there and It's working fine. However, I want to use this code in other place where ul,li have been already defined styles using another CSS file. So, i searched a bit and read that in this case, the solution is to use specific ids for elements so they will be distinguished. Can anyone please tell how to add ids to following CSS as I am confused because of their parent-child nesting in CSS code..
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 25px 40px;
color: #757575; text-decoration: none;
}
nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
nav ul ul li a:hover {
background: #4b545f;
}
Follow this semantic structure...
Your HTML:
<nav id="mainmenu"> ... </nav>
<nav id="sidemenu"> ... </nav>
Your CSS:
nav#mainmenu ul {
...
}
nav#sidemenu ul {
...
}
This should allow distinction from there.
In the html, you would find the specific ul and li elements and add id="unique_name" (ie: ). Then, in the CSS, you would add #unique_id to style that element. For example:
HTML
<ul id="myUL">
CSS
#myUL {
background: red;
}
If you are wanting to apply your CSS to a specific nav object, you could just replace nav in the css with a your id like this
.newId ul ul {
display: none;
}
.newId ul li:hover > ul {
display: block;
}
.newId ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-table;
}
.newId ul:after {
content: ""; clear: both; display: block;
}
.newId ul li {
float: left;
}
.newId ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
.newId ul li:hover a {
color: #fff;
}
.newId ul li a {
display: block; padding: 25px 40px;
color: #757575; text-decoration: none;
}
.newId ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
.newId ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
.newId ul ul li a {
padding: 15px 40px;
color: #fff;
}
.newId ul ul li a:hover {
background: #4b545f;
}
This will apply the given CSS to a nav object with the id "newId".
In css you access a member via its id using #
so if you were to set the ul li inside a nav that has the id myNav you would write
nav#myNav ul li {...}
keep in mind that id of course has to exist in your html (and may by standard only exist once per id)
<nav id="myNav"><ul><li>.....</li></ul></nav>
to add ids to css rules, just add # and id identifier (without spaces!) after the element, like:
nav ul#fisrtUlId ul#secondUlId {
display: none;
}
You can get the same result without using ids just including the css you provided after the existing one you mentioned. As long as the rules in the first css are not more descriptive, the rules for the same elements defined in the second css file will take precedence, which is I believe you want to accomplish here.
I stucked at this part. I have a menu in HTML like this:
<nav>
<ul>
<li>Home</li>
<li>Item1
<ul>
<li>Item1_1</li>
<li>Item1_1</li>
<li>Item1_1</li>
<li>Item1_1</li>
<li><a id="last" href="#">Last</a></li>
</ul>
</li>
</ul>
</nav>
The CSS is this:
nav {
margin-left: auto;
margin-right: auto;
width: 100%;
}
nav ul ul li a #last {
border-bottom-left-radius: 1em;
border-bottom-right-radius: 1em;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: linear-gradient(top, #ffffff 0%, #ffffff 100%);
background: -moz-linear-gradient(top, #fffff 0%, #fffff 100%);
background: -webkit-linear-gradient(top, #ffffff 0%,#ffffff 100%);
padding: 0px;
list-style: none;
position: relative;
display: inline-table;
width: 100%;
text-align: center;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
nav ul li {
width: 20%;
float: left;
text-align: center;
}
nav ul li:hover {
border-top-left-radius: 1em;
border-top-right-radius: 1em;
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
font-family: Arial,Helvetica,sans-serif;
font-size: 0.9em;
font-weight: bold;
display: block;
padding: 0.9em;
color: #000000;
text-decoration: none;
}
nav ul ul {
width: 20%;
background: #5f6975;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
}
nav ul ul li {
font-family: Arial,Helvetica,sans-serif;
float: none;
width: 100%;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a {
font-family: Arial,Helvetica,sans-serif;
font-size: 0.7em;
width: 89%;
padding: 15px 10px;
}
nav ul ul li a:hover {
background: #4b545f;
}
As You can see there is an id="last" for the last item at the list, because I want to this item have a rounderd bottom border (left and right side aswell). But I have no idea why its not working :(. Its my first post so sorry for my english, and for the long post aswell :) Plase help me, thank You!
For id you need to make css like this:
nav ul ul li a#last
noticed the difference? the #last is combined with the a.
Since #last is unique, all you need is:
#last {
...your css..
}
a #last means "the element with the ID of "last" that is a child of an <a> tag.
You don't need the space there. a#last means "an <a> tag with the ID of "last".
Actually, since IDs are supposed to be unique, you can just use #last, without the a (or even the rest of the elements before it).