Webspeeder
asked on
Insert image within UL / LI Area Dropdown Menu
Hey all.
I have this menu that is juuust about complete. I'm trying to mimic the behavior of another menu that has been generated with a WYSIWYG.
The last piece is the ability to insert an image to the right of the links being displayed in a drop down menu. Ideally, when the user hovers over the menu link, the sub menu options appear with X links. To the right of those links I want to display an image.
I've tried inserting a <section> but I can't get it to be visible.
For example, here is the code:
<li class="topmenu">
 <a href='' style="height:16px;line-he ight:16px; ">
   <span>Option 1</span>
 </a>
 <ul>
   <li><a href=''>Sub Option 1</a></li>
   <li><a href=''>Sub Option 1</a></li>
   <li><a href=''>Sub Option 1</a></li>
   <li><a href=''>Sub Option 1</a></li>
 </ul>
 <section> IMAGE TO DISPLAY HERE</section>
</li>
                Â
Any ideas?
I have this menu that is juuust about complete. I'm trying to mimic the behavior of another menu that has been generated with a WYSIWYG.
The last piece is the ability to insert an image to the right of the links being displayed in a drop down menu. Ideally, when the user hovers over the menu link, the sub menu options appear with X links. To the right of those links I want to display an image.
I've tried inserting a <section> but I can't get it to be visible.
For example, here is the code:
<li class="topmenu">
 <a href='' style="height:16px;line-he
   <span>Option 1</span>
 </a>
 <ul>
   <li><a href=''>Sub Option 1</a></li>
   <li><a href=''>Sub Option 1</a></li>
   <li><a href=''>Sub Option 1</a></li>
   <li><a href=''>Sub Option 1</a></li>
 </ul>
 <section> IMAGE TO DISPLAY HERE</section>
</li>
                Â
Any ideas?
Not sure what you want.
ul#externalMenuLink li.topmenu ul li:hover {
  background: url('/explore_icon.png') no-repeat;
background-position:right center
}
ul#externalMenuLink li.topmenu ul li:hover {
  background: url('/explore_icon.png') no-repeat;
background-position:right center
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Using the code below, when you hover over the menu items, a "white" area displays for the drop down with 1 to X links. What I need is to insert an image to the right of those links, within the "white" area.
The white area is one UL element, if I put an image after using the :after, it appends the image to the area but is below the UL.
I was thinking of putting in another UL with one LI that would contain the image, then float the ULs.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
     Remove this if you use the .htaccess -->
  <meta http-equiv="X-UA-Compatibl e" content="IE=edge,chrome=1" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-widt h; initial-scale=1.0" />
  <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
  <link rel="shortcut icon" href="/favicon.ico" />
  <link rel="apple-touch-icon" href="/apple-touch-icon.pn g" />
  <!--[if lt IE 9]>
    <script src="/js/html5shiv.js"></s cript>
  <![endif]-->
<style type="text/css">
/* --------------------- */
/* BEGIN Navigation Menu */
/* --------------------- */
/***********************/
/* External Menu Links */
/***********************/
body{background-color: #E6E6DC;}
ul#externalMenuLinks,ul#ex ternalMenu Links ul{
   margin:0;list-style:none;p adding:0;b ackground- color:#2e5 568;border -width:0;b order-styl e:solid;bo rder-color :;}
ul#externalMenuLinks ul{
   visibility:hidden;position :absolute; left:0;top :100%;opac ity:0;-moz -transitio n:all 0.5s;-webkit-transition:op acity 0.5s;-o-transition:opacity 0.5s,visibility 0.5s;transition:opacity 0.5s;background-color:#F8F 9F3;border -width:0 1px 1px 1px;border-radius:0 0px 0px 0px;-moz-border-radius:0 0px 0px 0px;-webkit-border-radius: 0;-webkit- border-top -right-rad ius:0px;-w ebkit-bord er-bottom- right-radi us:0px;-we bkit-borde r-bottom-l eft-radius :0px;borde r-style:so lid;border -color:#F8 F9F3;paddi ng:0 3px 3px;}
ul#externalMenuLinks li:hover>ul{
   visibility:visible;opacity :1;}
