Why won't CSS hover effect cover only my dropdown menu? - html

In the first photo, my cursor is hovering over the slogan in the top right corner. If someone could tell me the adjustments I need to make so that my dropdown menu only comes down when I hover over it, it would be much appreciated.
HTML:
<ul class="dropdown">
<li>Menu</li>
<ul class="dropdownElements">
<li><a href="About.html"/>About</li>
<li><a href="Vintage.html"/>Vintage Products</li>
<li><a href="Antique.html"/>Antique Products</li>
<li><a href="Collectibles.html"/>Collectibles</li>
<li><a href="Contact.html"/>Contact Information</li>
</ul>
</ul>
CSS:
* {
margin: 0px;
padding: 0px;
}
div.header ul.dropdown {
position: absolute;
margin: auto;
list-style: none;
margin-left: 190px;
position: relative;
top: 40px;
}
div.header ul.dropdown li {
background-color: white;
height: 45px;
width: 135px;
line-height: 45px;
border-radius: 5px;
box-shadow: 1px 3px 5px black;
text-align: center
}
ul.dropdownElements li {
list-style: none;
}
div.header ul.dropdown li:hover {
background-color: #C5A06D;
transition: background linear 0.2s;
}
div.header ul ul {
visibility:hidden;
}
div.header ul:hover ul {
visibility:visible;
}
a:link {
text-decoration: none;
color: black;
}

See below. I have removed div.header at a few places because that element isn't in the HTML and stops the CSS from working.
Essential changes: list items of the top level menu positioned relative, submenu positioned absolute.
* {
margin: 0px;
padding: 0px;
}
ul.dropdown {
position: relative;
margin: auto;
list-style: none;
margin-left: 190px;
position: relative;
top: 40px;
}
div.header ul.dropdown li {
background-color: white;
height: 45px;
width: 135px;
line-height: 45px;
border-radius: 5px;
box-shadow: 1px 3px 5px black;
text-align: center
}
ul.dropdownElements {
display: none;
position: absolute;
top: 1em;
left: 0;
}
ul.dropdownElements li {
list-style: none;
}
div.header ul.dropdown li:hover {
background-color: #C5A06D;
transition: background linear 0.2s;
}
ul.dropdown li:hover ul.dropdownElements {
display: inline-block;
}
a:link {
text-decoration: none;
color: black;
}
<ul class="dropdown">
<li>Menu
<ul class="dropdownElements">
<li><a href="About.html" />About</li>
<li><a href="Vintage.html" />Vintage Products</li>
<li><a href="Antique.html" />Antique Products</li>
<li><a href="Collectibles.html" />Collectibles</li>
<li><a href="Contact.html" />Contact Information</li>
</ul>
</li>
</ul>

Related

HTML menu with CSS hover

I'm working on an HTML menu.
I have a problem with the "L3 submenu" (Item-221, Item-222).
When I "mouse in" to Item-22, L3 is displayed. It's ok.
But I can't click either Item-221 or Item-222.
If I "mouse out" Item-22, then L3 disappear.
Is there a solution for this using (only) CCS?
CSS code:
ul {
background-color: #c4c4c4;
list-style-type: none;
display: flex;
}
li {
padding: 5px 10px 5px 10px;
white-space: nowrap;
position: relative;
}
li:hover {
background-color: #02DB02;
}
.menu li>ul {
padding: 10px 13px 10px 13px;
position: absolute;
display: none;
top: calc(100%);
left: -8px;
}
#it_2:hover #ul_2, #it_22:hover #ul_3 {
display: block;
}
.menu>li>ul>li>ul {
top: -0.5em;
left: calc(100% + 10px);
}
HTML code:
<ul class="menu">
<li>Item-1</li>
<li id="it_2">Item-2
<ul id="ul_2">
<li>Item-21</li>
<li id="it_22">Item-22
<ul id="ul_3">
<li>Item-221</li>
<li>Item-222</li>
</ul>
</li>
</ul>
</li>
<li>Item-3</li>
</ul>
It is better to put padding on the list item so the sub-menu won't disappear
ul {
background-color: #c4c4c4;
list-style-type: none;
display: flex;
}
li {
padding: 5px 10px 5px 10px;
white-space: nowrap;
position: relative;
}
li:hover {
background-color: #02DB02;
}
.menu ul > li {
position:relative;
padding: 0 13px 0 13px;
}
.menu li>ul {
padding: 10px 0 10px 0;
position: absolute;
display: none;
top: calc(100%);
left: -8px;
}
#it_2:hover #ul_2, #it_22:hover #ul_3 {
display: block;
}
.menu>li>ul>li>ul {
position: absolute;
top: -0.5em;
left: calc(100%);
padding: 1em;
}
<ul class="menu">
<li>Item-1</li>
<li id="it_2">Item-2
<ul id="ul_2">
<li>Item-21</li>
<li id="it_22">Item-22
<ul id="ul_3">
<li>Item-221</li>
<li>Item-222</li>
</ul>
</li>
</ul>
</li>
<li>Item-3</li>
</ul>

