I have an excerpt of code that I need centered in my header, (just the text and the actual padding). I'm new to coding so if this doesn't sound right don't be surprised. This is the code where I need my list items centered in. Try to make your answer as beginner-like as possible.
CSS:
#navcontainer ul {
list-style-type: none;
margin: 0;
padding: 0;
font-family:'Raleway', sans-serif;
font-size: 23px;
color: #800000;
}
#navcontainer ul li {
display: inline;
}
#navcontainer ul li a {
text-decoration: none;
padding: 0px;
margin: 40px;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #800000;
}
HTML:
<div id= "navcontainer">
<!-- BEGIN TABS -->
<ul>
<a id="index" class="page-logo" href="/">
<img src="slamlogo.png" alt="Logo">
<li>Jackpot</li>
<li>Profile</li>
<li>Market</li>
<li>Support</li>
</ul>
I know the li elements are messy but I do it so I can see it better. Sorry.
Add a text-align: center to the <ul>:
#navcontainer ul {
text-align: center;
}
Snippet
#navcontainer ul {
list-style-type: none;
margin: 0;
padding: 0;
font-family: 'Raleway', sans-serif;
font-size: 23px;
color: #800000;
text-align: center;
}
#navcontainer ul li {
display: inline;
}
#navcontainer ul li a {
text-decoration: none;
padding: 0px;
margin: 40px;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #800000;
}
<div id="navcontainer">
<!-- BEGIN TABS -->
<a id="index" class="page-logo" href="/">
<img src="slamlogo.png" alt="Logo">
</a>
<ul>
<li>
Jackpot
</li>
<li>
Profile
</li>
<li>
Market
</li>
<li>
Support
</li>
</ul>
</div>
Also, not a good idea to have anything other than <li> inside the <ul>. You have also omitted a </a>.
There were a few errors in your markup, I've gone ahead and fixed them for you. All that's required to center your list items is text-align: center if you're positioning them as inline elements.
<div id= "navcontainer">
<ul>
<li>
<a id="index" class="page-logo" href="/">
<img src="slamlogo.png" alt="Logo">
</a>
</li>
<li>Jackpot</li>
<li>Profile</li>
<li>Market</li>
<li>Support</li>
</ul>
</div>
#navcontainer ul {
list-style-type: none;
margin: 0;
padding: 0;
font-family:'Raleway', sans-serif;
font-size: 23px;
color: #800000;
text-align: center;
}
#navcontainer ul li {
display: inline;
}
#navcontainer ul li a {
text-decoration: none;
padding: 0px;
margin: 40px;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #800000;
}
http://jsfiddle.net/ruLns221/
Just to further explain the changes, you should only add li elements to an unordered list (ul) so I've nested your logo within a list item. I've closed some unclosed tags off as well.
Related
I am new to CSS and I have been looking for a solution but I can't seem to make it working.
I have this simple nav:
<nav class="navbar-left">
<ul>
<li>
My usage report
</li>
</ul>
</nav>
How could I select and style the li inside the nav I have tried but it does not work:
.navbar-left li {
background-color: red;
}
use this
nav > ul{
background-color:red;
}
and try.
.navbar-left ul {
List-style-type: none;
margin: 0px;
padding: 0px;
}
.navbar-left ul li {
background-color: red;
padding: 3px 10px;
margin: 0px;
}
.navbar-left ul li a {
color: #ffffff;
text-decoration: none;
font-size: 16px;
line-height: 18px;
}
<nav class="navbar-left">
<ul>
<li>
My usage report
</li>
<li>
My next report
</li>
</ul>
</nav>
Use this code i hope its work..
When I try to make a navigation bar I want it to float right but when I do that the < li > elements display vertically when I want them horizontally.
#navigation ul{
font-family: 'Roboto', sans-serif;
float: right;
overflow: hidden;
line-height: 1px !important;
/*position: fixed;*/
}
#navigation ul li h3 {
font-weight: normal;
font-size: 34px !important;
color: #000;
margin-right: auto;
padding: 0;
margin: auto;
letter-spacing: 0.25px;
}
#navigation ul li {
list-style: none;
line-height: 40px !important;
}
#navigation a{
text-align: center;
}
<header>
<nav id="navigation">
<ul>
<li>
<h3>Home</h3>
<h3>About</h3>
<h3>Timeline</h3>
<h3>Video</h3>
</li>
</ul>
</nav>
</header>
Try to insert a display: inline; on element.
#navigation ul li h3 {
font-weight: normal;
font-size: 34px !important;
color: #000;
margin-right: auto;
float:right;
padding: 0;
margin: auto;
letter-spacing: 0.25px;
display:inline;
}
You have a bunch of block elements that stack by default. So make the li's, a, h3 all display: inline or inline-block. Also, add a width to the UL since a "float" makes it collapse to the width of the content.
#navigation ul{
font-family: 'Roboto', sans-serif;
float: right;
overflow: hidden;
line-height: 1px !important;
width: 100%;
text-align: right;
}
#navigation ul li h3 {
font-weight: normal;
font-size: 34px !important;
color: #000;
margin-right: auto;
padding: 0;
margin: auto;
letter-spacing: 0.25px;
}
#navigation ul li {
list-style: none;
line-height: 40px !important;
display:inline-block;
}
#navigation a{
text-align: center;
}
#navigation a, #navigation h3 {
display:inline;
}
<header>
<nav id="navigation">
<ul>
<li>
<h3>Home</h3>
<h3>About</h3>
<h3>Timeline</h3>
<h3>Video</h3>
</li>
</ul>
</nav>
</header>
Also, that's overly complicated from a markup standpoint. It used to be that putting navigation into an unordered list was a way to make it semantic but HTML5's Nav element can do that for you. A better way would look like this:
nav {
font-size: 14px;
font-family: sans-serif;
text-align: right;
}
nav a {
margin-left: 10px;
padding: 5px;
display: inline-block;
}
<nav>
Home
About
Timeline
Video
</nav>
The li items have a default display of list-item which stacks like block elements. If you add display: inline; to your li elements and display: inline-block; or display: inline; to your anchor tags inside the li it should display your menu items horizontally.
You need to create separate lines for these items.Changes your HTML to this
<header>
<nav id="navigation">
<ul>
<li class="menuItem">
<a href="./entry.html">
<h3>Home</h3>
</a>
</li>
<li class="menuItem">
<a href="#">
<h3>About</h3>
</a>
</li>
<li class="menuItem">
<a href="#">
<h3>Timeline</h3>
</a>
</li>
<li class="menuItem">
<a href="#">
<h3>Video</h3>
</a>
</li>
</ul>
</nav>
</header>
And add this to your css
#navigation ul{
display: flex;
width:100%;
font-family: 'Roboto', sans-serif;
float: right;
overflow: hidden;
line-height: 1px !important;
/*position: fixed;*/
}
.menuItem {
padding: 10px;
}
You can change the padding according to the way you like
I'm trying to make a simple responsive navigation but i can't seem to eliminate the spaces inbetween the links. Any help would greatly be appreciated.
This is my code:
css:
.nav{
width:100%; text-align:centre; margin:0 auto;max-width:1010px;
}
.nav ul{
line-height:50px;
}
.nav li{
display:inline; list-style-type: none;border-right:#333333 1px solid;
}
.nav li:hover{
}
.nav a{
text-decoration:none; padding:10px; color:#000; font-family: sans-serif;
}
.nav a:hover{
color:#c00;background:#999999;
}
html:
<div class="nav"><!-- nav -->
<span class="menu-button"></span>
<ul class="clearfix menu">
<li>Home</li>
<li>About Us</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div><!--/nav-->
With CodeRomeos answer, most of the spacing/padding was removed but there was still some spacing between the links. From your request to eliminate the spacing between the links then the below solution will completely remove spacing (although it would look better IMO with at least some padding between links).
.nav {
width: 100%;
text-align: centre;
margin: 0;
max-width: 1010px;
}
.nav ul {
line-height: 16px;
}
.nav li {
display: inline;
list-style-type: none;
border-right: #333333 1px solid;
margin: 0;
padding: 0;
float: left;
}
.nav a {
text-decoration: none;
color: #000;
font-family: sans-serif;
font-size: 16px;
margin: 0;
padding: 0;
}
.nav a:hover {
color: #c00;
background: #999999;
}
<div class="nav">
<span class="menu-button"></span>
<ul class="clearfix menu">
<li>
Home
</li>
<li>
About Us
</li>
<li>
Portfolio
</li>
<li>
Contact
</li>
</ul>
</div>
I just switched your css a bit from display: inline to float: left for the li tags. Hope it helps, though float may not be the best approach here.
.nav li {
display: inline;
}
to
.nav li {
float: left;
}
http://codepen.io/anon/pen/OyVLOK
As in your css there is padding defined 10px.
.nav a{
text-decoration:none; padding:10px 5px; color:#000; font-family: sans-serif;
}
set it to
.nav a{text-decoration:none; padding:10px 2px; color:#000; font-family: sans-serif;}
Hope this help you.!
I need a cross-browser solution for having list item menu links with images. I'm using the default ASP.NET MVC 4 template and I have the following generated HTML:
<ul id="menu">
<li>
<a href="/Home/Item01">
<img src='/Images/MenuItem01.gif'/>
Menu Item 01
</a>
</li>
<li>
<a href="/Home/Item02">
<img src='/Images/MenuItem02.gif'/>
Menu Item 02
</a>
</li>
<li>
<a href="/Home/Item03">
<img src='/Images/MenuItem03.gif'/>
Menu Item 03
</a>
</li>
</ul>
The CSS:
ul#menu {
font-size: 1.3em;
font-weight: 600;
margin: 0 0 5px;
padding: 0;
text-align: left;
}
ul#menu li {
display: inline;
list-style: none;
padding-left: 15px;
}
ul#menu li a {
background: none;
color: #999;
text-decoration: none;
}
ul#menu li a:hover {
color: #333;
text-decoration: none;
}
Here's a Fiddle: http://jsfiddle.net/EY3ad/
I'd like to have each image above the text and centralized. I haven't done pure HTML and CSS in years so any help would be appreciated. :)
Are you looking for something like this?
The HTML:
<ul id="menu">
<li> <a href="/Home/Item01">
<img src='http://lorempixel.com/48/48'/>
<span>Menu Item 01</span>
</a>
</li>
<li> <a href="/Home/Item02">
<img src='http://lorempixel.com/48/48'/>
<span>Menu Item 02</span>
</a>
</li>
<li> <a href="/Home/Item03">
<img src='http://lorempixel.com/48/48'/>
<span>Menu Item 03</span>
</a>
</li>
</ul>
The CSS:
ul#menu {
font-size: 1.3em;
font-weight: 600;
margin: 0 0 5px;
padding: 0;
text-align: left;
}
ul#menu li {
display: inline-block;
list-style: none;
padding-left: 15px;
}
ul#menu li a {
background: none;
color: #999;
text-decoration: none;
position:relative;
}
ul#menu li a:hover {
color: #333;
text-decoration: none;
}
ul#menu li a img { display:block; margin:auto; }
ul#menu li a span{position:absolute; top:0; text-align:center;}
Try this:
ul.menu li{
background: url(images/<image-name>.gif) no-repeat;
list-style:none;
padding-left:4%;
margin-top:1%;
}
Trying to make just the services link orange on hover with a gray background- can't do it without changing all the menu items.
I can't click on the examples link after hovering over services.
.menu
{
margin:0;
padding:0;
}
.menu ul {
padding-top: 40px;
padding-left: 0px;
line-height: 0px;
margin-bottom: 0px;
float: right;
}
ul li {
display: inline;
}
ul li a:visited {
text-decoration: none;
}
ul li a:hover, .menu ul li .current{
color: #f7823b;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul { display: none; }
ul li a {
float: left;
font-size: 20px;
display: block;
text-decoration: none;
color: #ffffff;
padding: 20px;
margin-left: 1px;
white-space: nowrap;
}
li:hover ul {
display: block;
}
li:hover li {
float: none;
font-size: 11px;
}
ul ul li:hover a { background: #818285; }
/*li:hover li a:hover { background: #818285; width:100%; }*/
ul ul {
position: absolute;
z-index: 500;
margin:0;
padding-top: 0px;
}
ul ul li a
{
padding: 20px 0px 20px 5px;
width: 100%;
background: #818285;
}
<div class="socialmedia">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/facebook.png" <="" img="">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/twitter.png" <="" img="">
<a href="http://www.stumbleupon.com/stumbler/CyclonStrategies">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/stumbleupon.png" <="" img=""></a>
<a href="http://www.linkedin.com/company/cyclone-strategies-llc">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/linkedin.png" <="" img=""></a>
</div>
<div class="menu">
<ul id="menu">
<li>Home</li>
<li> About</li>
<li class="special"> Services
<ul>
<li>Digital Advertising</li>
<li>Promotion Management</li>
<li>Social Media</li>
</ul>
</li>
<li>Examples</li>
<li> Blog </li>
<li> Contact Us</li>
</ul>
</div>
<div style="clear:both"></div>
</div>
I've tried everything- any help is appreciated. Thanks!
http://jsfiddle.net/8ARm5/
Since the li containing services has a class special you can use this to target the element upon hover.
.special:hover{
color: orange;
background: grey;
}
Try to add hover on li not a element:
li:hover > a {
color: #f7823b;
}
Doing so the link keeps style definition even if you points links in submenu.
Take a look: http://jsfiddle.net/8ARm5/5/