ul#externalMenuLinks li{
   position:relative;display: block;whit e-space:no wrap;font- size:0;flo at:left;}
ul#externalMenuLinks li:hover{
   z-index:1;}
ul#externalMenuLinks{
   font-size:0;z-index:999;po sition:rel ative;disp lay:inline -block;zoo m:1;paddin g:0;border -radius:0p x;-moz-bor der-radius :0px;-webk it-border- radius:0px ;
   *display:inline;}
* html ul#externalMenuLinks li a{
   display:inline-block;}
ul#externalMenuLinks>li{
   margin:0 0 0 0;}
ul#externalMenuLinks ul>li{
   margin:10px 0 0;}
ul#externalMenuLinks a:active, ul#externalMenuLinks a:focus{
   outline-style:none;}
ul#externalMenuLinks a{
   display:block;vertical-ali gn:middle; text-align :left;text -decoratio n:none;fon t:13px Helvetica,Arial,sans-serif ;color:#F8 F9F3;curso r:pointer;
   padding:4px 10px 6px 10px;margin-top: 6px;background-color:#2e55 68;backgro und-repeat :repeat;bo rder-width :0px;borde r-style:no ne;border- color:;}
ul#externalMenuLinks ul li{
   float:none;margin:3px 0 0;}
ul#externalMenuLinks ul a{
   text-align:left;padding:4p x 10px;background-color:#F8F 9F3;border -width:1px 0 1px 0;border-style:solid;borde r-color:#F 8F9F3;bord er-radius: 0px;-moz-b order-radi us:0px;-we bkit-borde r-radius:0 px;font:bo ld 12px Helvetica,Arial,sans-serif ;color:#2e 5568;text- decoration :none;}
ul#externalMenuLinks li:hover>a,ul#externalMenu Links li a.pressed{
   background-color:#F8F9F3;b order-styl e:none;col or:#E79736 ;text-deco ration:non e;}
ul#externalMenuLinks span{
   display:block;overflow:vis ible;backg round-imag e:url("arr owsubn.gif ");backgro und-positi on:right center;background-repeat:n o-repeat;p adding-rig ht:19px;}
ul#externalMenuLinks li:hover>a>span{
   background-image:url("arro wsub.gif") ;}
ul#externalMenuLinks ul li:hover>a,ul#externalMenu Links ul li a.pressed{
   background-color:#F8F9F3;b order-styl e:solid;bo rder-color :#F8F9F3;c olor:#E797 36;text-de coration:n one;}
ul#externalMenuLinks li.topfirst>a{
   background-color:;border-w idth:1px 1px 0 1px;border-style:solid;bor der-color: transparen t;border-r adius:0px 0px 0 0;-moz-border-radius:0px 0px 0 0;-webkit-border-radius:0p x;-webkit- border-bot tom-right- radius:0;- webkit-bor der-bottom -left-radi us:0;}
ul#externalMenuLinks li.topfirst:hover>a,ul#ext ernalMenuL inks li.topfirst a.pressed{
   background-color:#FFF;bord er-style:s olid;borde r-color:#F 8F9F3;}
/* Shift left most dropdown to right */
ul#externalMenuLinks li.topfirst ul
{
   margin: 0 0 0 5px;
} Â Â Â
/***
ul#externalMenuLinks li.toplast ul
{
   margin: 0 100px 0 0px;
   border: 1px solid red;
   position: absolute;
  top: 32px;
  right: 32px;
}
***/
/* Set rounded corners */
ul#externalMenuLinks, ul#externalMenuLinks li.topfirst, ul#externalMenuLinks li.topfirst a {
  -moz-border-radius-bottom- left: 6px;
  -webkit-border-bottom-left -radius: 6px;
  border-bottom-left-radius: 6px;
}
#externalMenuLinks ul li.last {
 -moz-border-radius-bottom- right: 6px;
 -webkit-border-bottom-righ t-radius: 6px;
 border-bottom-right-radius :6px; Â
 border: 1px solid red;
}
  Â