My drop down menu won't stay open on hover

I am facing a problem whereby my drop down menu will not stay open when I hover my cursor over it. It sometimes stay open for a while and disappears. I have been trying to find solutions but I can't really tell what is the problem. Can anyone help me? I am new to CSS and HTML...
.arrow {
background-image: url(arrow.png);
background-repeat: no-repeat;
background-position: 100px;
}
.menu-area ul {
text-transform: uppercase;
list-style: none;
width: 145px;
margin-left: 10px;
padding: 0px;
position: absolute;
display: block;
box-shadow: 10px 10px 5px rgba(96, 96, 96, 0.8);
}
.menu-area ul ul {
margin-left: 1px;
position: absolute;
display: none;
left: 100%;
top: 0px;
}
.menu-area ul li {
border-bottom: 1px solid white;
background: MediumVioletRed;
position: relative;
display: block;
margin-bottom: 0px;
}
.menu-area ul li a {
font-family: verdana;
font-size: 12px;
font-weight: bold;
text-align: left;
color: white;
text-decoration: none;
padding: 10px 20px;
display: block;
}
.menu-area ul li:hover {
background-color: hotpink;
}
.menu-area ul li:hover>ul {
display: block;
}
<div class="menu-area">
<ul>
<li>Home</li>
<li><a class="arrow" href="#">Soalan</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
<li><a class="arrow" href="#">Topic</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Youre adding margin-left: 1px; on .menu-area ul ul which makes a 1px gap between the main ul and your submenu ul. If you hit that gap (which is pretty hard as its only 1px but still possible) the submenu closes.
Remove the margin so the ul's "touch" each other without gap for a safe transition between menu and submenu (You can add the same spacing as padding so you keep the 1px gap). Apart from this 1px gap everything runs smoothly.
In general i would recommend adding https://github.com/kamens/jQuery-menu-aim tho so the menu doesnt close when trying to reach for the last submenu item (where you most likely move out of the main-ul which makes the menu close instantly).
The hover style is not applied because of that 1px gap to the child elements. You could remove that margin and set a transparent border on the child ul
.arrow {
background-image: url(arrow.png);
background-repeat: no-repeat;
background-position: 100px;
}
.menu-area ul {
text-transform: uppercase;
list-style: none;
width: 145px;
margin-left: 10px;
padding: 0px;
position: absolute;
display: block;
box-shadow: 10px 10px 5px rgba(96, 96, 96, 0.8);
}
.menu-area ul ul {
margin-left: 0;
border-left: 1px solid transparent;
position: absolute;
display: none;
left: 100%;
top: 0px;
}
.menu-area ul li {
border-bottom: 1px solid white;
background: MediumVioletRed;
position: relative;
display: block;
margin-bottom: 0px;
}
.menu-area ul li a {
font-family: verdana;
font-size: 12px;
font-weight: bold;
text-align: left;
color: white;
text-decoration: none;
padding: 10px 20px;
display: block;
}
.menu-area ul li:hover {
background-color: hotpink;
}
.menu-area ul li:hover>ul,
.menu-area ul li>ul:hover {
display: block;
}
<div class="menu-area">
<ul>
<li>Home</li>
<li><a class="arrow" href="#">Soalan</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
<li><a class="arrow" href="#">Topic</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

Text next to the menu moving the menu when more text is added

