I am able to display all the nested li's inline. What I don't understand is why there is a gap between About and Our Team li elements. I have already tried setting the margin and padding of both ul and li elements to 0.
<div ng-show = "buttonDisplay" id = "buttonDisplayContent">
<ul>
<li> Home </li>
<li class = "subLi"> About </li>
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
<li class = "nextToNested"> Blog </li>
<li class = "subLi"> Services </li>
<ul class = "nested">
<li> Design </li>
<li> Web </li>
<li> Learn </li>
<li> Invent </li>
</ul>
<li class = "nextToNested"> Portfolio </li>
<li> Contact </li>
</ul>
</div>
CSS
#buttonDisplayContent ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul a {
text-decoration: none;
color: #000;
font-size: 25px;
font-weight: bold;
}
#buttonDisplayContent ul ul a {
text-decoration: none;
color: lightgray;
font-size: 15px;
font-weight: bold;
}
.subLi {
float: left;
margin: 0;
padding: 0;
list-style-type: none;
}
.nested {
margin-left: 0;
}
.nested li {
display: inline-block;
padding-bottom: 6px;
padding-right: 1%;
padding-left: 1%;
padding-top: 8px;
}
#buttonDisplayContent ul li:hover {
background-color: black;
}
UPDATE
Thanks for all your help. I changed my HTML and CSS as follows. Li elements are still not aligning as desired. Here is a fiddle: https://jsfiddle.net/qvq87ke1/2/
HTML
<div ng-show = "buttonDisplay" id = "buttonDisplayContent" >
<ul>
<li> Home </li>
<li class = "subLi">About
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
</li>
<li class = "nextToNested"> Blog </li>
<li class = "subLi"> Services
<ul class = "nested">
<li> Design </li>
<li> Web </li>
<li> Learn </li>
<li> Invent </li>
</ul>
</li>
<li class = "nextToNested"> Portfolio </li>
<li> Contact </li>
</ul>
</div>
CSS
#buttonDisplayContent {
background-color: #141516;
width: 100%;
margin-top: 9%;
text-align: center;
position: absolute;
opacity: 0.9;
}
#buttonDisplayContent ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul a {
text-decoration: none;
color: #fff;
font-size: 50px;
font-weight: bold;
}
#buttonDisplayContent ul ul a {
text-decoration: none;
color: lightgray;
font-size: 40px;
font-weight: bold;
}
.subLi {
float: left;
margin: 0;
padding: 0;
list-style-type: none;
}
.nested {
float: right;
margin-left: 0;
}
.nested li {
display: inline-block;
padding-bottom: 6px;
padding-right: 1%;
padding-left: 1%;
padding-top: 8px;
}
#buttonDisplayContent ul li:hover {
background-color: black;
}
Your markup looks like it is incorrect. When nesting un-ordered or ordered lists they should be contained withing the li they will be creating a sub list for.
Like this:
<ul>
<li>One</li>
<li>Two
<ul>
<li>One - Sub Two</li>
<li>Two - Sub Two</li>
</ul>
</li>
<li>Three</li>
</ul>
You are adding your ul between the li:
<li class="subLi">About</li>
<ul class="nested">
<li>Our Team</li>
<li>Our efforts</li>
</ul>
<li class="nextToNested">Blog</li>
Updated answer based on updated question..
Try setting display:inside; on your nested <ul> and put your nested <ul> inside of the <li>
P.S. A screenshot or a fiddle (or at least your plain CSS) would be really helpful..
You should post a JSFiddle with your code, that would be easier to help you.
Otherwise, as a good practice, the UL nested nested should be in the previous LI (which should it parent so).
<li class = "subLi">
About
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
</li>
Maybe this is where the problem comes from.
If it can helps you:
Proper way to make HTML nested list?
Good Luck'
It's possible there is some padding/margin on the "a" element as well from the browser. Best practices is to import a reset.css file at the beginning of your project to clear all browser-applied CSS and style it on your own or using a framework.
I figured it out. I was floating the li elements unnecessarily.
<div ng-show = "buttonDisplay" id = "buttonDisplayContent" >
<ul>
<li> Home </li>
<li class = "subLi">About
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
</li>
<li class = "nextToNested"> Blog </li>
<li class = "subLi"> Services
<ul class = "nested">
<li> Design </li>
<li> Web </li>
<li> Learn </li>
<li> Invent </li>
</ul>
</li>
<li class = "nextToNested"> Portfolio </li>
<li> Contact </li>
</ul>
</div>
SASS
#buttonDisplayContent
background-color: #141516
width: 100%
margin-top: 9%
text-align: center
position: absolute
opacity: 0.9
#buttonDisplayContent
ul
list-style-type: none
padding: 0
#buttonDisplayContent
ul
ul
list-style-type: none
padding: 0
#buttonDisplayContent
ul
a
text-decoration: none
color: #fff
font-size: 50px
font-weight: bold
#buttonDisplayContent
ul
ul
a
text-decoration: none
color: lightgray
font-size: 40px
font-weight: bold
.subLi
//float: left
margin: 0
padding: 0
list-style-type: none
.nested
//float: right
margin-left: 0
display: inline
.nested
li
display: inline
padding-bottom: 6px
padding-right: 1%
padding-left: 1%
padding-top: 8px
#buttonDisplayContent
ul
li:hover
background-color: black
Related
when over menu the menu slips in HTML.
Codes and view:
https://codepen.io/anon/pen/XvrJpx
Demo:
.menuu {
position: absolute;
z-index: 1;
}
.menuu ul {
text-align: center;
}
.menuu>ul>li {
list-style: none;
float: left;
margin: 5px;
}
.menuu>ul>li>a {
text-decoration: none;
text-transform: uppercase;
background-color: white;
padding: 5px;
font-weight: 600;
font-size: 16px;
}
.menuu ul li a:hover {
color: white;
background-color: black;
}
.menuu ul li ul {
display: none;
}
.menuu li:hover>ul {
display: block;
}
.menuu ul li ul li a {
text-decoration: none;
}
.menuu>ul>li>ul>li {
list-style: none;
text-align: center;
margin: 5px;
padding: 5px;
}
.icerik {
position: absolute;
top: 75px;
}
<div class="menuu">
<ul>
<li>
Anasayfa
</li>
<li>
c
<ul>
<li>
c1
</li>
</ul>
</li>
<li>
a
</li>
<li>
Programlama
<ul>
<li>
<a>Android</a>
</li>
<li>
Java
</li>
<li>
Php
</li>
<li>
Html
</li>
<li>
Css
</li>
<li>
Javascript
</li>
</ul>
</li>
<li>
Turizm
</li>
<li>
Origami
</li>
<li>
Bebek
<ul>
<li>
Bebeklerin Aylık Gelişimi
</li>
</ul>
</li>
<li>
İletişim
</li>
</ul>
</div>
<div class="icerik">Önceden İçerik Aşağı kayıyordu email de dediğiniz gibi projeme position absolute ekledim kaymıyor. Teşekkür ederim. Şimdi Tek sorun Bebek Bölümü ve C bölümü üstüne gelince yana kayıyorlar ve yanındakini de kaydırıyorlar</div>
Menu C and menu Bebek have submenu. When over menu the menu slips. I doesn’t would slip.
How I can resolve this problem?
I need your help.
All you have to do is remove the browsers default ul styles, as it is adding 40px of padding to the left, and position the sub-menu items absolutely.
In your case, this will work:
ul li ul {
padding: 0;
position: absolute;
}
To make the sub-menu easier to read, I would recommend having a background and some sort of border. eg:
ul li ul {
padding: 0;
position: absolute;
background: white;
border: 1px solid black;
}
Remove > ul from
.menuu li:hover {
display: block;
}
so that menu doesnt slip
Hope this is what you need
.menuu {
position: absolute;
z-index: 1;
}
.menuu ul {
text-align: center;
}
.menuu>ul>li {
list-style: none;
float: left;
margin: 5px;
}
.menuu>ul>li>a {
text-decoration: none;
text-transform: uppercase;
background-color: white;
padding: 5px;
font-weight: 600;
font-size: 16px;
}
.menuu ul li a:hover {
color: white;
background-color: black;
}
.menuu ul li ul {
display: none;
}
.menuu li:hover {
display: block;
}
.menuu ul li ul li a {
text-decoration: none;
}
.menuu>ul>li>ul>li {
list-style: none;
text-align: center;
margin: 5px;
padding: 5px;
}
.icerik {
position: absolute;
top: 75px;
}
<div class="menuu">
<ul>
<li>
Anasayfa
</li>
<li>
c
<ul>
<li>
c1
</li>
</ul>
</li>
<li>
a
</li>
<li>
Programlama
<ul>
<li>
<a>Android</a>
</li>
<li>
Java
</li>
<li>
Php
</li>
<li>
Html
</li>
<li>
Css
</li>
<li>
Javascript
</li>
</ul>
</li>
<li>
Turizm
</li>
<li>
Origami
</li>
<li>
Bebek
<ul>
<li>
Bebeklerin Aylık Gelişimi
</li>
</ul>
</li>
<li>
İletişim
</li>
</ul>
</div>
<div class="icerik">Önceden İçerik Aşağı kayıyordu email de dediğiniz gibi projeme position absolute ekledim kaymıyor. Teşekkür ederim. Şimdi Tek sorun Bebek Bölümü ve C bölümü üstüne gelince yana kayıyorlar ve yanındakini de kaydırıyorlar</div>
I was wondering if anyone could see the bug in my code I am clearly not seeing. I am trying to create a simple navigation bar with a sub menu under 'brands' that appears on hover. Not sure if I am targeting the menu wrong, or what is happening. Any help would be appreciated. Thank you
<div class="nav">
<ul>
<li> Home </li>
<li> History </li>
<li> Brands </li>
<ul>
<li> Proprietary Brands </li>
<li> Licenced Brands </li>
<li> Distributed Brands </li>
</ul>
<li> Corp. Info </li>
<li> Investors </li>
</ul>
</div>
.nav{
width: 100%;
}
.nav ul{
font-size: 1.2em;
text-align: right;
padding-right: 5%;
padding-top: 2%;
list-style: none;
}
.nav li {
text-decoration: none;
padding-left: 2%;
display: inline-block;
}
.nav li li{
font-size: 1em;
}
.nav li ul{
position: absolute;
display: none;
width: inherit;
}
.nav li:hover ul{
display: block;
}
.nav li ul li{
display: block;
}
Your html just a bit wrong, it should be
...
<li>
<ul> ... </ul>
</li>
...
instead
...
<li> ... </li>
<ul> ... </ul>
<li> ... </li>
...
That mean you close li tag that should be the container of too soon, that make your csss for .nav li ul and anything with that become invalid because no structure like that exist in your html
I have learnt CSS online and I am new to web designing. Need some expert opinion here, I may have written something wrong or stupid. Please forgive that as I am a beginner.
Here are my CSS and HTML codes:
#menu {
float: left;
width: 1000px;
height: 30px;
background-color:#0066FF;
border-bottom: 1px solid #333;``
}
#menu ul {
float: left;
width: 1000px;
margin: 0;
padding: 7px 0 0 0;
list-style: none;
}
#menu ul li{
display:inline;
}
li ul {display: none;}
li:hover ul {display: block; position:relative;}
li:hover li a{background: #0066FF;}
#menu ul li a{
float: left;
padding: 0 20px;
font-size: 12px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #FFFFFF;
}
#menu li a:hover, #menu li .current{
color: #FFFF00;
}
#menu ul li:hover ul{
width: 150px;
white-space: nowrap
height: 10px;
text-align: center;
background:#0066FF;
}
<div id="menu">
<ul>
<li>Home</li>
<li>Quran
<ul>
<li>Translation</li>
<li>Tajweed</li>
<li>Tafseer</li>
<li>Qoutes</li>
</ul>
</li>
<li>Ahadees
<ul>
<li>Sahih Al-Bukhari</li>
<li>Sahih Muslim</li>
<li> Sunan Abu-Dawud</li>
<li>al-Tirmidhi</li>
<li>al-Nasa'i</li>
<li>Ibn Maja </li>
</ul></li>
<li>Wazaif
<ul>
<li>Allah's help</li>
<li>Rizzaq</li>
<li>Aulaad</li>
<li>Marriage</li>
</ul></li>
<li>Rights & Duties
<ul>
<li>As Parents</li>
<li>As Husband</li>
<li>As Wife</li>
<li>As Son</li>
<li>As Daughter</li>
</ul></li>
<li>Videos
<ul>
<li>Molana Tariq Jameel</li>
<li>Dr Zakir Naik</li>
<li>Dr Farhat Hashmi</li>
<li>Naat videos</li>
</ul></li>
<li>Quran & Science</li>
<li>Library
<ul>
<li>Masnoon Duain</li>
<li>Tib-e-Nabvi</li>
<li>Tafseer</li>
<li>Islamic comerace</li>
</ul></li>
<li>FAQs</li>
<li>Blogs</li>
<li>Contacts</li>
</ul>
</div>
It looks like the problem is that you haven't positioned the sub-menus properly.
Because the sub-menu have not been given position:absolute they remain in the documents flow and so disturb other elements when shown.
Adding position:absolute removes them from the flow and solves the problem.
In order to be positioned according to the parent li, that li needs to be a block (hence display:inline-block)(you could float the li too if that's your choice) and be given position:relative.
Here's a suggestion that should help you along the way.
#menu ul li {
display:inline-block;
position: relative;
}
li ul {
display: none;
position: absolute;
top:100%;
left:0;
}
li:hover ul {
display: block;
}
JSfiddle Demo
#menu {
float: left;
width: 1000px;
height: 30px;
background-color: #0066FF;
border-bottom: 1px solid #333;
``
}
#menu ul {
float: left;
width: 1000px;
margin: 0;
padding: 7px 0 0 0;
list-style: none;
}
#menu ul li {
display: inline-block;
position: relative;
}
li ul {
display: none;
position: absolute;
top: 100%;
left: 0;
}
li:hover ul {
display: block;
}
li:hover li a {
background: #0066FF;
}
#menu ul li a {
float: left;
padding: 0 20px;
font-size: 12px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #FFFFFF;
}
#menu li a:hover,
#menu li .current {
color: #FFFF00;
}
#menu ul li:hover ul {
width: 150px;
white-space: nowrap height: 10px;
text-align: center;
background: #0066FF;
}
<div id="menu">
<ul>
<li>Home
</li>
<li>Quran
<ul>
<li>Translation
</li>
<li>Tajweed
</li>
<li>Tafseer
</li>
<li>Qoutes
</li>
</ul>
</li>
<li>Ahadees
<ul>
<li>Sahih Al-Bukhari
</li>
<li>Sahih Muslim
</li>
<li> Sunan Abu-Dawud
</li>
<li>al-Tirmidhi
</li>
<li>al-Nasa'i
</li>
<li>Ibn Maja
</li>
</ul>
</li>
<li>Wazaif
<ul>
<li>Allah's help
</li>
<li>Rizzaq
</li>
<li>Aulaad
</li>
<li>Marriage
</li>
</ul>
</li>
<li>Rights & Duties
<ul>
<li>As Parents
</li>
<li>As Husband
</li>
<li>As Wife
</li>
<li>As Son
</li>
<li>As Daughter
</li>
</ul>
</li>
<li>Videos
<ul>
<li>Molana Tariq Jameel
</li>
<li>Dr Zakir Naik
</li>
<li>Dr Farhat Hashmi
</li>
<li>Naat videos
</li>
</ul>
</li>
<li>Quran & Science
</li>
<li>Library
<ul>
<li>Masnoon Duain
</li>
<li>Tib-e-Nabvi
</li>
<li>Tafseer
</li>
<li>Islamic comerace
</li>
</ul>
</li>
<li>FAQs
</li>
<li>Blogs
</li>
<li>Contacts
</li>
</ul>
</div>
I want to make this navigation that it looks like in tiled format. But here some white spaces coming at the end of the one row. Is it possible to make it form like a border surrounded by navigation & inside it navigation looks like proper tiles instead of some white space..
My Code..
.nav {
width: 960px;
margin: 50px auto;
border: 1px solid #06c;
display: table
}
.nav ul {
padding: 0;
margin: 0
}
.nav ul li {
list-style: none;
float: left;
border: 1px solid #06C;
font-family: Swis721 Cn BT;
font-weight: bold;
display: block
}
.nav ul li a {
text-decoration: none;
color: #06C;
padding: 10px 20px 10px 12px;
display: block
}
.nav ul li a:hover {
color: #fff;
background: #06c
}
<div class="nav">
<ul>
<li>ALL
</li>
<li>AGENCY
</li>
<li>AUTOMOBILES
</li>
<li>BANKING
</li>
<li>CONSUMER DURABLE & FMCG
</li>
<li>CONSULTING
</li>
<li>EDUCATIONAL
</li>
<li>FINANCIAL SERVICES
</li>
<li>HOSPITALITY
</li>
<li>INFRASTRUCTURE & REAL ESTATE
</li>
<li>INTERNATIONAL
</li>
<li>IT
</li>
<li>LEGAL
</li>
<li>MANFACTURING
</li>
<li>MARINE
</li>
<li>MEDIA
</li>
<li>OIL & GAS
</li>
<li>ONLINE
</li>
<li>OTHERS
</li>
<li>PHARMA
</li>
<li>RETAIL
</li>
<li>THEME PARK
</li>
</ul>
</div>
Probably this will work as i have given some special styles (css) to some 'li' however this will not provide 100% output as you want but still effective in such case..
.nav {
width: 970px;
margin: 50px auto;
border:0px solid;
display: table
}
.nav ul {
padding: 0;
margin: 0
}
.nav ul li {
list-style: none;
float: left;
border: 1px solid #06C;
font-family: Swis721 Cn BT;
font-weight: bold;
display: block;
min-width:5%;
width:auto;
text-align:center
}
.nav ul li a {
text-decoration: none;
color: #06C;
padding: 10px 20px 10px 12px;
display: block
}
.nav ul li a:hover {
color: #fff;
background: #06c
}
<div class="nav">
<ul>
<li>ALL
</li>
<li>AGENCY
</li>
<li>AUTOMOBILES
</li>
<li>BANKING
</li>
<li>CONSUMER DURABLE & FMCG
</li>
<li>CONSULTING
</li>
<li style="width:25%">EDUCATIONAL
</li>
<li>FINANCIAL SERVICES
</li>
<li>HOSPITALITY
</li>
<li>THEME PARK
</li>
<li>INTERNATIONAL
</li>
<li>IT
</li>
<li>LEGAL
</li>
<li>MANFACTURING
</li>
<li style="width:15%">MARINE
</li>
<li>MEDIA
</li>
<li>OIL & GAS
</li>
<li>ONLINE
</li>
<li>OTHERS
</li>
<li>PHARMA
</li>
<li>RETAIL
</li>
<li style="width:45%">INFRASTRUCTURE & REAL ESTATE
</li>
</ul>
</div>
Note : Keep in mind the output will be different in such case like change of fonts, or any navigation position change other than it is written now..
you can use this
.nav{
border:0px solid;
}
.nav ul li{
width:25%;/*according to your need you can increase or decrease*/
}
.nav ul {
padding: 0;
margin: 0
}
.nav {
width: 960px;
margin: 50px auto;
border: 1px solid #06c;
display: table;
padding: 0px 0px;
font-size: 100%;
}
.nav ul li {
list-style: none;
float: left;
border: 1px solid #06C;
font-family: sans-serif;
font-weight: bold;
min-width: 7.8%;
width: auto;
font-size: inherit;
text-align: center;
}
.nav ul li a {
text-decoration: none;
color: #06C;
adding: 10px 12px 10px 12px;
display: list-item;
WIDTH: AUTO;
min-width: 100%;
box-sizing: border-box;
}
.nav ul li a:hover {
color: #fff;
background: #06c
}
<div class="nav">
<ul>
<li>ALL
</li>
<li>AGENCY
</li>
<li>AUTOMOBILES
</li>
<li>BANKING
</li>
<li>CONSUMER DURABLE & FMCG
</li>
<li>CONSULTING
</li>
<li>EDUCATIONAL
</li>
<li>FINANCIAL SERVICES
</li>
<li>HOSPITALITY
</li>
<li>INFRASTRUCTURE & REAL ESTATE
</li>
<li>INTERNATIONAL
</li>
<li>IT
</li>
<li>LEGAL
</li>
<li>MANFACTURING
</li>
<li>MARINE
</li>
<li>MEDIA
</li>
<li>OIL & GAS
</li>
<li>ONLINE
</li>
<li>OTHERS
</li>
<li>PHARMA
</li>
<li>RETAIL
</li>
<li>THEME PARK
</li>
</ul>
</div>
I want to make my navigation bar with dropdown, but there is always distance on left side of the div dropdown. How do I remove that distance?
Here is the code of the navigation bar:
.navbar {
background-color: #6b6b6b;
margin:10px;
}
.navbar ul {
display: inline;
color: white;
font-family: "Agency FB";
font-weight: bold;
text-transform: uppercase;
list-style-type: none;
font-size: 24px;
}
.navbar ul li {
display: inline-block;
padding-right: 10px;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
}
.navbar ul li:hover {
background-color: #cccccc;
}
.navbar ul li ul {
display: none;
position: absolute;
margin-left:-10px;
margin-top:5px;
background-color:white;
color:#6b6b6b;
padding-left:-20px;
font-size:20px;
}
.navbar ul li ul li {
display: block;
}
.navbar ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
And here is the code of html navigation bar (without link):
<div class="navbar">
<ul>
<li>
Home
</li>
<li>
Category
<ul>
<li>Batik</li>
<li>Party</li>
<li>Office</li>
<li>Casual</li>
<li>Sport</li>
</ul>
</li>
<li>
Information
<ul>
<li>
About Us
</li>
<li>
Cara Belanja
</li>
<li>
Our Location
</li>
</ul>
</li>
<li>
Contact Us
</li>
</ul>
</div>
Thanks before :)
I remade it for you kinda, I'm sure you'll get the jist of it
<div id="nav">
<ul>
<li>Home</li>
<li>Category
<ul>
<li>Blah</li>
<li>Blah</li>
<li>Blah</li>
</ul>
</li>
<li>Information
<ul>
<li>Blah</li>
<li>Blah</li>
<li>Blah</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</div>
http://jsfiddle.net/un64F/3/ for css
I'm not sure I understand what you are asking for exactly but does adding padding-left: 0; to the .navbar ul style have the effect you want?