#navLinks {
   position: absolute;
   top: 39px;  /* 40 - 1 to prevent pixle rounding errors on resize */
   right: 30px;
   height: 31px; /* 30 + 1 to make up for the subtracted pixel above */
   min-width: 780px;
   width: 75%;
   z-index: 99;
   /* background-color: #2f5568; - green */
   background-color: #3F5667;  /* blue */
   color: #fff;
  Â
   border-bottom-right-radius : 6px;
   -webkit-border-bottom-righ t-radius:6 px;
   -moz-border-radius-bottomr ight:6px;
  Â
   border-bottom-left-radius: 6px;
   -webkit-border-bottom-left -radius:6p x;
   -moz-border-radius-bottoml eft:6px;
}
  Â
/* ------------------- */
/* END Navigation Menu */
/* ------------------- */
</style>
</head>
<body>
  <div id="bodyContainer">
  Â
    <!-- Begin Header -->
   Â
    <header>  Â
      <!-- Begin Primary Nav -->
      <div id="mainSiteBar">
         <nav id="navLinks12" class="shadow" style="margin: 5em 0 0 10em;">
           <ul id="externalMenuLinks" class="topmenu" style="">
                  <li class="topfirst">
                     <a href="http://menullink/Why+"
                       style="height:16px;line-he ight:16px; "><span>Wh y</span></ a>
                     <ul style="">
                        <li><a href="http://menullink/Why">Our Story</a></li>
                        <li><a href="http://menullink/Locations">Locations</a></li>
                        <li><a href="http://menullink/Videos">Videos</a></li>
                        <li><a href="http://menullink/Distinct+Advantages">Distinct Advanatages</a></li>
                        <li><a href="http://menullink/Testimonials">Testimonials</a></ li>
                     </ul>
                  </li>
                  <li class="topmenu">
                     <a href="http://menullink/Dealer+Access"
                       style="height:16px;line-he ight:16px; "><span>Ac cess</span ></a>
                     <ul style="">
                        <li><a href="http://menullink/">About Access</a></li>
                        <li><a href="http://menullink/Marketing+Tools">Marketing Tools</a></li>
                        <li><a href="http://menullink/Retail+Tools">Retail Tools</a></li>
                        <li><a href="http://menullink/Industry+Tools">Industry Tools</a></li>
                     </ul>
                  </li>
                  <li class="topmenu">
                     <a href="http://menullink/Industry+Resources"
                       style="height:16px;line-he ight:16px; "><span>In dustry Resources</span></a>
                     <ul style="">
                        <li><a href="http://menullink/Sportsman+Magazine">Sportsman Magazine</a></li>
                        <li><a href="http://menullink/Product+Information+Charts">Product Information Charts</a></li>
                     <li><a href="http://menullink/Outdoor+Recreation+Resources">Outdoor Recreation Resources</a></li>
                        <li><a href="http://menullink/State+DNR+Regulations">State DNR Regulations</a></li>
                        <li><a href="http://menullink/Industry+News">Industry News</a></li>
                     </ul>
                  </li>
                  <li class="topmenu">
                     <a href="http://menullink/Protect"
                       style="height:16px;line-he ight:16px; "><span>Pr otect</spa n></a>
                     <ul style="">
                        <li><a href="http://menullink/Advocacy+Associations">Advocacy Associations</a></li>
                        <li><a href="http://menullink/">ACTION</a></li>
                     </ul>
                  </li>
                  <li class="toplast">
                     <a href="http://menullink/Contact"
                       style="height:16px;line-he ight:16px; "><span>Co ntact</spa n></a>
                     <ul style="">
                        <li><a href="http://menullink/Contact">Contact Us</a></li>
                        <li><a href="http://menullink/Media">Media</a></li>
                       <li><a href="http://menullink/Employment">Employment</a></li >
                     </ul>
                  </li>
               </ul>
         </nav>
      </div>
      <!-- End Primary Nav -->
     Â
    </header>
    <!-- End Header -->
  </div>
</body>
</html>
The white area is one UL element, if I put an image after using the :after, it appends the image to the area but is below the UL.
I was thinking of putting in another UL with one LI that would contain the image, then float the ULs.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
     Remove this if you use the .htaccess -->
  <meta http-equiv="X-UA-Compatibl
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-widt
  <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
  <link rel="shortcut icon" href="/favicon.ico" />
  <link rel="apple-touch-icon" href="/apple-touch-icon.pn
  <!--[if lt IE 9]>
    <script src="/js/html5shiv.js"></s
  <![endif]-->
