CSS 3 Gradient Confines Nested List to Parent UL - html

I have a horizontal unordered list which I'm using as a main menu, with a nested unorderd list which I'm using as a dropdown sub menu.
I'm using a CSS 3 Gradient on the Main Menu but it is causing the sub menu to be confined to the list in IE. What I mean is, if I increase the height of the list items I can see part of the sub menu but this obviously ins't an option.
I have heard about someone encountering this problem before and was wondering if anyone could help.
This is the HTML of the menu.
<div id="menu">
<div class="mainmenu">
<ul>
<li>
<a href='path'>Home</a>
</li>
<li>
<a href='path'>Country Garden</a>
</li>
<li>
<a href='path'>Inner City Garden</a>
</li>
<li>
<a href='path'>Winter Garden</a>
<ul>
<li>
<a href='path'>Featured Products</a>
</li>
<li>
<a href='path'>Best Sellers</a>
</li>
<li>
<a href='path'>Special Offers</a>
</li>
</ul>
</li>
<li>
<a href='path'>Water Garden</a>
</li>
<li>
<a href='path'>Window Box</a>
</li>
</ul>
</div>
</div>
This is the CSS that controls it.
.mainmenu{
clear: both;
height: 42px;
margin: 0;
width: 980px;
}
.mainmenu ul{
list-style: none;
margin: 0;
padding: 0;
text-align:center;
}
.mainmenu li{
display: inline-block;
margin: 0;
padding: 0;
z-index:1000;
height: 42px;
position: relative;
}
.mainmenu li a{
display: inline-block;
height: 33px;
padding: 9px 25px 0;
}
.mainmenu ul ul{
float: left;
left: 0;
padding: 5px 0 10px 0;
position: absolute;
text-align: left;
top: 42px;
width: 200px;
z-index: 10000;
}
.mainmenu li li{
clear: both;
text-align: left;
height: 30px;
}
.mainmenu ul li ul{
display:none;
}
.mainmenu li ul li a {
height: auto;
padding: 2px 25px;
width: 150px;
}
.mainmenu li ul li a, .mainmenu li.over li a {
text-decoration: none !important;
}
.mainmenu li:hover ul, .mainmenu li.over ul {
display: block;
}
This is style that causes the problem in IE8.
.mainmenu li{
background-color: #25abec;
background-image:-moz-linear-gradient(top,#25abec,#1984b8);
background-image:-webkit-gradient(linear,left top,left bottom,from(#25abec),to(#1984b8));
filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#25abec,endColorStr=#1984b8);
}
It's the final line that causes the problem. If I take it out it works but looks wrong. The problem is in IE and Opera but it works in Firefox, Google Chrome and Safari.

The IE filter can indeed cause various issues at times. My recommendation is to not put the filter on at all, letting IE8 just have the plain default background-color, and then perhaps using SVG to get the background for IE9.

Related

Nav UL items stretch across page

I'm working on a simple static page and almost have my navigation bar right. Right now, the menu items are stretching across the width of the entire nav bar, rather than staying contained in their "list area" if that makes sense. I feel like I've tried everything, and I think it has something to do with the z-index I have on the nav and photo carousel (so that the nav menu items show up on top of the carousel) and the positioning, but I can't figure it out.
nav ul {
background: #A6CE4F;
box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
padding: 0px;
list-style: none;
position: relative;
display: inline-table;
width: 100%;
display: table;
}
nav ul ul {
display: none;
width: 100%;
background: #f37b35;
border-radius: 0px;
padding: 0;
position: absolute;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover > ul {
display: block;
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block;
padding: 25px 40px;
color: #1f354b;
}
nav ul ul li {
float: none;
border-top: 1px solid #fff;
border-bottom: 1px solid #fff;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
nav ul ul li a:hover {
background: #e2550e;
}
nav ul ul ul {
position: absolute;
left: 100%;
top: 0;
}
<nav style="position: relative; z-index: 2;">
<ul>
<li>
ICAB Leadership Group
<ul>
<li>Requirements
</li>
<li>Roles & Responsibilities
</li>
</ul>
</li>
<li>
Site Cabs
<ul>
<li>Community Input
</li>
<li>Cross Network Collaborations
</li>
</ul>
</li>
<li>
Community Toolbox
<ul>
<li>Community engagement templates and documents
</li>
<li>Network and Community fact sheets
</li>
<li>Training materials
</li>
<li>FAQs
</li>
<li>Community Research Resources
</li>
<li>Acronyms
</li>
<li>Email Alias Lists
</li>
</ul>
</li>
<li>
Contacts & Email Lists
</li>
</ul>
</nav>
It's because you have width: 100% set to .nav ul ul. If you want the width to remain variable, set width: 100% to width: auto in .nav ul ul
Example here: http://codepen.io/anon/pen/MaRJXZ
That's happening because you have width set to 100% to your dropdown ul.
Add a width like this:
width: auto;
See fiddle here.

Dropdown links do not display on hover

After a long break from HTML/CSS, I recently created a menu with dropdown links using a method I have used once before, and was surprised to find that this application of them is not working.
I used this
ul li:hover ul{ display:block;}
to "turn on" my menus when hovering, but they simply never appear. I have tried adding div tags around various blocks of code to no avail. What tricks am I missing?
jsfiddle here: https://jsfiddle.net/qccs4mLL/
Your html isn't align with your css selector.
ul.menu li:hover > ul {
display: block;
background: green;
}
There isn't any ul element that is direct child of li element. You can change your html so ul is direct child of li element.
body {
margin: 0px;
}
a {
text-decoration: none;
width: 8em;
/*width of each link*/
}
/*format list*/
ul {
text-align: center;
margin: 0;
padding: 0;
list-style: none;
}
ul.menu {
height: 2.5em;
width: 100%;
padding: 0;
margin: 0;
border: 0;
background-color: #454545;
}
ul.menu li {
float: left;
position: relative;
}
ul.menu li a {
cursor: pointer;
display: block;
color: white;
line-height: 2.5em;
padding: 0 10px;
}
ul.menu ul {
background: #555;
display: none;
position: absolute;
left: 0;
top: 100%;
}
ul.menu li:hover {
background: red;
}
ul.menu li:hover > ul {
display: block;
background: green;
}
<body>
<!--Heading-->
<!--Should change when scrolled down/on mobile-->
<h1 class="heading">Title</h1>
<!--Create Menus-->
<nav>
<ul class="menu">
<li>link1
<ul>
<li>sublink1
</li>
</ul>
</li>
<!--menu options with sub options have dropdown on computer, may unfold with tap on mobile or just be a click since they all go to one page maybe? maybe go with unfolding.-->
<li>link2
<ul>
<li>sublink1
</li>
<li>sublink2
</li>
<li>sublink3
</li>
<li>sublink4
</li>
</ul>
</li>
<li>link3
</li>
<li>link4
</li>
</ul>
</nav>
</body>

drop down menu won't go horizontal

I'm making my first website with HTML and CSS and it's all gone fine, but now I'm stumped. I made a pretty typical horizontal menu under my header using the inline command in my CSS. Then I decided I wanted drop down elements on my menu, so deleted all my menu css and copied in some new from a tutorial for horizontal drop down menus online. The drop downs work perfectly, but now, for some reason, my menu is vertical! Any ideas how I can make it horizontal again? Hoping it should be relatively easy! Thanks so much.
Here's my html (in my .html sheet)
<div class="header">
<div class="topimagebox">
<img src="images/header1.jpg" class="topimage"; alt="Nets drying at Folkestone harbour";>
</div> <!--topimagebox-->
<ul id="Menu">
<li >Home</li>
<li >About
<ul>
<li >Context</li>
<li >The Project</li>
<li >People</li>
</ul>
</li>
<li >News</li>
<li >Publications</li>
<li >Case Studies</li>
<li >Contact
<ul>
<li >Contact</li>
<li >Get Involved</li>
</ul>
</li>
<li class="menu" >Impact</li>
<li class="menu">Links</li>
</ul>
</div> <!--header-->
And here's my CSS (in a seperate stylesheet)
div.header {
background-color: white;
width: 1000px;
margin-bottom: 10px;
}
ul {
padding: 0px;
padding-top: 20px;
padding-bottom: 20px;
margin: 0px;
}
li {
width: 850px;
margin:0px auto 0px auto;
}
#Menu {
margin: 0;
padding: 0;
height: 1em; }
#Menu li {
list-style: none;
float: left; }
#Menu li a {
display: block;
padding: 3px 8px;
background-color: #5e8ce9;
color: #fff;
text-decoration: none; }
#Menu li ul {
display: none;
width: 10em; /* Width to help Opera out */
background-color: #69f;}
#Menu li:hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0; }
#Menu li:hover li {
float: none; }
#Menu li:hover li a {
background-color: #69f;
border-bottom: 1px solid #fff;
color: #000; }
#Menu li li a:hover {
background-color: #8db3ff; }
I put in my generic ul and li in case that had something to do with it. If anyone can help, I'd really appreciate it.
li {
width: 850px; //<-- This is your problem.
margin:0px auto 0px auto;
}
If you remove the width the li-elements will float next to each other, until there isnt anymore room for it to float, then it will break onto a new row.

Offset drop-down menu in IE7

I'm having some issues with a drop-down menu in IE7.
It works fine in all other browsers but appears offset in IE7 for some reason. Any ideas?
Please see the menu code below and the computed CSS from Firebug as well as images demonstrating the issues.
Correct Menu
Offset Menu
HTML
<ul id="coolMenu">
<li class="">
<a class="donate" href="#">
User Options
<span class="downarrowclass"></span>
</a>
<ul id="style_me" style="display: none;">
<li>
Candidate Panel
</li>
<li>
Access details
</li>
<li>
Personal details
</li>
<li>
History
</li>
<li>
Withdraw application
</li>
<li>
Jobs by e-mail
</li>
<li>
Log off
</li>
</ul>
</li>
</ul>
CSS
#coolMenu,
#coolMenu ul {
list-style: none;
}
#coolMenu {
float: right;
}
#coolMenu > li {
/*float: left;*/
}
#coolMenu li a {
display: block;
text-decoration: none;
color: #ffffff;
width: 100px;
text-align: center;
}
#coolMenu ul {
position: absolute;
display: none;
z-index: 999;
}
#coolMenu li:hover ul {
display: block;
}
.dropdown a li{
color: #124162 !important;
}
#coolMenu li #style_me li a{
color: #124162 !important;
width: 140px !important;
}
#coolMenu li #style_me li a:hover {
color: #ffffff !important;
}
If it helps, there appears to be some form of offset present in the IE developers tab:
Also, here is the computed code in iedeveloper for ul coolmenu.
This can be fixed by targeting IE7 specifically using the following code:
Html.ie7 #coolMenu ul {
top: 59px;
left: 71px;
}

