I want to create a 3 layer li ul menu but the 3 layer is covering the second layer. Can someone help me to align the 3 layer just right next to the second layer?
I very much appreciate your comments!
Best,
W
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<HEAD><title>bla</title>
<style type="text/css">
ul {
font-family : Arial, Verdana;
font-size : 18px;
font-weight: bold;
margin : 0;
padding : 0;
list-style : none;
z-index: -10;
}
ul li {
display : block;
position : relative;
float : left;
}
li ul {
display : none;
position : relative;
}
ul li a {
display : block;
text-decoration : none;
color : #ffffff;
border-top : 0 solid #ffffff;
padding : 6px 25px 6px 25px;
background : #033a96;
margin-left : 0;
white-space : nowrap;
}
ul li a:hover {
background : #9092c7;
}
li:hover ul {
display : block;
position : absolute;
z-index: 10;
}
li:hover li {
float : none;
font-size : 14px;
z-index: 10;
}
li:hover a {
background : #9092c7;
z-index: 10;
}
li:hover li a:hover {
background : #033a96;
z-index: 10;
}
</style>
</head>
<body >
<TABLE border=0 align="center" cellPadding=0 cellSpacing=0 valign="top">
<TBODY valign="top">
<TR valign="top">
<TD width="100%" bgcolor="#FFFFFF">
<TABLE height=19 valign="top" cellSpacing=0 cellPadding=0 width="100%" border=0>
<tr>
<td height=35 bgcolor="#033a96" >
<div id="menu_about" style="position: relative; z-index: 10;">
<ul id="menu">
<li ><a class="link" href="index.htm" >Layer 1</a>
<ul>
<li >Layer 2 blblb</li>
<li >Layer 2</li>
<ul >
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
</ul>
<li>Layer 2</li>
<li>Layer 2</li>
<li>Layer 2</li>
</ul>
</li>
<li><a class="link" href="#about" data-link="second">Layer 1</a>
<ul>
<li >Layer 2 blblb</li>
<li >Layer 2</li>
<ul >
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
</ul>
<li>Layer 2</li>
<li>Layer 2</li>
<li>Layer 2</li>
</ul>
</li>
</div>
</td>
</tr>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
I very much suspect you are using a WYSIWYG (like Dreamweaver) to generate your code?
Two notes on this:
Try to avoid inline styling
Don't use table-based lay-out except for tabular data. Use divs, nav, footer, header, and aside elements
For your solution:
Removed all the z-indexes, they aren't needed
You forgot to nest the 3rd level ul's in a second level li
Try to set properties like font-size on normal state elements, not hover (doesn't change)
I would advise naming your ul's and li's, or at least putting them in a logical order in your css, because this is quite messy.
The most important part that fixes your navigation is this css I added
ul li ul li ul {
margin-left: 100%;
}
It sets your nested ul's and their children's margin to the parent div's width.
So here is your complete new css:
ul {
font-family : Arial, Verdana;
font-size : 18px;
font-weight: bold;
margin : 0;
padding : 0;
list-style : none;
}
ul li {
display : block;
float : left;
}
ul li ul li ul {
margin-left: 100%;
}
li ul {
display : none;
}
ul li a {
display : block;
text-decoration : none;
color : #ffffff;
padding : 6px 25px 6px 25px;
background : #033a96;
white-space : nowrap;
}
ul li a:hover {
background : #9092c7;
}
li:hover ul {
display : block;
position : absolute;
}
li li {
float : none;
font-size : 14px;
}
li:hover a {
background : #9092c7;
}
li:hover li a:hover {
background : #033a96;
}
And your html (only the relevant part):
<div id="menu_about" style="position: relative; z-index: 10;">
<ul id="menu">
<li ><a class="link" href="index.htm" >Layer 1</a>
<ul>
<li>Layer 2 blblb</li>
<li>Layer 2</li>
<li>Layer 2
<ul >
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
</ul>
</li>
<li>Layer 2</li>
<li>Layer 2</li>
</ul>
</li>
<li><a class="link" href="#about" data-link="second">Layer 1</a>
<ul>
<li >Layer 2 blblb</li>
<li >Layer 2
<ul >
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
<li >Layer 3 Layer 3 Layer 3 Layer 3 </li>
</ul>
</li>
<li>Layer 2</li>
<li>Layer 2</li>
<li>Layer 2</li>
</ul>
</li>
</ul>
</div>
Related
I am trying to apply a class on the parent based on the child and it doesn't seem working.
Html
<ul>
<li class="nav-item">
<a class="nav-link active">Home</a>
</li>
<li class="nav-item">
<a class="nav-link">Profile</a>
</li>
</ul>
scss
.nav-item {
$root: &;
.nav-link.active {
border: solid 1px gray!important;
background-color: lightgray;
}
a {
color: black;
font-weight: bold;
}
&-.nav-link.active {
#{$root} {
border-left: solid 3px green;
}
}
}
You can't traverse up the DOM with CSS or SASS. You should instead put the active class on the parent:
.nav-item.active .nav-link {
border: solid 1px gray!important;
background-color: lightgray;
}
.nav-item a {
color: black;
font-weight: bold;
}
.nav-item.active {
border-left: solid 3px green;
}
<ul>
<li class="nav-item active">
<a class="nav-link">Home</a>
</li>
<li class="nav-item">
<a class="nav-link">Profile</a>
</li>
</ul>
Hello and thanks in advance for the help. Here's a link to the site in question: caulfield.co/test/originals.html
I'm attempting to create a responsive navbar in which the current dropdown-items appear as the standard nav-items after collapse.
See this image:
The dropdown-items are displaying as intended on desktop. On mobile, however, the separate dropdown is unnecessary. Here is how it displays with Bootstrap 4 out of the box:
Does anyone know of a convenient or custom solution to remove the dropdown once the navbar-collapse is in use on mobile etc such that the dropdown-items appear just like the navbar-items? Ideally, the "More" nav-link would display:none and the nav-items would continue from "Contact" to "Works On Display" seamlessly.
HTML:
<nav id="navHome" class="navbar navbar-expand-lg navbar-light sticky-top">
<div class="container-fluid max-width-940">
<a class="navbar-brand" href="index.html">
<img src="images/mb.svg" alt="Margaret Biggs" width="220px"/>
</a>
<button class="navbar-toggler togglerNoBorder" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse backgroundWhite" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="bio.html">Bio <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="originals.html">Originals</a>
</li>
<li class="nav-item">
<a class="nav-link" href="exhibition.html">Exhibition</a>
</li>
<li class="nav-item">
<a class="nav-link" href="prints.html">Prints</a>
</li>
<li class="nav-item">
<a class="nav-link" href="professionals.html">For Professionals</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact</a>
</li>
<li class="nav-item dropdown navDropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More
</a>
<div class="dropdown-menu navDropdown" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="works-on-display.html">Works on Display</a>
<a class="dropdown-item" href="poetry.html">Poetry</a>
<a class="dropdown-item" href="commissions.html">Commissions</a>
<a class="dropdown-item" href="blog.html">Blog</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
CSS:
.navbar-right {
float:right;
}
.togglerNoBorder{
border: 0px solid transparent;
}
.nav940{
max-width:940px;
margin:0 auto;
}
#navHome {
color:rgb(34, 34, 34);
font-size:13px;
font-weight:400;
line-height:16px;
text-transform:uppercase;
background-color:white;
height:60px;
box-shadow: 0 0 18px -4px #000;
}
#navHome a{
color:rgb(34, 34, 34);
}
#navHome a:hover{
color:#165fa5;
}
.navDropdown {
font-size:13px;
}
.navDropdown a:hover {
background-color:white;
}
.backgroundWhite{
background-color:white;
}
.nav-item{
padding-left:10px;
}
.dropdown-item {
padding-top:10px;
}
.navbar-brand {
margin-bottom:3px;
}
.dropdown-menu {
top:45px;
}
Use a #media query for mobile (<992px) to show the dropdown-menu as normal nav-links...
#media (max-width: 992px) {
.dropdown-toggle {
display: none;
}
.dropdown-menu {
display: block;
position: relative;
border-width: 0;
padding: 0;
margin: 0;
}
.dropdown-item {
padding: .5rem 0rem;
color: rgba(0,0,0,.5);
}
}
https://www.codeply.com/go/lAAQOwhAx0
Based on the excellent answer by #Zim, I modified the style a bit to fit one by side in a dark navbar. Tested with Bootstrap 5, but I guess it should work in Bootstrap 4 as well.
#media (max-width: 992px) {
.dropdown-toggle {
display: none;
}
.dropdown-menu {
position: relative;
display: contents;
border-width: 0;
padding: 0;
margin: 0;
color: transparent;
}
.dropdown-item {
color: white;
background-color: black;
display: inline;
}
}
I'm wondering if I can change the background's size of the text.
I mean, I have a navbar who contain an image with text over <ul><li> then
I added a display:flex; property.
All the links are separated by little bars.
When I mouse over the links, I change the background color or image with hover. However, the background doesn't fill the area between the little bars.
nav ul {
list-style-type: none;
display: flex;
margin-top: -30px;
margin-left: -30px;
}
nav li {
margin-right: 25px;
}
nav a {
font-size: 1.2em;
color: #666060;
text-decoration: none;
}
li .news:hover {
background: url("Images/news.png");
color: white;
}
<nav>
<img src="Images/NavBar.png" alt="NavBar" />
<ul>
<li>
<a href="#">
<img src="Images/Home.png" alt="Home" title="home" />
</a>
</li>
<li> News
</li>
<li> Chat
</li>
<li> Forum
</li>
<li> Contact
</li>
</ul>
</nav>
I have an issue related to css viewing of webview on Android 4.0.4
I have an list : using <ul> , <li> tags.
But when show on tablet 7 inches, some <li> has a different border size (> 1px).
Here is html :
<div id="cmSettingMenuList">
<ul>
<li >11111111</li>
<li >2222222</li>
<li >33333333</li>
<li >11111111</li>
<li >2222222</li>
<li >33333333</li>
<li >11111111</li>
<li >2222222</li>
<li >11111111</li>
<li >2222222</li>
<li >33333333</li>
<li >33333333</li>
<li >11111111</li>
<li >2222222</li>
<li >33333333</li>
</ul>
</div>
I use 1 css for it:
#cmSettingMenuList ul {
width: 580px;
list-style: none;
overflow: visible;
}
#cmSettingMenuList ul li {
padding-left: 2px;
height: 58px;
line-height: 58px;
border-bottom: 1px solid #9AB2E7;
background-size: 26px;
position: relative;
}
Here is display on tablet:
http://i.stack.imgur.com/RBsBL.png
It's not same size.
Do you have any solution for it.
THANKS
I have some padding and margin "errors" in firefox that I haven't figured out yet.
This is the test page where the screw-ups are happening.
This is the code for the HTML/CSS for the black caption box:
#caption{
position:relative;
display:block;
margin: -4px 0 0 0;
width: 650px;
height:68px;
background-color: black;
}
<div>
<div id="slider2">
<div>
<img src="img/urban.jpg" />
</div>
<div>
<img src="img/urban2.jpg" />
</div>
<div>
<img src="img/urban3.jpg" />
</div>
</div>
<div id="caption"></div>
</div>
This is the schedule code too:
#schedule{
height: 500px;
background-color: #ededed;
padding: 10px 10px 0px 10px;
}
#schedule h2{
text-align: center;
font-family: Arial;
color: rgba(0,0,0,.7);
}
.away{
color: red;
}
.gameline{
border-bottom: 1px solid rgba(0,0,0,.4);
}
.lineup > li{
margin: 0 0 7px 0;
}
#date{
margin: 20px 0 0 0;
list-style:none;
width: 70px;
float:left;
padding-right:30px;
font-family: 'Esteban', serif;
font-family: Arial;
font-weight: bold;
}
#date > .gameline{
border-bottom: 1px dashed rgba(0,0,0,0);
}
#opponent{
margin: 20px 0 0 0;
font-family: 'Esteban', serif;
font-family: Arial;
list-style:none;
}
<div id="right">
<div id="schedule">
<h2>2012 Schedule</h2>
<ul id="date" class="lineup">
<li>APR. 21</li>
<li class="gameline"></li>
<li>SEPT. 1</li>
<li class="gameline"></li>
<li>SEPT. 8</li>
<li class="gameline"></li>
<li>SEPT. 15</li>
<li class="gameline"></li>
<li>SEPT. 22</li>
<li class="gameline"></li>
<li class="away">SEPT. 29</li>
<li class="gameline"></li>
<li>OCT. 6</li>
<li class="gameline"></li>
<li class="away">OCT. 13</li>
<li class="gameline"></li>
<li>OCT. 20</li>
<li class="gameline"></li>
<li class="away">OCT. 27</li>
<li class="gameline"></li>
<li>NOV. 3</li>
<li class="gameline"></li>
<li>NOV. 10</li>
<li class="gameline"></li>
<li class="away">NOV. 17</li>
<li class="gameline"></li>
<li>NOV. 24</li>
</ul>
<ul id="opponent" class="lineup">
<li>Scarlet & Gray Game</li>
<li class="gameline"></li>
<li>Miami(Ohio)</li>
<li class="gameline"></li>
<li>Central Florida</li>
<li class="gameline"></li>
<li>California</li>
<li class="gameline"></li>
<li>UAB</li>
<li class="gameline"></li>
<li class="away">Michigan State</li>
<li class="gameline"></li>
<li>Nebraska</li>
<li class="gameline"></li>
<li class="away">Indiana</li>
<li class="gameline"></li>
<li>Purdue</li>
<li class="gameline"></li>
<li class="away">Penn State</li>
<li class="gameline"></li>
<li>Illinois</li>
<li class="gameline"></li>
<li>BYE</li>
<li class="gameline"></li>
<li class="away">Wisconsin</li>
<li class="gameline"></li>
<li>Michigan</li>
</ul>
</div>
Use a inside your LI (for the date) and style the label instead of trying to put two LIs side-by-side and getting them to match. Set a width and float:left for the label.