<style type="text/css">
/* --------------------- */
/* BEGIN Navigation Menu */
/* --------------------- */
/***********************/
/* External Menu Links */
/***********************/
body{background-color: #E6E6DC;}
ul#externalMenuLinks,ul#ex
   margin:0;list-style:none;p
ul#externalMenuLinks ul{
   visibility:hidden;position
ul#externalMenuLinks li:hover>ul{
   visibility:visible;opacity
ul#externalMenuLinks li{
   position:relative;display:
ul#externalMenuLinks li:hover{
   z-index:1;}
ul#externalMenuLinks{
   font-size:0;z-index:999;po
   *display:inline;}
* html ul#externalMenuLinks li a{
   display:inline-block;}
ul#externalMenuLinks>li{
   margin:0 0 0 0;}
ul#externalMenuLinks ul>li{
   margin:10px 0 0;}
ul#externalMenuLinks a:active, ul#externalMenuLinks a:focus{
   outline-style:none;}
ul#externalMenuLinks a{
   display:block;vertical-ali
   padding:4px 10px 6px 10px;margin-top: 6px;background-color:#2e55
ul#externalMenuLinks ul li{
   float:none;margin:3px 0 0;}
ul#externalMenuLinks ul a{
   text-align:left;padding:4p
ul#externalMenuLinks li:hover>a,ul#externalMenu
   background-color:#F8F9F3;b
ul#externalMenuLinks span{
   display:block;overflow:vis
ul#externalMenuLinks li:hover>a>span{
   background-image:url("arro
ul#externalMenuLinks ul li:hover>a,ul#externalMenu
   background-color:#F8F9F3;b
ul#externalMenuLinks li.topfirst>a{
   background-color:;border-w
ul#externalMenuLinks li.topfirst:hover>a,ul#ext
   background-color:#FFF;bord
/* Shift left most dropdown to right */
ul#externalMenuLinks li.topfirst ul
{
   margin: 0 0 0 5px;
} Â Â Â
/***
ul#externalMenuLinks li.toplast ul
{
   margin: 0 100px 0 0px;
   border: 1px solid red;
   position: absolute;
  top: 32px;
  right: 32px;
}
***/
/* Set rounded corners */
ul#externalMenuLinks, ul#externalMenuLinks li.topfirst, ul#externalMenuLinks li.topfirst a {
  -moz-border-radius-bottom-
  -webkit-border-bottom-left
  border-bottom-left-radius:
}
#externalMenuLinks ul li.last {
 -moz-border-radius-bottom-
 -webkit-border-bottom-righ
 border-bottom-right-radius
 border: 1px solid red;
}
  Â
#navLinks {
   position: absolute;
   top: 39px;  /* 40 - 1 to prevent pixle rounding errors on resize */
   right: 30px;
   height: 31px; /* 30 + 1 to make up for the subtracted pixel above */
   min-width: 780px;
   width: 75%;
   z-index: 99;
   /* background-color: #2f5568; - green */
   background-color: #3F5667;  /* blue */
   color: #fff;
  Â
   border-bottom-right-radius
   -webkit-border-bottom-righ
   -moz-border-radius-bottomr
  Â
   border-bottom-left-radius:
   -webkit-border-bottom-left
   -moz-border-radius-bottoml
}
  Â