CSS - looking for a good way to display <LI> options with posotion:absolute

I have the code:
<div class='selectAnAction'>
<ul>
<li class='actionSelect'><span>Select an Action</span></li>
<li class='action' onclick='location.href=\"/post.php?key=".$row['hash']."\";'>post</li>
<li class='action' onclick='location.href=\"/adpreview.php?key=".$row['hash']."\";'>preview</li>
<li class='action' onclick='location.href=\"/adupdate.php?key=".$row['hash']."\";'>edit</li>
<li class='action' onclick='location.href=\"/addelete.php?key=".$row['hash']."\";'>archive</li>
</ul>
</div>
And I have this CSS:
.selectAnAction ul {
display: block;
background-image: url("/images/selectAnAction-dropdown.png");
background-position: 0px -200px;
background-repeat: repeat-x;
border: 1px solid #FFFFFF;
box-shadow: 0px 0px 3px #CCCCCC;
font-size: 0.75em;
list-style: none outside none;
margin: 0px;
overflow: hidden;
padding: 0px;
text-indent: 0px;
width: 120px;
color:white;
}
ul {
display: block;
}
.selectAnAction ul li.actionSelect {
background: url("/images/selectAnAction-bg.png") repeat-x transparent;
font-weight: bold;
}
.selectAnAction ul li:first-child {
display: block;
}
.selectAnAction ul li {
display: none;
margin: 0px;
text-indent: 0px;
width: 120px;
background-color:grey;
}
.selectAnAction:hover ul li{
display: block;
margin: 0px;
text-indent: 0px;
width: 120px;
}
.selectAnAction ul {
font-size: 0.75em;
list-style: none outside none;
}
.selectAnAction ul li {
display: none;
margin: 0px;
text-indent: 0px;
width: 100%;
padding-left:10px;
font-family:"Times New Roman",Georgia,Serif;
font-size:1.3em;
text-align:left;
}
.action:hover {
background-color:black;
cursor:pointer;
}
What I get is an action menu.
First I see only the LI "select option".
On mouse over - it shows other options (post, edit, archive etc)
I have many such menus on the page.
I want to fix the position of .action elements so that they don't influence the design of rest of the site (because right now when they become visible - other elements of the site move as well).
So I was trying to add something like:
.action {
position:absolute;
}
But what happens is all the .action elements show up on top of each other - right after the first LI (.actionSelect).
So now I'm trying to make them show not on top of each other, but one after another, but with position absolute.
Is there any good way to do that?
(m.b. someting like top:+20px;)
Position: relative does not work - in this way when .action elements become visible - they will move all other elements.
Can't use hard absolute positioning too (top:100px) as I have many of these lists on the page.
You want to position the ul absolutely, and then move the action select outside of the ul as the parent element. If you want to keep the select in a ul, you should have a nested ul for the options. Be sure to add position:relative to whatever is the parent of the options list.
<div class='selectAnAction'>
<ul>
<li class='actionSelect'>
<span>Select an Action</span></li>
<ul class="optionMenu">
<li class='action' onclick='location.href=\"/post.php?key=".$row['hash']."\";'>post</li>
<li class='action' onclick='location.href=\"/adpreview.php?key=".$row['hash']."\";'>preview</li>
<li class='action' onclick='location.href=\"/adupdate.php?key=".$row['hash']."\";'>edit</li>
<li class='action' onclick='location.href=\"/addelete.php?key=".$row['hash']."\";'>archive</li>
</ul>
</li>
</ul>
</div>
position:absolute should be on the .selectAnAction ul li ul I believe
Check out this site for doing dropdowns http://www.htmldog.com/articles/suckerfish/dropdowns/