i want to make my text on the left side of the menu not interact with my menu. Every time I add text to it, it moves my menu bars to the side. Any idea how to fix it? I tried fixed position for the text but its buggy and doesn't work in Mozilla Firefox.
JsFiddle: https://jsfiddle.net/3vetp3y3/
HTML:
<nav>
<span class="nadpis"> BUR </span>
<ul class="nav">
<li class="prve">PSI
<ul>
<li>Simoncik</li>
<li>Kodrla</li>
<li>Vajs</li>
<li>Hrebicek</li>
</ul>
</li>
<li class="druhe">&#9776
<ul>
<li> RPO </li>
<li> FLV
<ul>
<li>Simoncik</li>
<li>Kodrla</li>
<li>Vajs</li>
<li>Hrebicek</li>
</ul>
</li>
<li> FLC
<ul>
<li>Bednarikova</li>
<li>Dobrikova</li>
<li>Duracka</li>
</ul>
</li>
<li> QUA
<ul>
<li>Klco</li>
<li>Cisar</li>
</ul>
</li>
<li> HFX
</li>
<li> PDT
</li>
<li> RSH
</li>
<li> BUR
</li>
<li> SUHRN </li>
<li> INCI </li>
<li> JIRA </li>
<li> CHGT </li>
<li> TASK </li>
<li> VRS </li>
</div>
</ul>
</li>
</ul>
</nav>
CSS:
body,
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav {
display: inline-block;
position: fixed;
width: 100%;
text-align: center;
background-color: #111;
vertical-align: top;
top: -1px;
opacity: 1;
transition: 0.3s;
}
nav:hover {
opacity: 1!important;
background-color: #111;
transition: 0.3s;
}
span {
float: left;
margin-left: 3px;
}
span a {
text-decoration: none;
color: #2670CF;
background-color: #111;
font-family: 'Helvetica Neue', sans-serif;
font-size: 30px;
font-weight: bold;
}
.nav a {
display: block;
background: #111;
color: #fff;
text-decoration: none;
padding: 0.7em 1.7em;
text-transform: uppercase;
font-size: 85%;
letter-spacing: 3px;
position: relative;
}
.nav {
vertical-align: top;
display: inline-block;
width: 250px;
}
.nav li {
position: relative;
}
.nav > li {
display: inline-block;
}
.nav li:hover > a {
transition: 0.3s;
background-color: #3a3939;
color: #40d23b;
}
.nav ul {
position: absolute;
white-space: nowrap;
z-index: 1;
left: -99999em;
background-color: #000;
border: 2px solid #81D4FA;
border-top: none;
}
.nav > li:hover > ul {
left: auto;
min-width: 100%;
}
.nav > li li:hover > ul {
left: 100%;
top: -1px;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
right: 10px;
}
.prve {
max-width: 125px;
min-width: 90px;
border: 2px solid #81D4FA;
border-bottom: none;
border-top: none;
}
.druhe {
max-width: 14px;
min-width: 110px;
border-right: 2px solid #81D4FA;
}
use position: absolute instead of float
span.nadpis {
position: absolute;
left: 0;
}
with float, the element will still own an amount of space which will affect its sibling elements
with position: absolute, the element would position itself separately from its sibling elements

Creating vertical line at the center of li

I have created a html page with ul and li's to show some links and set up some background color to the li's. Now I want to add vertical line on the li's.
When I try to set up a image it is coming as shown in figure 1 but I want it to be as shown in figure 2.
figure 1
figure 2
What I have tried so far:
ul#sitemap1 {
list-style: none;
}
ul#sitemap1 li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
#sitemap1 li {
clear: left !important;
margin-top: 0px !important;
padding: 10px !important;
background: url('/Images/ConnectLine.JPG') no-repeat !important;
float: inherit;
}
ul#sitemap1 li a:hover {
background-color: Orange;
}
ul#sitemap2 {
list-style: none;
}
ul#sitemap2 li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
ul#sitemap2 li a:hover {
background-color: Orange;
}
ul#sitemap3 {
list-style: none;
}
ul#sitemap3 li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
ul#sitemap3 li a:hover {
background-color: Orange;
}
<h1>Innovations</h1>
<ul id="sitemap1">
Home
<li>Services</li>
<li>Organizational Change</li>
<li>kit</li>
<li>Sheets</li>
</ul>
<ul id="sitemap2">
Engagement
<li>Ideas</li>
<li>WorkSmart</li>
</ul>
<ul id="sitemap3">
Related Links
<li>GO-TIME</li>
</ul>
I suggest remove the id's form the CSS, no need to duplicate the same CSS just refer to the ul tag.
You can use :after pseudo-element to create the line.
Use :last-child to remove the line form the last item.
ul {
list-style: none;
}
ul li {
width: 220px;
position: relative;
margin-bottom: 20px;
}
ul li:after {
content: "";
position: absolute;
top: 90%;
left: 50%;
height: 25px;
background: black;
width: 4px;
border-radius: 5px;
border: 2px solid white;
z-index: 100;
}
ul li:last-child:after {
display: none;
}
ul li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
ul li a:hover {
background-color: Orange;
}
<h1>Innovations</h1>
<ul id="sitemap1">Home
<li>Services
</li>
<li>Organizational Change
</li>
<li>kit
</li>
<li>Sheets
</li>
</ul>
<ul id="sitemap2">Engagement
<li>Ideas
</li>
<li>WorkSmart
</li>
</ul>
<ul id="sitemap3">Related Links
<li>GO-TIME
</li>
</ul>
you can use a pseudo element ::after in the a child of li
Note you can only have li as direct childs of ul. otherwise it is invalid HTML
I tweaked your CSS removing duplicated properties.
ul {
list-style: none;
margin-top: 30px
}
ul li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
position: relative
}
ul li a::after {
position: absolute;
top: 100%;
left: 50%;
background: black;
width: 5px;
height: 100%;
content: ""
}
ul li:last-of-type a::after {
background: transparent;
height: 0
}
ul li a:hover {
background-color: Orange;
}
<div>
<h1>Innovations</h1>
<ul id="sitemap1">
<li>Home
</li>
<li>Services
</li>
<li>Organizational Change
</li>
<li>kit
</li>
<li>Sheets
</li>
</ul>
<ul id="sitemap2">
<li>Engagement
</li>
<li>Ideas
</li>
<li>WorkSmart
</li>
</ul>
<ul id="sitemap3">
<li>Related Links
</li>
<li>GO-TIME
</li>
</ul>
Try this, same you could try for sitemap 1 and 3.
ul#sitemap2 li::after{
content:'';
border:3px solid #111;
height:50px;
margin-left:110px;
}

