0

I have a CSS like this:

#poll_list {
    margin: 0;
}
#poll_list li {
    height: 50px;
    list-style-type: none;
    font-size: 20px;
    border-bottom: 5px solid white;
    background-color: #cfcfcf;
    position: relative;
}
#poll_list a {
    text-decoration: none;
    line-height: 50px; /*need to match #poll_list li for text in middle*/

    display: inline-block;
    *display: block;
    *zoom: 1;

    width: 100%;
    height: 50px;   
}
#poll_list a:link, #poll_list a:visited {
    color: black;
}
#poll_list a:hover {
    color: white;
}
#poll_list li.first_topic_list, #poll_list li:hover  {
    color: #F0F0F0;
    background-color: slateblue;
}
#poll_list li.first_topic_list:after, #poll_list li:hover:after  {
    position: absolute;

    top: 0;
    bottom: 0;
    left: -20px;

    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 20px solid slateblue;

    content: "";
}

for an HTML list like this:

<ul id="poll_list">
    <li class='first_topic_list'><a id='first_topic' href='#'>a</a></li>
    <li><a class='topic' href='#'>b</a></li>
    <li><a class='topic' href='#'>c</a></li>
    <li><a class='topic' href='#'>d</a></li>
    <li><a class='topic' href='#'>e</a></li>
    <li><a class='topic' href='#'>f</a></li>
    <li><a class='topic' href='#'>g</a></li>
</ul>

See this as live demo in JSFiddle.

I want 'a' to behave like all other elements when all other elements are not hovered. This effect should be added to the top of the above CSS.

Sorry for my bad english. In my mind I have something like this:
only 'a' is pointing to left->user mouseenter effect on all others elements will make it points to the left->'a' not pointing again

something like html option tag selected attribute. selected option is preserved, and user can select others options which it then will highlight the option. If user choose back the selected option, selected option will be highlighted and no others will be.

2
  • Means when another 'a' is hovered first "a"'s color will become simple like others? Commented Jul 28, 2014 at 22:46
  • yes,..sorry for my bad english :( Commented Jul 28, 2014 at 23:16

2 Answers 2

1

Is this the effect you want; where the first link is pre-selected but looses its higlighting when hovering over another link?

http://jsfiddle.net/John_C/N6Gcx/

The main part of my solution is using different :hover selectors for each of the possibilities.

#poll_list li:hover  {
  color: black;
  background-color: slateblue;
}
#poll_list:hover li.first_topic_list{
  color: #cfcfcf;
  background-color: #cfcfcf;
}
#poll_list li.first_topic_list{
  color: #F0F0F0;
  background-color: slateblue;
}
#poll_list:hover li.first_topic_list:hover{
  color: #F0F0F0;
  background-color: slateblue;
}
Sign up to request clarification or add additional context in comments.

3 Comments

yess :) just one minor question, can 'a' not be the selected element after mouse leave the lists but instead of the last li that the mouse hovered?
probably not without using javascript
opps, but that's still very close to what I wanted so I will give you the up vote. If possible I would love to come by to hug you and give my appreciation ! :)
0

You need to remove #poll_list li.first_topic_list from the CSS properties you applied.

Replace your code with:

#poll_list {
    margin: 0;
}
#poll_list li {
    height: 50px;
    list-style-type: none;
    font-size: 20px;
    border-bottom: 5px solid white;
    background-color: #cfcfcf;
    position: relative;
}
#poll_list a {
    text-decoration: none;
    line-height: 50px; /*need to match #poll_list li for text in middle*/

    display: inline-block;
    *display: block;
    *zoom: 1;

    width: 100%;
    height: 50px;   
}
#poll_list a:link, #poll_list a:visited {
    color: black;
}
#poll_list a:hover {
    color: white;
}
#poll_list li:hover  {
    color: #F0F0F0;
    background-color: slateblue;
}
#poll_list li:hover:after  {
    position: absolute;

    top: 0;
    bottom: 0;
    left: -20px;

    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 20px solid slateblue;

    content: "";
}


Check this fiddle: http://jsfiddle.net/CYtK5/2/

5 Comments

Thanks for reply! is there by any chance that 'a' element is pre-seleced too like when mouse hover?
You are welcome :) What do you mean by preselected? What is the effect you would like to achieve?
:), I mean 'a' element will be look like the hovered elements. something like html option tag selected attribute, sorry for my bad english :(
You can style that in CSS if you want to have a preselected element. Create a class in CSS and call it "preselected" for instance and give it whatever properties you need to. If you post me a screenshot it would be better :) Otherwise try google translate :P
I have the idea of another SO topic [How to affect other elements when a div is hovered][1], but dont know why it doesnt work in my situation -_- [1]:stackoverflow.com/questions/4502633/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.