I am trying to create a simple menu using li elements, but it only works on IE7, in FF and Chrome, the alignment get weird.
Also the :hover and :Active only works on IE7.
Could anybody give me a hit on this?
I would really appreciate it.
CSS:
#heading{
width: 700px;
height:auto;
margin: 0 auto;
background-color:#FFFFFF;
margin-top:5px;
margin-bottom:5px;
display:block;
}
#imglogo{
float:left;
}
#barDescription{
float:right;
}
#navigation{
text-align: right;
margin-top: 70px;
}
#navigation li{
float: right;
display: block;
text-align: center;
list-style-type: none;
}
#navigation li a{
color:#A08019;
background-image: url('Images/Menu1.png');
background-repeat:repeat-x;
background-position: center center;
text-decoration:none;
font-weight:bold;
display: block;
height:25px;
vertical-align:middle;
padding-right:10px;
padding-left:10px;
}
navigation li a:hover{
color:white;
background-image: url('Images/Menu2.png');
background-repeat:repeat-x;
background-position: center center;
text-decoration:none;
font-weight:bolder;
display: block;
height:25px;
vertical-align:middle;
padding-right:10px;
padding-left:10px;
}
navigation li a:active{
color:#B39A48;
background-image: url('Images/Menu2.png');
background-repeat:repeat-x;
background-position: center center;
text-decoration:none;
font-weight:bolder;
display: block;
height:25px;
vertical-align:middle;
padding-right:10px;
padding-left:10px;
}
HTML:
<div id="heading" >
<div id="imglogo">
<img id="logo" src="Images/logo.png" alt="logo" />
</div>
<div id="barDescription">
<h4>Especialidad en tapas,vinos y menus</h4>
<h5>Restaurante de cocina creativa tradicional. Vinos y tapas</h5>
</div>
<ul id="navigation">
<li>Contacto</li>
<li>Ubicacion</li>
<li>Reservas</li>
<li>Menus</li>
<li>Local</li>
</ul>
</div>
Suns of Suckerfish teaches how to get there. (Example.)
edit: Now that you posted the :active and :hover CSS, I can see you're missing a # in the beggining of the rule. So it is being applied to the "navigation" tags instead of the tags with "navigation" id. Change your CSS to add the # before "navigation":
#navigation li a:hover{
/* ... */
}
#navigation li a:active{
/* ... */
}
Related
I was wondering if anyone could help me with an issue I'm having. I wanted the text "Liam's Digital Portfolio" to be in the centre of the webpage at the top in line with the navigation bar text. In addition, I then wanted the navigation bar to be on the far right hand corner as shown within the codepen link http://codepen.io/ldocherty1/pen/qRowVK.
I have only started programming and this is my second day and really want to improve, apologies if the code is not in the correct structure.
Below is my HTML code, within the codepen is my CSS if needed.
<div id="Navagationbar">
<ul>
<li><b>HomePage</b></li>
<li><b>Portfolio</b></li>
<li><b>Contact Us</b></li>
<li><b><center>Liam's Digital Portfolio<center></b></li>
</ul>
</div>
</body>
</html>
Thanks,
Liam.
I wish you all the best with your coding journey :) I will give you an easy solution to get the desired effect. First off, cut the padding-top from the body in the css:
padding-top: 180px;
Now from your html, remove
<li><b><center>Liam's Digital Portfolio<center></b></li>
Since this is your page title, it is standard practice to have it inside of h1 tags. Then we can center it with simple css. The html will look like this:
<h1 class="title">Liam's Digital Portfolio</h1>
<div id="Navagationbar">
<ul>
<li><b>HomePage</b></li>
<li><b>Portfolio</b></li>
<li><b>Contact Us</b></li>
</ul>
</div>
And now we can simply add this to the css
.title{text-align:center;}
With the padding-top removed and this added, the title will be in the center of the page inline with the navigation bar. I see you have a lot of issues with your css so I suggest you go through a good tutorial, like this one from w3schools http://www.w3schools.com/css/ . I hope this helps, and good luck!
Make the HTML changes as below
<ul>
<li><b>HomePage</b></li>
<li><b>Portfolio</b></li>
<li><b>Contact Us</b></li>
<li style="position:absolute;right:45%"><b>Liam's Digital Portfolio</b></li>
</ul>
CSS changes as below
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
h1 {
font-family:Arial;
color:white;
font-size:10pt;
text-align:center;
}
li a:hover:not(.active) {
background-color:grey;
}
#Navagationbar {
font-family:Arial;
color:white;
font-size:10pt;
text-align:center;
}
#Navagationbar ul {
list-style:none;
float:right;
margin:0;
padding:0;
}
#Navagationbar ul li {
display:block;
list-style:none;
margin:0;
padding:0;
}
#Navagationbar ul li a {
display:block;
margin:0 0 0 1px;
padding:3px 10px;
color:white;;
text-decoration:none;
line-height:1.3em;
}
#Navagationbar ul li a:hover {
color:white;
}
#Navagationbar ul li a.active,
#Navagationbar ul li a.active:hover {
color:white;
}
body {
margin:0;
}
.page{
min-height:-590px;
background:linear-gradient(45deg, #999, #FFF);
}
#footer{
list-style:none inside none;
margin:0;
padding:0;
position:fixed;
right:0;
bottom:0;
left:0;
height:50px;
background-color:#1f1f1f;
font-size:0;
}
#footer li {
font-family:Arial;
float: right;
color:white;
font-size:10pt;
display:inline-block;
text-align:center;
height:50px;
padding:0 20px;
line-height:3.3;
border-right:1px solid #000;
border-left:1px solid #333;
}
#footer li {
font-family:Arial;
float: left;
color:white;
font-size:10pt;
display:inline-block;
text-align:center;
height:50px;
padding:0 20px;
line-height:3.3;
border-right:1px solid #000;
border-left:1px solid #333;
}
#footer li:last-child {
border-right:0;
}
body {
background:url('https://static.pexels.com/photos/34088/pexels-photo.jpg');
position:static;
height:400px;
background-attachment:fixed;
background-repeat:no-repeat;
background-size:cover;
}
So I've been desperately trying out every method I can find online for centering my nav bar links.
However whatever I do, they seem to either line horizontally (like I want) but to the left of the page (not what I want), or they line vertically (not what I want) but to the center of the page (what I want).
It seems no matter what margin, float, display settings I use in the CSS it never renders the navbar links in a horizontal line, in the center of the page.
My code is:
HTML:
<body>
<div class="maincontent">
<div class="navbar">
<div>
<h1>Tom Love</h1>
<ul>
<li> Home </li>
<li> About </li>
<li> Portfolio </li>
<li> Contact </li>
</ul>
</div>
</div>
</div>
</body>
CSS:
h1 {font-family:'Roboto Slab',sans-serif;
font-size:250%;
font-weight:300;
color:black;
text-align:center;
line-height:32px;
}
h1 span {font-size:60%;
font-family:'Roboto Slab',sans-serif;
}
.navbar {
clear:both;
margin:0 auto;
overflow:hidden;
padding:0;
text-align:center;
width:100%;
}
.navbar div {
float:center;
position:relative;
}
.navbar ul {
list-style-type: none;
text-align:center;
padding:10px;
margin:auto;
}
.navbar ul li {
padding:10px;
float:center;
}
.navbar ul li a {
text-decoration:none;
color:black;
margin:10px;
display:inline;
width:80px;
height:30px;
}
.navbar ul li a:hover {
text-decoration:none;
color:white;
background:black;
}
Apologies for any glaring mistakes in the code, it's my first attempt at building something outside of codeacademy and YouTube tuts.
Thanks in advance :)
Just add
display: inline;
to your .navbar ul li
Remove float:center (it does not exist)
Add display: inline or display: inline-block to .navbar ul li
If you want everything centered then place margin: 0 auto; on .maincontent and give it a width.
The differences between display values are listed here on the MDN.
It could be worth considering a CSS Reset or Normalise. (Do some research on the two options)
Have an example!
CSS
.maincontent {
margin: 0 auto;
width: 800px;
}
h1 {font-family:'Roboto Slab',sans-serif;
font-size:250%;
font-weight:300;
color:black;
text-align:center;
line-height:32px;
}
.navbar ul {
list-style-type: none;
text-align:center;
padding:10px;
}
.navbar ul li {
padding:10px;
display: inline;
}
.navbar ul li a {
text-decoration:none;
color:black;
margin:10px;
}
.navbar ul li a:hover {
text-decoration:none;
color:white;
background:black;
}
How can it be that there are so many answers on this topic and I still can't figure this out? I've been fiddling with the CSS on jsfiddle for hours and I still don't understand why my navigation bar won't center without going into a vertical list.
The html:
<div class='nav'>
<ul class='menu' id='menu'>
<li><a expr:href='data:blog.homepageUrl'>home</a></li>
<li><a class='drop-ctg' href='a'>MAKEUP</a>
<ul>
<li><a href='a'>EYES</a></li>
<li><a href='a'>LIPS</a></li>
<li><a href='a'>FACE</a></li>
</ul>
</li>
<li><a href='a'>SKINCARE</a></li>
<li><a href='a'>LIFESTYLE</a></li>
<li><a href='a'>DIY</a></li>
<li><a href='a'>CONTACT</a></li>
</ul>
</div>
and the CSS, I think:
*{
margin:0;
padding:0;
outline:0;
}
.nav {
width:950px;
height:auto;
border-bottom:1px solid #eee;
margin:10px auto 5px;
display:inline-block;
}
.menu {
width:auto;
list-style:none;
font:$pagenavifont;
text-align:center;
margin:0 auto;
}
.menu a {
float:left;
color:#999;
text-decoration:none;
text-transform:uppercase;
width:auto;
line-height:36px;
padding:0 20px;
}
.menu a:hover,li.menuhover a{
color:#111;
}
.menu li {
position:relative;
float:left;
width:auto;
}
.menu li:last-child {
background:none;
}
.menu ul{
display:none;
position:absolute;
top:36px;
left:0;
background:#fbfbfb;
display:none;
list-style:none;
}
.menu ul li{
float:none;
border-top:1px solid #e3e3e3;
border-right:1px solid #e3e3e3;
border-left:1px solid #e3e3e3;
width:auto;
background:none;
}
.menu ul li:last-child {
border-bottom:1px solid #e3e3e3
}
.menu ul li a{
float:none;
display:block;
background:none;
line-height:36px;
min-width:137px;
width:auto;
text-align:left;
padding-left:10px;
color:#444;
}
.menu ul li a:hover{
background:#fdfdfd;
color:#777;
}
I just started my blog today, and so far I've learned that getting rid of floats and putting inline-block might help, but there are so many that I really don't get which code applies to what. Any help is appreciated!
Here's the fiddle link: http://jsfiddle.net/vFDrV/9/
Here's the link to my blog: http://theprettyfoxes.blogspot.com/
if I understand correctly your question, its quite simple.
Add the follow code to your menu css class.
.menu { /* applying to a ul element */
/* ... your code ... */
display: inline-block;
}
You can read more about this at the Mozilla Docs
https://developer.mozilla.org/en-US/docs/Web/CSS/display
What it's going on when we add "inline-block" is this:
The element generates a block element box that will be flowed with
surrounding content as if it were a single inline box (behaving much
like a replaced element would)
Thats all!
remove float from following:
.menu a {
/*float: left;*/
color: #999;
text-decoration: none;
text-transform: uppercase;
width: auto;
line-height: 36px;
padding: 0px 20px;
}
.menu li {
position: relative;
/*float: left;*/
width: auto;
display: inline; /* <- add this */
}
Can't get my navigation to stay active using html and css. It just light up but does not stay active when pressed. What am I missing?
How do I make it stay active when pressed? Really need the help fast! Sorry for my bad code, I'm new to coding.
How do I type the active class? I tried to, but it did not work.
HTML
<div id="apaknavig">
<div id="menu2">
<ul>
<li>Uzņēmums</li>
<li>kontakti</li>
</ul>
</div>
</div>
CSS
#apaknavig {
Width: 200px;
height: 604px;
top:-613px;
position:relative;
font:14px Arial;
color:black;
float:left;
right:35px;
text-indent:12px;
display: block;
line-height:30px;
}
#menu2 ul{
list-style:none;
float: left;
font:14px Arial;
color:black;
right:90px;
text-decoration:none;
text-align:left; width:10px;
display: block;
line-height:30px;
margin-bottom:10px;
}
#menu2 a{
background-image: url(bildes/apak_navig.png);
display:block;
width: 196px;
height:34px;
font:14px Arial;
color:black;
float:left;
right:90px;
text-decoration:none;
display: block;
line-height:30px;
margin-bottom:3px;
}
#menu2 a:hover{
background-image: url(bildes/apak_navig_green.png);
color:white;
font:14px Arial;
color:black;
text-decoration:none;
display: block;
line-height:30px;
}
Just change #menu2 a:hover{ to #menu2 a:hover, #menu2 a:active {.
You just have to add #menu2 a:active to the CSS.
#menu2 a:hover,#menu2 a:active{
background-image: url(bildes/apak_navig_green.png);
color:white;
font:14px Arial;
color:black;
text-decoration:none;
display: block;
line-height:30px;
}
I tried it but it just does not work. It continues to just hover, but does not stay active when I press it.
Can someone help me to center the "ul" in the "div" vertically and horizontally according the code below?
Thank you very much!
<div id="nav">
<ul>
<li><a class="top" href="#top"><span></span></a></li>
<li><a class="bottom" href="#bottom"><span></span></a></li>
<li><a>Link 1</a></li>
<li><a>Link 2</a></li>
</ul>
</div>
css
#nav {
height:35px;
border-bottom:1px solid #ddd;
position:fixed;
top:0px;
left:0px;
right:0px;
background:#fff url(../images/navigation/nav.png) repeat-x center left;
z-index:999999;
}
#nav ul {
list-style:none;
margin:auto;
float:left;
padding:0;
display: block;
}
#nav ul li {
display:inline;
float:left;
margin:0px 2px;
}
#nav a {
font-size:13px;
font-weight:bold;
float:left;
padding: 2px 4px;
color:#999;
text-decoration: none;
border:1px solid #ccc;
cursor: pointer;
background:transparent url(../images/navigation/overlay.png) repeat-x center left;
height:16px;
line-height:16px;
}
#nav a:hover {
background:#D9D9DA none;
color: #fff;
}
#nav a.top span, #nav a.bottom span {
float:left;
width:16px;
height:16px;
}
#nav a.top span {
background:transparent url(../images/navigation/top.png) no-repeat center center;
}
#nav a.bottom span {
background:transparent url(../images/navigation/bottom.png) no-repeat center center;
}
Use display: inline-block combined with text-align: center. This is good because it will continue to work if you add or remove links.
See: http://jsfiddle.net/thirtydot/VCZgW/
The important changes I made:
#nav {
/*height:35px;*/
padding: 6px 0;
}
#nav ul {
/*float:left;*/
text-align: center;
}
#nav ul li {
/*float:left;*/
vertical-align: top;
display: inline-block;
}
This won't directly solve your problem, but these are my go to links for css centering issues
Horizontal
http://dorward.me.uk/www/centre/
Vertical
http://phrogz.net/css/vertical-align/index.html
The right thing to do is this:
you put style on a ul {display:table; margin:0 auto;}
that is all ;)