dropdown menu not working in IE8 css

I have a drop down ul menu that is working in every browser except IE8. I have tried messing with the Z-index but haven't had much luck. When the user hovers over the first element, there is it displays the 2nd list as a drop down but then once the user tries to navigate to it, it disappears. Is there something else that I may be missing? Please help.
Here is the generated HTML:
<div id="topNav" class="topNavMenu">
<ul>
<li>Home</li>
<li><a rel="submenu1">Account Information</a></li>
<li><a rel="submenu2">Financial</a></li>
<li><a rel="submenu3">Pricing</a></li>
<li><a rel="submenu4">Operations</a></li>
<li><a rel="submenu5">Support</a></li>
<li><a rel="submenu6">Document Management</a></li>
<li><a rel="submenu7">Administration</a></li>
</ul>
<ul id="submenu1" class="ddsubmenustyle">
<li>Bill To/Ship To Search</li>
<li>Customer Account Information</li>
</ul>
<ul id="submenu2" class="ddsubmenustyle">
<li>Statement Search</li>
</ul>
<ul id="submenu3" class="ddsubmenustyle">
<li>Price Notification Summary</li>
</ul>
<ul id="submenu4" class="ddsubmenustyle">
<li>Online Environmental Compliance</li>
</ul>
<ul id="submenu5" class="ddsubmenustyle">
<li>Manage Profile</li>
<li>Administrative Interfaces</li>
</ul>
<ul id="submenu6" class="ddsubmenustyle">
<li>HES</li>
<li>Marketing Services</li>
<li>Sunoco University Classes</li>
<li>Credit Card Program Information</li>
</ul>
<ul id="submenu7" class="ddsubmenustyle">
<li>Create a New User</li>
<li>User Administration</li>
<li>Create a New Role</li>
<li>Maintain Menu Items</li>
<li>Refresh Menu</li>
</ul>
</div>
and the CSS:
/* Top navigation menu
topNavMenu = the class used on the menu div.
ddsubmenustyle = dropdown div css.
-----------------------------------------------------------*/
.topNavMenu ul
{
margin: 0;
padding: 0;
font: bold 12px Verdana;
list-style-type: none;
background: #C3C9D9; /* #153371 */
overflow: hidden;
width: 100%;
background-image:url(../images/menu_bg.png);
height:35px;
float:left;
}
.topNavMenu li
{
display: inline;
margin: 0;
z-index: 100;
}
.topNavMenu li a
{
float: left;
display: block;
text-decoration: none;
margin: 0;
padding: 0px 10px; /*padding inside each tab*/
border-right: 1px solid white; /*right divider between tabs*/
color: black;
background: #6c94b0; /* #153371 */
background-image:url(../images/menu_bg.png);
height:35px;
line-height:35px;
font-family:Verdana, Arial, Helvetica, sans-serif;
/*font-size:10px;*/
}
.topNavMenu li a:visited
{
color: black;
}
.topNavMenu li a:hover
{
background:#4D77A7; /*background of tabs for hover state */
color:White;
text-decoration:bold;
}
.topNavMenu a.selected
{
background: #4D77A7; /*background of tab with "selected" class assigned to its LI */
color:White;
}
.ddsubmenustyle, .ddsubmenustyle div
{ /*topmost and sub DIVs, respectively*/
font: normal 12px Verdana;
margin: 0;
font-weight:bold;
padding: 0;
position: absolute;
left: 0;
top: 0;
list-style-type: none;
background: white;
border-bottom-width: 0;
visibility: hidden;
z-index: 300;
}
.ddsubmenustyle ul
{
margin: 0;
padding: 0;
position: absolute;
left: 0;
top: 0;
list-style-type: none;
border: 0px none;
z-index: 300;
}
.ddsubmenustyle li a
{
display: block;
width: 170px; /*width of menu (not including side paddings)*/
color: white;
background-color: #aec6f6;
text-decoration: none;
padding: 4px 5px;
border-bottom: 1px solid white;
background-color:#4D77A7;
line-height:24px;
z-index: 300;
}
.ddsubmenustyle li ul li a, .ddsubmenustyle li ul li:first-child a
{
display: block;
width: 170px; /*width of menu (not including side paddings)*/
color: white;
background-color: #aec6f6;
text-decoration: none;
padding: 4px 5px;
border-bottom: 1px solid white;
background-color:#4D77A7;
line-height:24px;
background-image:none;
-moz-border-bottom-radius: none;
-webkit-border-bottom-radius: none;
-khtml-border-bottom-radius: none;
border-bottom-radius: none;
}
.ddsubmenustyle li:first-child a
{
display: block;
width: 170px; /*width of menu (not including side paddings)*/
color: white;
background-image:url(../images/arrow_first-child.png);
background-repeat:no-repeat;
background-position:top left;
background-color: #4D77A7;
text-decoration: none;
padding: 16px 5px 4px 5px;
border-bottom: 1px solid white;
background-color:#4D77A7;
}
.ddsubmenustyle li ul li:last-child a
{
-moz-border-bottom-right-radius: 0px;
-webkit-border-bottom-right-radius: 0px;
-khtml-border-bottom-right-radius: 0px;
border-bottom-right-radius: 0px;
-moz-border-bottom-left-radius: 0px;
-webkit-border-bottom-left-radius: 0px;
-khtml-border-bottom-left-radius: 0px;
border-bottom-left-radius: 0px;
border-bottom: none;
}
.ddsubmenustyle li ul li a:hover
{
background-color:#4D77A7;
color: 40638A;
line-height:24px;
}
.ddsubmenustyle li:last-child a
{
-moz-border-bottom-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-khtml-border-bottom-right-radius: 5px;
border-bottom-right-radius: 5px;
-moz-border-bottom-left-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-khtml-border-bottom-left-radius: 5px;
border-bottom-left-radius: 5px;
}
* html .ddsubmenustyle li
{ /*IE6 CSS hack*/
display: inline-block;
width: 170px; /*width of menu (include side paddings of LI A*/
}
.ddsubmenustyle li a:hover
{
background-color:#38587C;
color: white;
line-height:24px;
}
/* Neutral CSS */
.downarrowpointer
{ /*CSS for "down" arrow image added to top menu items*/
padding-left: 4px;
border: 0;
}
.rightarrowpointer
{ /*CSS for "right" arrow image added to drop down menu items*/
position: absolute;
padding-top: 3px;
left: 100px;
border: 0;
}
.ddiframeshim
{
position: absolute;
z-index: 500;
background: transparent;
border-width: 0;
width: 0;
height: 0;
display: block;
}
I tried to view this in Chrome but couldn't get it to work properly. Why are the sub-menus separate ul's? Perhaps you could try a nested list, like this:
<nav>
<ul class="top-nav">
<li>
Item 1
<ul class="sub-nav">
<li>Item 1a</li>
<li>Item 1b</li>
<li>Item 1c</li>
</ul>
</li>
<li>
Item 2
<ul class="sub-nav">
<li>Item 2a</li>
<li>Item 2b</li>
<li>Item 2c</li>
</ul>
</li>
</ul>
</nav>
And here's some CSS to make it work:
* {
margin: 0;
padding: 0;
list-style: none;
color: inherit;
text-decoration: none;
}
body {
font-family: sans-serif;
}
nav {
margin: 0 auto;
}
.sub-nav {
display: none;
}
.sub-nav li {
background: #333;
color: #fff;
padding: 4px 2px;
border-bottom: 1px solid #e0e0e0;
}
.top-nav {
overflow: hidden;
}
.top-nav > li {
float: left;
width: 100px;
padding: 4px 0;
background: #e0e0e0;
}
.top-nav > li:hover ul {
display: block;
}
Just tested in Chrome and IE, and worked fine.