I have a un-ordered list of links, each of which contains some text and a span element.
<li class="ui-state-default"><a href="#pg-control">Control<span class="ui-icon ui-icon-right_arrow"></span></a></li>
I would like the icon to appear vertically centered relative to the li (inline with the text)
Here is my css
li {
line-height: 240%;
display: block;
border-bottom: 1px solid #666;
padding: 5px;
}
li a {
text-decoration: none;
color: #000;
display: block;
}
.ui-icon {
width: 24px;
height: 24px;
float: right;
display: inline-block;
}
Note I am not usi开发者_JAVA百科ng jQuery, I do realize my class names are the same. That is merely coincidence.
You could move the icon to be a background of the li, or:
Give the li
relative positioning then give the icon absolute positioning. Position the icon 50% from the top, and then minus margin the top half of the icon's height. This will vertically center the icon.
li {
position: relative;
line-height: 240%;
display: block;
border-bottom: 1px solid #666;
padding: 5px;
}
li a {
text-decoration: none;
color: #000;
display: block;
}
.ui-icon {
position: absolute;
top: 50%;
right: 10px;
margin-top: -12px
width: 24px;
height: 24px;
display: inline-block;
}
If it was me i'd make the arrow the background-image
of the li
something like:
li{
background:transparent url(the_arrow.jpg) no-repeat center right;
}
I've coded an example...
精彩评论