/* ------------------- */
/* END Navigation Menu */
/* ------------------- */
</style>
</head>
<body>
  <div id="bodyContainer">
  Â
    <!-- Begin Header -->
   Â
    <header>  Â
      <!-- Begin Primary Nav -->
      <div id="mainSiteBar">
         <nav id="navLinks12" class="shadow" style="margin: 5em 0 0 10em;">
           <ul id="externalMenuLinks" class="topmenu" style="">
                  <li class="topfirst">
                     <a href="http://menullink/Why+"
                       style="height:16px;line-he
                     <ul style="">
                        <li><a href="http://menullink/Why">Our Story</a></li>
                        <li><a href="http://menullink/Locations">Locations</a></li>
                        <li><a href="http://menullink/Videos">Videos</a></li>
                        <li><a href="http://menullink/Distinct+Advantages">Distinct Advanatages</a></li>
                        <li><a href="http://menullink/Testimonials">Testimonials</a></
                     </ul>
                  </li>
                  <li class="topmenu">
                     <a href="http://menullink/Dealer+Access"
                       style="height:16px;line-he
                     <ul style="">
                        <li><a href="http://menullink/">About Access</a></li>
                        <li><a href="http://menullink/Marketing+Tools">Marketing Tools</a></li>
                        <li><a href="http://menullink/Retail+Tools">Retail Tools</a></li>
                        <li><a href="http://menullink/Industry+Tools">Industry Tools</a></li>
                     </ul>
                  </li>
                  <li class="topmenu">
                     <a href="http://menullink/Industry+Resources"
                       style="height:16px;line-he
                     <ul style="">
                        <li><a href="http://menullink/Sportsman+Magazine">Sportsman Magazine</a></li>
                        <li><a href="http://menullink/Product+Information+Charts">Product Information Charts</a></li>
                     <li><a href="http://menullink/Outdoor+Recreation+Resources">Outdoor Recreation Resources</a></li>
                        <li><a href="http://menullink/State+DNR+Regulations">State DNR Regulations</a></li>
                        <li><a href="http://menullink/Industry+News">Industry News</a></li>
                     </ul>
                  </li>
                  <li class="topmenu">
                     <a href="http://menullink/Protect"
                       style="height:16px;line-he
                     <ul style="">
                        <li><a href="http://menullink/Advocacy+Associations">Advocacy Associations</a></li>
                        <li><a href="http://menullink/">ACTION</a></li>
                     </ul>
                  </li>
                  <li class="toplast">
                     <a href="http://menullink/Contact"
                       style="height:16px;line-he
                     <ul style="">
                        <li><a href="http://menullink/Contact">Contact Us</a></li>
                        <li><a href="http://menullink/Media">Media</a></li>
                       <li><a href="http://menullink/Employment">Employment</a></li
                     </ul>
                  </li>
               </ul>
         </nav>
      </div>
      <!-- End Primary Nav -->
     Â
    </header>
    <!-- End Header -->
  </div>
</body>
</html>
Using :after you can only set a background like:
ul#externalMenuLinks li.topmenu ul:after {
  content:'';
background:url('/explore_i con.png');
  }
However it sounds like you are trying to actually add an image in which case you just need to use an image tag inside the ul. if you do use the image background it may get cutoff or be mis-positioned unless you use the other background properties to refine the declaration.
If you are placing an image it may alter the size of the ul and may require alignment.
I think you are making a lot of extra work for yourself with little benefit, when an image can just be used and positioned as a regular background image.
Cd&
ul#externalMenuLinks li.topmenu ul:after {
  content:'';
background:url('/explore_i
  }
However it sounds like you are trying to actually add an image in which case you just need to use an image tag inside the ul. if you do use the image background it may get cutoff or be mis-positioned unless you use the other background properties to refine the declaration.
If you are placing an image it may alter the size of the ul and may require alignment.
I think you are making a lot of extra work for yourself with little benefit, when an image can just be used and positioned as a regular background image.
Cd&
i'd rather suggest a different approach using only CSS and no js
-> first make your menu AND submenu visible and placed where you want it
you'll need to fix your level 1 li's width and height, and add overflow:visible to them
then add the submenu and use position:relative and left/top properties to move it to the left of the main menu
-> then apply visibility:hidden to the submenu
-> then add the following
li.level1:hover ul{ visibility:visible; }
assuming that your level1 lis have the level1 class.
if you need a sample code, i can provide it, but i doubt you'll need it if you give it a try and follow the above steps
-> first make your menu AND submenu visible and placed where you want it
you'll need to fix your level 1 li's width and height, and add overflow:visible to them
then add the submenu and use position:relative and left/top properties to move it to the left of the main menu
-> then apply visibility:hidden to the submenu
-> then add the following
li.level1:hover ul{ visibility:visible; }
assuming that your level1 lis have the level1 class.
if you need a sample code, i can provide it, but i doubt you'll need it if you give it a try and follow the above steps
ASKER
ul#externalMenuLinks li.topmenu ul:after {
  content: url('/explore_icon.png');
  float: left;
}