简体   繁体   中英

Styling the <a> tags inside <ul> <li>

I would like to add a hover effect when user moves the mouse over one of the menu links.

I would also like a bit of space between each line in the menu.

Is there a way to add this to .menuitems or will I have to add a class to each of the elements inside the <ul> scope?

CSS :

.menuitems {
    font-size: 20px;
    font-family: 'Roboto';
    color: #337AB7;
    position: relative;
    display: block;
    width: 180px;
}

a:hover .menuitems {
    background-color: yellow;
}

HTML:

<md-menu-content>
    <ul class="menuitems">
        <li md-ink-ripple>
            <a ui-sref="book">New Booking</a>
        </li>
        <li md-ink-ripple>
            <a ui-sref="admin.home">Admin</a>
        </li>
        <li md-ink-ripple>
            <a ui-sref="admin_logout">Logout</a>
        </li>
    </ul>
</md-menu-content>

Use the following CSS selector, to refer to the <a>

.menuitems li a:hover

For adding space after the lines you can use margins.

.menuitems li {
margin-bottom: 5px;
}

See for reference : CSS Selectors

 .menuitems { font-size: 20px; font-family: 'Roboto'; color: #337AB7; position: relative; display: block; width: 180px; } .menuitems li a:hover { background-color: yellow; } .menuitems li { margin-bottom: 5px; } 
 <ul class="menuitems"> <li md-ink-ripple> <a ui-sref="book">New Booking</a> </li> <li md-ink-ripple> <a ui-sref="admin.home">Admin</a> </li> <li md-ink-ripple> <a ui-sref="admin_logout">Logout</a> </li> </ul> 

Remove class name from hover css will give you yellow background color and add padding-bottom will give you extra space. Working Example

CSS :

.menuitems {
    font-size: 20px;
    font-family: 'Roboto';
    color: #337AB7;
    position: relative;
    display: block;
    width: 180px;
    padding-bottom: 24px;
}
.menuitems li {
   padding-bottom: 10px;
}

.menuitems li a:hover {
    background-color: yellow;
}

Just remove .menuitems from a:hover .menuitems .

CSS

.menuitems {
font-size: 20px;
font-family: 'Roboto';
color: #337AB7;
position: relative;
display: block;
width: 180px;
}
/*For hover */
    a:hover{
        background-color: yellow;       
    }
/* To make space between two lines */
    li {
    margin-bottom: 5px;
    }

It will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM