Below is my html
<div id="wrap">
<ul class="navbar">
<li>Home</li>
<li>Franchises
<ul>
<li>elroyz Xpress</li>
<li>skye stickbeetles</li>
<li>Juddamania</li>
</ul>
</li>
<li>Fixtures
<ul>
<li>Round 1</li>
<li>Round 2</li>
<li>Round 3</li>
<li>Round 4</li>
<li>Round 5</li>
</ul>
</li>
<li>Free Agents
<ul>
<li>Adelaide</li>
<li>Brisbane</li>
<li>Carlton</li>
</ul>
</li>
</ul>
</div>
below is my CSS
#wrap {
width:100%;
height: 37px;
margin: 0;
z-index:99;
position:relative;
background-color:#F00;}
.navbar {
height: 35px;
padding:0;
margin: 0;
position:absolute;
border-right: 1px solid #1c1c1c;
}
.navbar li {
height: auto;
width: 150px;
float: left;
text-align: center;
list-style: none;
font: normal bold 14px/1.2em Arial, Verdana, Helvetica;
padding: 0;
margin: 0;
background-color: #F00
}
.navbar a {
padding: 10px 0;
border-left: 1px solid #1c1c1c;
border-right: 1px solid #1c1c1c;
text-decoration: none;
color: white;
display: block;
}
.navbar li:hover, a:hover {background-color: #a4a4a4;}
.navbar li ul {
display: none;
height: auto;
margin: 0;
padding: 0;
}
.navbar li:hover ul {
display: block;
}
.navbar li ul li {background-color: #a4a4a4;}
.navbar li ul li a {
border-left: 1px solid #1c1c1c;
border-right: 1px solid #1c1c1c;
border-top: 1px solid #1c1c1c;
border-bottom: 1px solid #1c1c1c;
}
.navbar li ul li a:hover {background-color: #1c1c1c;}
im only new to html and css so im having abit of trouble getting the nav bar to center in the page. by center i mean the actual list items to center in the page not on the left hand side like it is now. any help is greatly appreciated thanks!
You need to add width and margin auto to your navbar I made a little jsFiddle
.navbar {
height: 35px;
width:610px;
margin:0 auto;
}
jsFiddle
You have to set the width of wrap to something in pixels like this
#wrap {
width:750px; // Set it according to your need
margin: 0px auto; // i also changed this
height: 37px;
z-index:99;
position:relative;
background-color:#F00;}
and also the margin to 0px auto
Here is the JSfiddle
.navbar {
height: 35px;
padding:0;
position:relative;
margin-left:auto;
margin-right:auto;
width: 100px;// change this to desired width
border-right: 1px solid #1c1c1c;
}
Related
I'm having trouble coming up with a solution here. I have a menu with a bar between list elements. However rather than a standard border, there is a break at the top and bottom.
The only solution I came up with is to use li:after in the CSS to place an image but for some reason the padding and margin gets all messed up. So far I have the CSS and HTML embedded below (I'm using Bootstrap as the framework here).
Any ideas on how to get these bars working?
Screenshot:
(Ignore the red color ... things were messed up in illustrator).
#reviews .review-actions {
text-align: center;
z-index: 2;
padding-top: 1px;
}
#reviews nav {
display:inline-block;
margin:0 auto;
}
#reviews nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
#reviews nav ul li{
display: inline;
margin: 0;
float: left;
padding: 10px;
background-color: #fff;
font-size:1.2em;
}
/*#reviews nav ul li:after{
content: url('./img/menu-splitter.png');
}*/
#reviews nav ul > li:first-child {
border-top-left-radius: .5em;
border-bottom-left-radius: .5em;
border: 1px solid #ccd0d0;
border-right: none;
}
#reviews nav ul > li:nth-child(2){
border: 1px solid #ccd0d0;
border-right: none;
border-left: none;
}
#reviews nav ul > li:last-child {
border-top-right-radius: .5em;
border-bottom-right-radius: .5em;
border: 1px solid #ccd0d0;
border-left: none;
}
#reviews nav ul li a{
}
<section id='reviews'>
<!-- Navigation -->
<div class="review-actions">
<nav>
<ul>
<li><a href='#'>The App</a></li>
<li><a href='#'>Our Service</a></li>
<li><a href='#'>Surprises</a></li>
</ul>
</nav>
</div>
</section>
You can set it directly in the background of the li
#reviews .review-actions {
text-align: center;
z-index: 2;
padding-top: 1px;
}
#reviews nav {
display:inline-block;
margin:0 auto;
}
#reviews nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
#reviews nav ul li{
display: inline;
margin: 0;
float: left;
padding: 10px;
background-color: #fff;
font-size:1.2em;
}
/*#reviews nav ul li:after{
content: url('./img/menu-splitter.png');
}*/
#reviews nav ul > li:first-child {
border-top-left-radius: .5em;
border-bottom-left-radius: .5em;
border: 1px solid #ccd0d0;
border-right: none;
}
#reviews nav ul > li:nth-child(2){
border: 1px solid #ccd0d0;
border-right: none;
border-left: none;
}
#reviews nav ul > li:last-child {
border-top-right-radius: .5em;
border-bottom-right-radius: .5em;
border: 1px solid #ccd0d0;
border-left: none;
}
#reviews nav ul li a{
}
li:nth-last-child(n+2) {
background-image: linear-gradient(blue, blue);
background-size: 2px 90%;
background-repeat: no-repeat;
background-position: right center;
}
<section id='reviews'>
<!-- Navigation -->
<div class="review-actions">
<nav>
<ul>
<li><a href='#'>The App</a></li>
<li><a href='#'>Our Service</a></li>
<li><a href='#'>Surprises</a></li>
</ul>
</nav>
</div>
</section>
One solution is to deploy 4 single-pixel-width box-shadows around the <ul> as a faux border, and then give the <ul> an actual border the same color as the <li> background-color:
#reviews .review-actions {
text-align: center;
z-index: 2;
padding-top: 1px;
}
#reviews nav {
display:inline-block;
margin:0 auto;
}
#reviews nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 6px solid #ffffff;
box-shadow: 1px 1px #ccd0d0, -1px 1px #ccd0d0, -1px -1px #ccd0d0, 1px -1px #ccd0d0;
border-radius: .5em;
}
#reviews nav ul li{
display: inline;
margin: 0;
float: left;
padding: 10px;
background-color: #fff;
font-size:1.2em;
border-left: 1px solid #ccd0d0;
}
#reviews nav ul > li:first-child {
border-left: none;
}
<section id='reviews'>
<!-- Navigation -->
<div class="review-actions">
<nav>
<ul>
<li><a href='#'>The App</a></li>
<li><a href='#'>Our Service</a></li>
<li><a href='#'>Surprises</a></li>
</ul>
</nav>
</div>
</section>
I'm very confused. #top div has a weird extra space in the bottom of it, setting height of course works, but the problem is that I want to add back compatibility, so if a custom font doesn't load, it uses Verdana, which is wider, so it takes more place, and if the navbar gets bigger, it won't properly fit in the #top
The code is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sidebar test</title>
</head>
<style>
div {
border: 1px solid #999;
}
body { font-family: Verdana, sans-serif; font-size: 17px; }
#navbar {
border-radius: 6px;
overflow: hidden;
display: inline-block;
margin: 0;
padding: 0;
}
#navbar ul {
list-style-type: none;
padding: 0;
margin: 0;
float: left;
}
#navbar ul li {
display: inline;
color: black;
text-decoration: none;
}
#navbar ul a {
float: left;
padding: 10px 18px;
text-decoration: none;
color: black;
background-color: #f1f1f1;
-webkit-transition: background-color 0.02s;
transition: background-color 0.02s;
}
#navbar ul a:hover {
background-color: #e6e6e6;
}
#navbar ul a:selected {
background-color: #c7c7c7;
}
#content {
padding: 35px 50px 60px 50px;
}
#container {
width: 900px;
margin: 20px auto;
border-radius: 5px;
box-shadow: 0px 2px 2px 1px #d5d5d5;
}
</style>
<body>
<div id="container">
<div id="top">
<img alt="logo" height="27px" src="http://static.tumblr.com/zicio7x/Tphntwm0j/yvemiro.svg">
<div id="navbar">
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</div>
</div>
<div id="content">
Content
</div>
</div>
</body>
</html>
By default, inline elements are vertically aligned to the baseline. Now the navbar contains an image and the menu bar next to each other, so it has to shift these up and down a bit in order to align them.
Solution: give these things vertical-align:middle (or any other value that doesn't require shifting the blocks out of center).
div {
border: 1px solid #999;
}
body {
font-family: Verdana, sans-serif;
font-size: 17px;
}
#top > a > img { /* this was added */
vertical-align: middle;
}
#navbar {
border-radius: 6px;
overflow: hidden;
display: inline-block;
margin: 0;
padding: 0;
vertical-align: middle; /* and this */
}
#navbar ul {
list-style-type: none;
padding: 0;
margin: 0;
float: left;
}
#navbar ul li {
display: inline;
color: black;
text-decoration: none;
}
#navbar ul a {
float: left;
padding: 10px 18px;
text-decoration: none;
color: black;
background-color: #f1f1f1;
-webkit-transition: background-color 0.02s;
transition: background-color 0.02s;
}
#navbar ul a:hover {
background-color: #e6e6e6;
}
#navbar ul a:selected {
background-color: #c7c7c7;
}
#content {
padding: 35px 50px 60px 50px;
}
#container {
width: 900px;
margin: 20px auto;
border-radius: 5px;
box-shadow: 0px 2px 2px 1px #d5d5d5;
}
<div id="container">
<div id="top">
<a href="#">
<img alt="logo" height="27" src="http://static.tumblr.com/zicio7x/Tphntwm0j/yvemiro.svg">
</a>
<div id="navbar">
<ul>
<li>Link 1
</li>
<li>Link 2
</li>
<li>Link 3
</li>
<li>Link 4
</li>
</ul>
</div>
</div>
<div id="content">
Content
</div>
</div>
I have a fairly simple navigation bar with a bottom border but I would like to box it off on either side - but not the top. So I get a |______________| surrounding all of my links but I am just starting out and whatever I try seems to border every single link which I don't want.
<nav>
<div align="center">
<div id="navigation">
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>News</li>
<li>Careers</li>
<li>Contact Us</li>
</ul>
</div><!--navigation-->
</nav>
and css
nav {
width: 100%;
margin:0 auto;
}
nav ul li {
width: 16.6%;
float: left;
border-bottom: 1px solid #A2A2A2;
list-style-type: none;
display: inline;
}
nav ul li a {
display: block;
width: 100%;
text-align: center;
padding-top: 8px;
padding-right: 8px;
padding-bottom: 8px;
padding-left: 8px;
color: #202020;
font-family: "Myriad Pro Light";
text-transform: uppercase;
text-decoration: none;
font-size: 12pt;
}
nav ul li a:hover {
color: #89ccca
}
nav ul{
width: 80%;
list-style: none;
margin: 0;
padding: 0;
}
Use first-child and last-child properties and apply it like below.
CSS
nav ul li:first-child
{
border-left: 1px solid #A2A2A2;
}
nav ul li:last-child
{
border-right: 1px solid #A2A2A2;
}
FIDDLE DEMO
maybe i can help you
try this
nav ul li {
width: 16.0%;
float: left;
border-bottom: 1px solid #A2A2A2;
border-right: 1px solid #A2A2A2;
list-style-type: none;
display: inline;
}
nav ul li:first-child{border-left: 1px solid #A2A2A2;}
fiddle here
http://jsfiddle.net/zfdxko8h/
try including this one..
#navigation ul li:first-child {
border-left: 1px solid #A2A2A2;
}
#navigation ul li:last-child {
border-right: 1px solid #A2A2A2;
}
Here is The Fiddle
I can't make ul to be centered in the div element
<div class="top-menu">
<ul class="topnav dropdown" a>
<li>Home</li>
<li>
Tutorials
<ul class="subnav">
<li>
Sub Nav Link
<ul class="subnav">
<li>Sub Nav Link
<ul class="subnav">
<li>Sub Nav Link</li>
<li>Sub Nav Link</li>
</ul>
</li>
<li>Sub Nav Link</li>
</ul>
</li>
<li>Sub Nav Link</li>
</ul>
</li>
<li>
Resources
<ul class="subnav">
<li>Sub Nav Link</li>
<li>Sub Nav Link</li>
</ul>
</li>
<li>About Us</li>
<li>Advertise</li>
<li>Submit</li>
<li>Contact Us</li>
</ul>
</div>
and css style
.top-menu{
width:100%;
text-align:center;
}
ul.topnav {
border:1px solid black;
list-style: none;
padding: 0 20px;
margin: auto;
width: 100%;
background: #222;
background: url(topnav_bg.gif) repeat-x;
}
ul.topnav li {
float: left;
margin: 0;
padding: 0 15px 0 0;
position: relative; /*--Declare X and Y axis base for sub navigation--*/
display: inline;
}
what is wrong?
fiddle is here http://jsfiddle.net/m82LK/2/, Thanks
See this FIDDLE
CSS:
.top-menu {
width:100%;
text-align:center;
}
ul.topnav {
border:1px solid black;
list-style: none;
padding: 0 20px;
margin: auto;
width: 100%;
background: #222;
background: url(topnav_bg.gif) repeat-x;
}
ul.topnav li {
display:inline-block;
margin: 0;
padding: 0 15px 0 0;
position: relative;
/*--Declare X and Y axis base for sub navigation--*/
}
ul.topnav li a {
padding: 10px 5px;
color: #aaaaaa;
display: block;
text-decoration: none;
}
ul.topnav li a:hover {
background: url(topnav_hover.gif) no-repeat center top;
}
ul.topnav li span {
/*--Drop down trigger styles--*/
width: 17px;
height: 35px;
float: left;
background: url(subnav_btn.gif) no-repeat center top;
}
ul.topnav li span.subhover {
background-position: center bottom;
cursor: pointer;
}
/*--Hover effect for trigger--*/
ul.topnav li ul.subnav {
list-style: none;
position: absolute;
/*--Important - Keeps subnav from affecting main navigation flow--*/
left: 0;
top: 35px;
background: #333;
margin: 0;
padding: 0;
display: none;
float: left;
width: 170px;
border: 1px solid #111;
}
ul.topnav li ul.subnav li {
margin: 0;
padding: 0;
border-top: 1px solid #252525;
/*--Create bevel effect--*/
border-bottom: 1px solid #444;
/*--Create bevel effect--*/
clear: both;
width: 170px;
}
html ul.topnav li ul.subnav li a {
float: left;
width: 145px;
background: #333 url(dropdown_linkbg.gif) no-repeat 10px center;
padding-left: 20px;
}
html ul.topnav li ul.subnav li a:hover {
/*--Hover effect for subnav links--*/
background: #222 url(dropdown_linkbg.gif) no-repeat 10px center;
}
replace ul.topnav with this:
ul.topnav {
border:1px solid black;
list-style: none;
padding: 0 20px;
background: url(topnav_bg.gif) repeat-x; // or #222 based on ur requirement
display: inline-block;
}
Remove the float: left on your li and use inline-block. Add text-align: center to your ul
See updated fiddle: http://jsfiddle.net/m82LK/3/
Edit: This works. I also added the box-sizing:border-box so that the padding on the UL doesn't affect it's width (before it was pushed off the right of the screen). Here is an updated fiddle http://jsfiddle.net/m82LK/11/
* {
box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
}
.top-menu{
width:100%;
text-align:center;
}
ul.topnav {
border:1px solid black;
list-style: none;
padding: 0 20px;
margin: auto;
width: 100%;
background: #222;
background: url(topnav_bg.gif) repeat-x;
}
ul.topnav li {
display:inline-block;
margin: 0;
padding: 0 15px 0 0;
position: relative; /*--Declare X and Y axis base for sub navigation--*/
}
ul.topnav li a{
padding: 10px 5px;
color: #aaaaaa;
display: block;
text-decoration: none;
display:inline-block;
}
ul.topnav li a:hover{
background: url(topnav_hover.gif) no-repeat center top;
}
ul.topnav li span { /*--Drop down trigger styles--*/
width: 17px;
height: 35px;
display:inline-block;
background: url(subnav_btn.gif) no-repeat center top;
}
ul.topnav li span.subhover {background-position: center bottom; cursor: pointer;} /*--Hover effect for trigger--*/
ul.topnav li ul.subnav {
list-style: none;
position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/
left: 0; top: 35px;
background: #333;
margin: 0; padding: 0;
display: none;
float:left;
width: 170px;
border: 1px solid #111;
}
ul.topnav li ul.subnav li{
margin: 0; padding: 0;
border-top: 1px solid #252525; /*--Create bevel effect--*/
border-bottom: 1px solid #444; /*--Create bevel effect--*/
clear: both;
width: 170px;
}
html ul.topnav li ul.subnav li a {
display:inline-block;
width: 145px;
background: #333 url(dropdown_linkbg.gif) no-repeat 10px center;
padding-left: 20px;
}
html ul.topnav li ul.subnav li a:hover { /*--Hover effect for subnav links--*/
background: #222 url(dropdown_linkbg.gif) no-repeat 10px center;
}
I have made a few attempts at this and they ended up just getting confusing. The current HTML and CSS seems to be working fine for a simple horizontal CSS menu. I am struggling with dropping subitems off the current <li> elements.
I am trying to making them show up exactly below the current menu items with the same hovering effects as I have in place now. Any assistance would be appreciated. I am admittedly no CSS pro.
Current HTML:
<div class="MenuTop">
<ul class="Nav">
<li>Home</li>
<li>Vehicles
<ul>
<li>SubItemOne</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>News</li>
</ul>
</div>
Current CSS:
.MenuTop
{
width: 960px;
background-color: Black;
color: #fff;
margin: auto auto 0px auto;
padding: 5px;
height:auto;
font-family: Segoe UI, Arial;
font-weight:bold;
min-height:15px;
}
.MenuTop ul
{
float: left;
list-style: none;
margin: -5px ;
padding: 0px;
}
.MenuTop li
{
float: left;
font-size:12px;
font-family: Segoe UI, Arial;
margin: 0;
padding: 0;
}
.MenuTop a
{
background-color: Black;
color: #fff;
display: block;
float: left;
margin: 0;
padding: 4px 12px 4px 12px;
text-decoration: none;
}
.MenuTop a:hover
{
background-color: #404040;
color: #fff;
padding: 4px 12px 4px 12px;
}
You were close, but you're forgetting about positioning your submenu items absolutely to your parent li menu item and hiding it as well, by using display:none and then showing it on hover, so try something like this to achieve that effect:
CSS
.Nav li {
position:relative;
}
.Nav li ul {
display:none;
position:absolute;
top:30px;
}
.Nav li:hover ul {
display:block;
}
Also, your submenu ul is not properly closed so go ahead and close it.
Ninja Edit: demo, by the way you can greatly benefit from properly targeting your menu by using the class you have given it, .Nav, instead of its parent class of its container, .MenuTop, that way you can target your menu and your menu alone and not any other element you might place inside that container,
I have created a working example for you on jsFiddle.
The HTML is as follows:
<nav>
<ul class="cf">
<li>Home</li>
<li>Vehicles
<ul>
<li>Sub-menu Item 1</li>
<li>Sub-menu Item 2</li>
<li>Sub-menu Item 3</li>
</ul>
</li>
<li>About</li>
<li>News</li>
</ul>
</nav>
and the CSS:
nav ul {
background: #ddd;
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}
nav li {
float: left;
margin: 0;
padding: 0;
position: relative;
min-width: 25%;
}
nav a {
font-family: Lucida Grande;
background-color: #666666;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: rgba(255,255,255,0.5) 0px 3px 3px;
display: block;
font: bold 14px sans-serif;
padding: 0 25px;
text-align: center;
text-decoration: none;
}
nav li ul {
float: left;
left: 0;
opacity: 0;
position: absolute;
top: 1em;
visibility: hidden;
z-index: 1;
}
nav li:hover ul {
opacity: 1;
top: 1em;
visibility: visible;
}
nav li ul li {
float: none;
width: 100%;
}
.cf:after, .cf:before {
content:"";
display:table;
}
.cf:after {
clear:both;
}
.cf {
zoom:1;
}