sbramlett
sbramlett

Reputation: 3

list expand on mouseover

I can't seem to find any information that shows me how to expand a list. I would like it to be a horizontal type nav menu with each list having an image and when you click on the image it expands the "span" text. I hope this makes sense and that I didn't overlook someone else's thread with the same issue.

Example:

<ul id="Topics">
    <li class="Items">
        <img src="results.png" alt="Results">
        <span>Title here</span>
        <span>Some more text here</span>
    </li>
    <li class="Items">
        <img src="language.png" alt="Language here">
        <span>Title here</span>
        <span>Some more text here</span>
    </li>
    <li class="Items">
        <img src="wording.png" alt="Wording here">
        <span>Title here</span>
        <span>Some more text here</span>
    </li>
</ul>

Upvotes: 0

Views: 2387

Answers (1)

Lynel Hudson
Lynel Hudson

Reputation: 2405

Here is a rather fancy example:

ul {
  text-align: left;
  display: inline;
  margin: 0;
  padding: 15px 4px 17px 0;
  list-style: none;
  -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
ul li {
  font: bold 12px/18px sans-serif;
  display: inline-block;
  margin-right: -4px;
  position: relative;
  padding: 15px 20px;
  background: #fff;
  cursor: pointer;
}
ul li:hover {
  background: #555;
  color: #fff;
}
ul li ul {
  padding: 0;
  position: absolute;
  top: 48px;
  left: 0;
  width: 150px;
  -webkit-box-shadow: none;
  box-shadow: none;
  display: none;
  opacity: 0;
  visibility: hidden;
}
ul li ul li { 
  background: #555; 
  display: block; 
  color: #fff;
  text-shadow: 0 -1px 0 #000;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
}
<ul id="Topics">
 <li class="Items">
    Title here
    <ul>
      <li>some more text here</li>
      <li>some more text here</li>
    </ul>
</li>
<li class="Items">
    Title here
    <ul>
      <li>some more text here</li>
      <li>some more text here</li>
    </ul>
</li>
<li class="Items">
    Title here
    <ul>
      <li>some more text here</li>
      <li>some more text here</li>
    </ul>
</li>
</ul>

The key code here is this part:

ul li:hover ul{
  display: block;
  opacity: 1;
  visibility: visible;
}

Basically, we are selecting the nested ul inside of a hovered li. This works because the :hover psudo-class combined with the ul descendant makes sure that we are selecting this list only when its parent li is hovered.

Upvotes: 2

Related Questions