I have the following code :
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="utf-8">
<style>
.nav{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
background-color: #333;
}
.navLi{
display:inline;
}
.nav ol{
display:flex;
}
.nav a{
display:inline-block;
padding:10px;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
color:white;
}
.green{
background-color:green;
}
.blue{
background-color:blue;
}
.sideBar{
width:25%;
background:#333;
height: 850px;
}
.whiteColor{
color:white;
}
.paragraph{
padding: 20px;
line-height: 150%;
font-family: ariel;
}
.div1{
width: 75%;
background: white;
}
.textSize{
font-size: 1px;
}
.div2{
border:solid 1px;
display:flex;
}
.image{
float:left;
}
.maxDiv{
max-width: 1000px;
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
}
</style>
</head>
<body>
<div class="maxDiv">
<div id="myTopnav">
<ul class="nav">
<li class="navLi"> 0</li>
<li class="navLi"><a href="#news" >1</a></li>
<li class="navLi">2</li>
<li class="navLi">3</li>
<li class="navLi">4</li>
<li class="navLi">5</li>
<li class="navLi">6</li>
<li class="navLi">7</li>
</ul>
</div>
I want each of the li to have an ordered list below it (I know that it won't look pretty)
I tried making an ol element and some li inside of it and it looks weird.
When I do the ol inside each li and inside that ol I put some li it looks something like:
Code :
<li class="navLi"> 0
<ol>
<li class="navLi"><a href="#news" >1</a></li>
<li class="navLi"><a href="#news" >1</a></li>
</ol>
</li>
The ol inside the li looks not good as marked in the red square in the photo.
Any idea ?
You can hover 4 to see a submenu. I cleaned up the CSS, deleted classes/IDs I couldn't find being used.
The submenu has absolute positioning. Both menus are now defined using flexbox.
.nav {
display: flex;
justify-content: center;
align-items: flex-start;
list-style: none;
margin: 0;
padding: 0;
}
.navLi {
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
position: relative;
}
.nav ol {
display: none;
position: absolute;
background-color: red;
list-style: none;
padding: 0;
margin: 1px;
}
.navLi:hover ol {
display: flex;
justify-content: center;
align-items: center;
}
.navLi:hover ol li {
padding: 14px 16px;
}
a {
display: block;
padding: 14px 16px;
text-decoration: none;
background-color: #333;
font-size: 17px;
color: white;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.maxDiv {
max-width: 1000px;
margin: auto;
border: 3px solid green;
padding: 10px;
background-color: #333;
}
<div class="maxDiv">
<ul class="nav">
<li class="navLi">0</li>
<li class="navLi">1</li>
<li class="navLi">2</li>
<li class="navLi">3</li>
<li class="navLi">4
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
</ol>
</li>
<li class="navLi">5</li>
<li class="navLi">6</li>
<li class="navLi">7</li>
</ul>
</div>
Related
I am trying to keep this menu on one line, when the browser gets resized, some of them make a new line and go under the first line.
Here is my code:
.menu{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
.item{
float: left;
}
.item a{
display: inline-block;
color: white;
text-align: center;
padding: 16px 100px 16px 100px;
text-decoration: none;
white-space: nowrap;
}
.item a:hover{
background-color: #111111;
}
<header>
<ul class="menu">
<li class="item">Home</li>
<li class="item">Popular Categories</li>
<li class="item">Today's Special</li>
<li class="item">Locations</li>
</ul>
</header>
Just use display: flex. I recommend you to have a read here https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.menu{
display: flex;
list-style: none;
}
.item a{
padding: 20px;
text-decoration: none;
color: #000;
}
.item a:hover{
background-color: #000;
color: #fff;
}
<header>
<ul class="menu">
<li class="item">Home</li>
<li class="item">Popular Categories</li>
<li class="item">Today's Special</li>
<li class="item">Locations</li>
</ul>
</header>
So I'm building a website with a top menu but I ran into a problem. Basicly I want to have my menu centered but now its aligned to the left. Also the menu has a background color with would have to expand the whole width. I've tryed the answers describes here: How do I center the navigation menu?. But to no succes.
My CSS/HTML code is:
body {
font-family: FuturaLight;
background: white;
color: #333;
align-content: top;
margin: 0;
margin-bottom: 5em;
padding: 0;
}
.margin {
margin-left: 300px;
margin-right: 300px;
}
ul {
font-family: Futura;
font-size: 25px;
list-style-type: none;
position: fixed;
top: 61px;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
border-right: 1px solid yellowgreen;
border-top: 1px solid yellowgreen;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #333;
}
.active {
background-color: white;
color: green
}
.spacer {
width: 100%;
height: 95px;
}
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Scouts Permeke</TITLE>
<link rel="stylesheet" type="text/css" href="siteStyle.css">
</HEAD>
<BODY>
<H1>Scouts Permeke</H1>
<ul>
<li><a class="active" href="scouts_permeke_site.html">Home</a>
</li>
<li>Nieuws
</li>
<li>Contact
</li>
<li>Over
</li>
<li>Foto's
</li>
<li>Activiteiten
</li>
<li>Papierwerk
</li>
<li>Afspraken
</li>
<li>Uniform
</li>
<li>Technieken
</li>
<li>Jaarthema
</li>
<li>Rituelen
</li>
<li>Verhuur
</li>
<li>Inschrijvingen
</li>
</ul>
<div class="spacer">
</div>
<img src="groepsfoto.jpg" width="100%" " >
<div style="font-family: Futura ">
<H2>Welkom op onze vernieuwde site!</H2>
<H2>Kijk gerust even rond.</H2>
</div>
</BODY>
</HTML>
Many thanks in advance.
Add to your ul in your Stylesheet this:
text-align: center;
and replace from li
float: left;
with this
display: inline-block;
That could do it.
Hope this helps.
Have you considered flexbox as it will work depending on screen size and you can set it to be centre alligned.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Just note it wont work in older versions of ie
BODY {
font-family: FuturaLight;
background: white; color: #333;
align-content: top;
margin: 0;
margin-bottom: 5em;
padding: 0;
}
.margin {
margin-left: 300px;
margin-right: 300px;
}
ul {
font-family: Futura;
font-size: 25px;
list-style-type: none;
position: fixed;
top: 61px;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
display: flex;
justify-content:center;
flex-wrap: wrap
}
li {
float: left;
border-right:1px solid yellowgreen;
border-top:1px solid yellowgreen;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #333;
}
.active {
background-color: white;
color: green
}
.spacer
{
width: 100%;
height: 95px;
}
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Scouts Permeke</TITLE>
<link rel="stylesheet" type="text/css" href="siteStyle.css">
</HEAD>
<BODY>
<H1>Scouts Permeke</H1>
<ul>
<li><a class="active" href="scouts_permeke_site.html">Home</a></li>
<li>Nieuws</li>
<li>Contact</li>
<li>Over</li>
<li>Foto's</li>
<li>Activiteiten</li>
<li>Papierwerk</li>
<li>Afspraken</li>
<li>Uniform</li>
<li>Technieken</li>
<li>Jaarthema</li>
<li>Rituelen</li>
<li>Verhuur</li>
<li>Inschrijvingen</li>
</ul>
<div class="spacer">
</div>
<img src="groepsfoto.jpg" width="100%"" >
<div style="font-family: Futura">
<H2>Welkom op onze vernieuwde site!</H2>
<H2>Kijk gerust even rond.</H2>
</div>
</BODY>
</HTML>
I did some research with font size and boxes sizes. I created ul li and styling them with some CSS to make them looks like a table and stay inline. after the epic code i realize that each words are different like home, tutorial, contact us, and registration. all font have a different sizes and different paddings to use.
so this is my code...
i tidy this up so it's not looks like in my localhost. what i did was made the percentage like 3.5754% to set the padding to get the exact SAME width of the boxes. so 4 of them should be the same size of boxes.
at home i created padding like 5% or so.
at tutorial i created padding like 3.something%
and etc.
because each words has a different width and number of letters.
sorry for my English, please let me know if i'm confusing u guys..
but please help about this percentage and font thing. i really don't get it. if u guys have some article to read it's also help... because i'm still looking for it. ty guys :)
body {
margin: 0;
padding: 0;
}
.navigation {
top: 0;
width: 90%;
height: 120px;
background: #ccc;
margin: 0 auto;
text-align: center;
}
.nav-head {
padding-top: 5%;
padding-left: 0;
width: 100%;
margin:
/*0 7.2%*/
;
}
.nav a {
color: #e74c3c;
text-decoration: none;
font-size: 1em;
}
.nav {
list-style: none;
display: inline;
border: solid 1px #e74c3c;
margin-left: 0;
}
#nav1 {
padding: 1% 1%;
}
#nav2 {
padding: 1% 5.74%;
}
#nav3 {
padding: 1% 3%;
}
#nav4 {
padding: 1% 3%;
}
.nav:hover {
padding: 2.2% 5%;
border: solid 1px #e74c3c;
}
.nav.currentpage {
padding: 2.2% 5%;
border: solid 1px #e74c3c;
}
<nav class="navigation">
<ul class="nav-head">
<li class="nav" id="nav1">HOME
</li>
<li class="nav" id="nav2">REGISTRATION
</li>
<li class="nav" id="nav3">TUTORIAL
</li>
<li class="nav" id="nav4">CONTACT US
</li>
</ul>
</nav>
2 easy option I believe:
1) display:table + table-layout:fixed;
body {
margin: 0;
padding: 0;
}
.navigation {
width: 90%;
height: 120px;
background: #ccc;
margin: 0 auto;
text-align: center;
}
.nav-head {
display:table;
width:100%;
padding:0;
table-layout:fixed;
}
.nav a {
color: #e74c3c;
text-decoration: none;
font-size: 1em;
}
.nav {
display:table-cell;
border: solid 1px #e74c3c;
}
#nav1 {
}
#nav2 {
}
#nav3 {
}
#nav4 {
}
.nav:hover {
border: solid 1px ;
}
.nav.currentpage {
border: solid 1px ;
}
<nav class="navigation">
<ul class="nav-head">
<li class="nav" id="nav1">HOME
</li>
<li class="nav" id="nav2">REGISTRATION
</li>
<li class="nav" id="nav3">TUTORIAL
</li>
<li class="nav" id="nav4">CONTACT US
</li>
</ul>
</nav>
2) display:flex + flex:1;
body {
margin: 0;
padding: 0;
}
.navigation {
width: 90%;
height: 120px;
background: #ccc;
margin: 0 auto;
text-align: center;
}
.nav-head {
display:flex;
padding:0;
list-style-type:none;
}
.nav a {
color: #e74c3c;
text-decoration: none;
font-size: 1em;
}
.nav {
flex:1;
border: solid 1px #e74c3c;
}
#nav1 {
}
#nav2 {
}
#nav3 {
}
#nav4 {
}
.nav:hover {
border: solid 1px ;
}
.nav.currentpage {
border: solid 1px ;
}
<nav class="navigation">
<ul class="nav-head">
<li class="nav" id="nav1">HOME
</li>
<li class="nav" id="nav2">REGISTRATION
</li>
<li class="nav" id="nav3">TUTORIAL
</li>
<li class="nav" id="nav4">CONTACT US
</li>
</ul>
</nav>
Using percentages is not always the best idea, specially for padding. Instead, use min-width, a normal padding and control the gutter with font-size:0 on the parent and normal padding on the LIs
Here is the code:
.nav-head{
font-size:0;
}
.nav {
padding: 2px 5px !important;
min-width: 116px;
display: inline-block;
margin: 0 !important;
font-size: 15px;
border:1px solid red;
}
And here is the DEMO
Here is the explanation on the font-zero concept link
You can use Flexbox to help you in making all the items with same width.
body {
margin: 0;
padding: 0;
}
.navigation {
top: 0;
width: 90%;
height: 120px;
background: #ccc;
margin: 0 auto;
text-align: center;
}
.nav-head {
display: flex;
padding-top: 5%;
padding-left: 0;
width: 100%;
}
.nav a {
color: #e74c3c;
text-decoration: none;
font-size: 1em;
}
.nav {
list-style: none;
flex: 1;
border: solid 1px #e74c3c;
margin-left: 0;
padding-top: 2.2%;
padding-bottom: 2.2%;
}
.nav:hover {
border: solid 1px #e74c3c;
}
.nav.currentpage {
padding-top: 2.2%;
padding-bottom: 2.2%;
border: solid 1px #e74c3c;
}
<nav class="navigation">
<ul class="nav-head">
<li class="nav" id="nav1">HOME
</li>
<li class="nav" id="nav2">REGISTRATION
</li>
<li class="nav" id="nav3">TUTORIAL
</li>
<li class="nav" id="nav4">CONTACT US
</li>
</ul>
</nav>
I am developing website and I have a problem,
<li> elements aren't inside <ul>
#category_select {
margin: 0 auto;
width: 97%;
height: 50%;
list-style: none;
text-align: center;
border: 1px solid black;
}
#category_select li {
display: inline;
padding: 10px;
border: 1px solid black;
}
<ul id="category_select">
<li>Naslovnica</li>
<li>Elektronika</li>
<li>Bijela tehnika</li>
<li>Vozila</li>
<li>Sport</li>
<li>Dom i vrt</li>
<li>Odjeća i obuća</li>
<li>Moda</li>
<li>Literatura</li>
<li>Ručni radovi</li>
<li>Igračke</li>
<li>O nama</li>
<li>Kontakt</li>
</ul>
Please try this
#category_select li {
display: inline-block; //change display:inline to display:inline-block
padding:10px;
border:1px solid black;
}
DEMO
I'm trying to hide part of my menu. When I call display:none The entire menu disappears. I have id's to separate them so I don't get why this happens. Here's the code:
HTML:
<ul id="menu">
<li>Categories 1
<ul id="cat1">
<li>temp1</li>
<li>temp2</li>
<li>temp3</li>
</ul>
</li>
</ul>
CSS:
#menu {
background-color: #0000FF;
height: 20px;
padding: 15px 0 10px;
margin-bottom: 20px;
font: 12px 'DroidSansBold', Tahoma,sans-serif;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
box-shadow: 3px 2px 3px #000;
border-radius: 5px;
text-align: center;
}
#menu li{
display: inline-block;
}
#menu li a {
color: #fff;
text-decoration: none;
margin: 0 120px;
}
#cat1 li{
display: block;
padding: 10px;
}
#cat1 li a{
background-color: #0000FF;
padding: 10px;
border-radius: 5px;
}
Somewhat working demo: http://jsfiddle.net/ZfN7t/
When you're dealing with ul inside ul, it's usually easier to style if you give them different classes:
<ul id="menu">
<li class="menu-item">Categories 1
<ul id="cat1">
<li class="cat1-item">temp1</li>
<li class="cat1-item">temp2</li>
<li class="cat1-item">temp3</li>
</ul>
</li>
</ul>
Hide the temp1, temp2, temp3 like this:
.menu-item #cat1{
display:none;
}
To display on hover:
.menu-item:hover #cat1{
display:block;
}