Reputation: 1472
I've been trying to attach an icon on the right side of the list using only css class member.
http://codepen.io/anon/pen/QwgqVp?editors=110
So when I attach a class named 'location' to a desired list It should display an icon on the right like so:
I tried using float:right; but it just stacks my list with the next one..
ul.listb li.location{
content: '\f124'; /* FontAwesome char code inside the '' */
font-family: FontAwesome; /* FontAwesome or whatever */
/*this Wont work it just stacks with the next list*/
/*
float: right;
*/
}
What makes this hard for me is that I don't want to add anything on the html side. I only want to use 'location' class to make my icon show up in the list.
How can I do that?
Upvotes: 0
Views: 1041
Reputation: 476
Instead of using float for the icon of navigation, you can just make it at the background :
background: url("http://www.icone-png.com/png/39/39015.png") no-repeat;
background-size: 20px 20px ; // Any size you want for your image
background-position: right 2px; // you can change the position if you want
You can try it yourself : http://codepen.io/anon/pen/mywBYJ
Best Regards
Upvotes: 1
Reputation: 22992
Since you are already using both :before
and after
:pseudo-elements, you will have to use border-bottom: 1px solid lightgray
instead of background: lightgray
and use content: '\f124'
along with it because content
only works with :after
or :before
:pseudo-elements.
ul.listb {
padding: 0px;
margin: 0px;
}
ul.listb li {
position: relative;
-webkit-user-select: none;
/* Chrome/Safari */
-moz-user-select: none;
/* Firefox */
-ms-user-select: none;
/* IE10+ */
cursor: pointer;
display: block;
list-style-type: none;
padding: 20px 0;
}
ul.listb li:after {
content: "";
position: absolute;
top: 0;
display: block;
height: 100%;
width: 100%;
border-bottom: 1px solid lightgray;
box-sizing: border-box;
}
ul.listb li.location:after {
position: absolute;
content: '\f124';
font-family: FontAwesome;
top: 0;
display: block;
height: 100%;
width: 100%;
border-bottom: 1px solid lightgray;
text-align: right;
line-height: 50px;
}
ul.listb li.online::before {
margin-left: 4px;
content: '\f0c8 ';
/* FontAwesome char code inside the '' */
font-family: FontAwesome;
/* FontAwesome or whatever */
color: green;
}
ul.listb li.offline::before {
margin-left: 4px;
content: '\f0c8 ';
/* FontAwesome char code inside the '' */
font-family: FontAwesome;
/* FontAwesome or whatever */
color: lightgray;
}
ul.listb li:hover {
background: #F5F5F5;
/*color: #428BCA;*/
font-weight: bold;
}
<link media="all" type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<body>
<ul class="listb">
<li class="online location">John Doe</li>
<li class="online">Doe John</li>
<li class="offline">Bill Gates</li>
<li class="online">Steve Jobs</li>
</ul>
</body>
Upvotes: 3