i have simple css & html menu. it's fine, but i try to move some links to right, but when i try, all of these goes. i tried with inside - and still nothing. Can someone help me?
#forum-nav,
#forum-nav ul {
list-style: none;
padding-left: 20px;
padding-right: 20px;
width: 960px;
}
#forum-nav {
float: left;
}
#forum-nav > li {
float: left;
}
#forum-nav li a {
display: block;
height: 28px;
line-height: 2em;
padding: 0 1.0em;
text-decoration: none;
}
#forum-nav ul {
position: absolute;
display: none;
z-index: 999;
}
#forum-nav ul li a {
width: 80px;
}
#forum-nav li:hover ul.dropdown {
display: block;
}
/* Main menu
------------------------------------------*/
#forum-nav {
background:#597288;
}
#forum-nav > li > a {
color: #fff;
font-weight: bold;
}
#forum-nav > li:hover > a {
background: #889bac;
color: #fff;
}
.active {
background: #889bac;
color: #fff;
}
/* Submenu
------------------------------------------*/
#forum-nav ul{
margin-left: -20px;
}
#forum-nav ul a {
border-top: 1.5px solid #fff;
width: 100%;
padding-left: 20px;
padding-right: 20px;
background: #597288;
}
#forum-nav ul li a {
color: #FFF;
}
#forum-nav ul li:hover a {
background: #889bac;
}
#forum-nav ul li:last-child a {
border-bottom-right-radius: 2px;
border-bottom-left-radius: 2px;
}
and html:
<ul id="forum-nav">
<id="m_index">LINK ON LEFT</li>
<id="m_index">LINK ON LEFT</li>
AND I WANT IN ON RIGHT
<id="m_index">LINK ON RIGHT</li>
<id="m_index">LINK ON RIGHT</li>
</ul>
how can i move it, and still it will be works fine?
Firstly, you haven't actually defined any li elements within your ul so your markup is invalid, secondly you need to add a rule in your CSS to float the last two list items to the right.
Change your HTML to:
<ul id="forum-nav">
<li>LINK ON LEFT</li>
<li>LINK ON LEFT</li>
<li>LINK ON RIGHT</li>
<li>LINK ON RIGHT</li>
</ul>
And add to your CSS:
#forum-nav li:nth-child(3),#forum-nav li:nth-child(4){
float:right;
}
nb. if you want to float all children other than the first two to the right you can use:
#forum-nav li:nth-child(n+3){
float:right;
}
nb. per Chriz's answer- id attributes must be unique.
html
<ul id="forum-nav">
<li>LINK ON LEFT</li>
<li>LINK ON LEFT</li>
AND I WANT IN ON RIGHT
<li class='right'>LINK ON RIGHT</li>
<li class='right'>LINK ON RIGHT</li>
</ul>
css
.right { float:right; }
Note : give li open tag, and giving same id more element is not good practice, this CSS classright will do your job
Related
I'm training my CSS to pass to JS, but I'm worried because I'm having some problems doing a drop-down menu.
The concept I already get, but when I put it to work, it's kind of bugging, and moving the nav.
header {
overflow: auto;
}
header img {
float: left;
margin-left: 300px;
margin-top: 10px;
}
header img:hover {
opacity: 0.8;
}
nav {
float: right;
margin-right: 250px;
margin-top: 40px;
}
nav ul {
padding: 0px;
}
nav ul li {
display: inline;
margin-right: 50px;
border-right: 1px solid black;
}
nav ul li:last-child {
border-right: none;
}
nav ul li a {
color: black;
text-decoration: none;
font-weight: bold;
font-family: roboto;
margin-right: 50px
}
nav ul li a:hover {}
nav li ul {
display: none;
}
nav li:hover ul {
display: block;
position: relative;
}
nav li:hover li {
float: none;
}
<header>
<img src="logo.png">
<nav>
<ul>
<li>
Menu 01
<ul>
<li>Submenu 01</li>
</ul>
</li>
<li>Menu 02</li>
<li>Menu 03</li>
<li>Menu 04</li>
</ul>
</nav>
</header>
I sent the code with the img tag just to make clear the position of the stuff. I'm also learning the stuff, so it'll probably be very bad in others monitors.
nav li ul{
display: none;
position:absolute;
}
nav li:hover ul{
display: block;
}
thats all
I have a problem with the navigation bar. When I hover over About or Text on the nav bar it shows a spacing on the left side of the button, I want it the hover colour to contain the full width of the button.
https://jsfiddle.net/jdd3h0sf/3/
HTML:
<div id="nav">
<ul>
<li class="home">Home</li>
<li>About</li>
<li>Text ⌄
<ul class="submenu">
<li>One</li>
<li>Two</li>
<li>Three</li></li>
</ul>
<li>Work</li>
<li>Contact ⌄
<ul class="submenutwo">
<li>One</li>
<li>Two</li>
<li>Three</li></li>
</ul>
</ul>
CSS:
#nav {
background-color: #333;
height: 52px;
text-align: center;
margin: 0 auto;
letter-spacing: 1px;
text-transform: uppercase;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
}
#nav li {
border-right: 1.8px solid #191919;
height: auto;
width: 156.5px;
padding: 0;
margin: 0;
}
.home {
border-left: 1.8px solid #191919;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #444;
}
#nav ul li a, visted {
color: #ccc;
display: block;
padding: 15px;
margin: 0;
text-decoration: none;
}
#nav ul li a:hover {
color: #ccc;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #444;
border: 1px solid #333;
border-top: 0;
max-width: 169px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:visited {
color: #ccc;
}
#nav ul ul li a:hover {
color: #2980B9;
}
This is a part of display:inline-block;. If you want to keep them displayed inline-block, there are several different solutions (Read a css-Tricks article about it):
1 - Change your HTML format:
Change your <li>'s html like this:
<ul>
<li>
one</li><li>
two</li><li>
three</li>
</ul>
Or this:
<ul>
<li>one</li
><li>two</li
><li>three</li>
</ul>
Or even with comments, like this:
<ul>
<li>one</li><!--
--><li>two</li><!--
--><li>three</li>
</ul>
Or, just place all the li's on a single line:
<ul><li>one</li><li>two</li><li>three</li></li>
It is messy, yet effective.
2 - Negative margins:
Pretty straightforward:
li{
display: inline-block;
margin-right: -4px;
}
3 - Skip the closing tag:
This is actually perfectly fine in HTML5, li's do not have to have a closing tag.
<ul>
<li>one
<li>two
<li>three
</ul>
4 - Set the <ul>'s font size to 0:
ul {
font-size: 0;
}
ul li {
font-size: 16px;
}
5 - Or, just float the <li>'s:
Whatever floats your boat.
You are experiencing the dreaded inline-block spacing issue. In your fiddle, if you condense all of your li elements to be on the same line, the hover works as expected. The linked article outlines a few other options.
You can also just float the elements and that would resolve the issue.
#nav ul li {
float: left;
}
i'm creating a site for a bookstore and the designer wants to represent the menu as seperate piles of books. I have 4 piles with different amount of books (read menu items). I can create the menu with ul containing 4 li's (piles) which contain ul with li's (books). I have to stick to the ul and li notation because the menu will be created like that by Joomla.
The problem is that the books look like they float to the ceiling instead of lying on the shelf. How can i make the books lie down on the shelf?
Example: http://jsfiddle.net/cJ8an/
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: white;
background: red;
padding: 2px 10px;
}
a:hover {
color: black;
}
ul li {
float: left;
list-style: none;
}
ul li ul {
margin-right: 25px;
}
ul li ul li {
float: none;
margin-top: 5px;
}
hr {
clear: both;
height: 10px;
background: brown;
}
</style>
</head>
<body>
<ul>
<li>
<ul>
<li>HOME</li>
</ul>
</li>
<li>
<ul>
<li>BOEKENTIPS</li>
<li>MEER DAN BOEKEN</li>
<li>NIEUWS</li>
</ul>
</li>
<li>
<ul>
<li>LEZERSBLOG</li>
<li>BESTELFORMULIER</li>
<li>VERTELTHEATER</li>
<li>ANTROPOSOFIE</li>
</ul>
</li>
<li>
<ul>
<li>CONTACT</li>
<li>SCHOLEN</li>
<li>KINDEROPVANG</li>
</ul>
</li>
</ul>
<hr id="bookshelf" />
</body>
</html>
display:table used in a clever way seems to have worked. This will need some tweaking, but I'm sure you can take it from here. Good luck. http://jsfiddle.net/tmpQM/
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: white;
background: red;
padding: 2px 10px;
}
a:hover {
color: black;
}
ul {
display:table;
}
ul li {
display:table-cell;
list-style: none;
vertical-align:bottom;
}
ul li ul {
margin-right: 25px;
display:block;
}
ul li ul li {
float: none;
margin-top: 5px;
display:inline-block;
}
hr {
clear: both;
height: 10px;
background: brown;
}
I'm new to CSS and I'm trying to experiment with this code - if you want to see what it looks like go to this link: https://www.servage.net/blog/wp-content/uploads/2009/03/css-menu.html
Here's the code:
<html>
<head>
<title>CSS based drop-down menu</title>
<style type="text/css">
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul { display: none; }
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover { background: #617F8A; }
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #617F8A; }
li:hover li a:hover { background: #95A9B1; }
</style>
</head>
<body>
<ul id="menu">
<li>Home</li>
<li>About
<ul>
<li>The Team</li>
<li>History</li>
<li>Vision</li>
</ul>
</li>
<li>Products
<ul>
<li>Cozy Couch</li>
<li>Great Table</li>
<li>Small Chair</li>
<li>Shiny Shelf</li>
<li>Invisible Nothing</li>
</ul>
</li>
<li>Contact
<ul>
<li>Online</li>
<li>Right Here</li>
<li>Somewhere Else</li>
</ul>
</li>
</ul>
</body>
</html>
I have 2 questions about this:
How do I make this navigation bar on the right side of the page ?
Some of the tabs have drop down lists, when I add this margin-top: 50px to change the position of the navigation bar the dropdown lists move down like this
To move the #menu to the right and 50px down, add these properties
#menu {
position: absolute;
top: 50px;
right: 0px;
}
JSFiddle
If you want to use float and margin-top instead, you must restrict the margin to the #menu
#menu {
float: right;
margin-top: 50px;
}
JSFiddle
you seem to be targeting both the parent ul and the childs uls
try that:
ul {
margin-top:50px;
}
ul#menu {
float:right;
margin-top:0;
}
By adding the #menu after ul you target that specific UL and therefore override its basic ul properties
Add float property to your list:
#menu {
float: right;
}
If you are using WordPress or a static website then you have to place this code to move your navigation bar to the right side.
position: static;
top: 50px;
right: 0px;
color: black;
display: inline-block;
margin-right: 45em;
}
You can vary margin-right according to your website design.
If you still not able to move navigation on the right side then change the position: Like static, absolute, relative and inherit.
Im trying to make a vertical menu that produces a horizontal menubar on hover. So far I have kind of gotten it to work but there is a gap between the first li and the sub li.
For example, i want it to look like this:
x
xxxx
x
Instead, it looks like this:
x
x xxx
x
Here is my html:
<ul id="mainmenu">
<li>Top 1
<ul class="submenu">
<li>sub 11
<li>sub 12</li>
</ul>
</li>
<li>Top 2
<ul class="submenu">
<li>sub 21
<li>sub 22</li>
</ul>
</li>
</ul>
Here is my css:
#mainmenu {
margin: 0;
padding: 0;
list-style-type: none;
}
#mainmenu li {
clear: left;
}
#mainmenu a {
display: block;
overflow: hidden;
float: left;
background-color: white;
border: 1px solid black;
color: black;
font-weight: bold;
text-decoration: none;
width: 10em;
text-align: center;
margin:0;
}
.submenu {
list-style-type: none;
float: left;
display: none;
}
#mainmenu li a:hover {
display: block;
color: white;
background-color: black;
}
#mainmenu li a:hover+.submenu, .submenu:hover{
display: block;
display: inline;
}
.submenu li {
float: left;
clear: none !important;
}
.submenu li a:hover {
color: white;
background-color: black;
}
You need to add this:
.submenu {
margin: 0;
padding: 0
}
You have already done this for ul#mainmenu, but you've forgotten to do it for the ul.submenus.
Also, check your HTML. You're missing a couple of </li>. With a HTML5 doctype, you are allowed to omit them, but it's confusing (for humans) if you do so.
it's a little bit hard to see it in this form, but I have impression that you did not clear padding and margin for "li" element. you did it only for "a" and "ul" (mainmenu)