简体   繁体   中英

How to align a link icon after the text via CSS?

I have a navigation menu with links, before the text link I have an icon, I would like to put this icon after the text link. The website is here http://www.labella.co.il/ .

CSS of the link:

.sidebar ul.menu li a {background: url("1-default/bullet.png") no-repeat scroll 0 12px transparent;}

Icon image is in url("1-default/bullet.png") .

Here is the changed code to get what you are after:

.sidebar ul.menu li a {
    background: url("1-default/bullet.png") no-repeat scroll 100% 12px transparent;
    padding: 10px 22px 10px 0;
}

I am swapping the left padding to the right, and pushing the background image across to the right hand side.

Note that I have used 100% as opposed to a 'magic number' (like the other answers). This means that even if the width changes, the icons will still line up, with no maintenance required!

Change the position of the background image and add some padding so the text won't cover it:

.sidebar ul.menu li a {
    background: url("1-default/bullet.png") no-repeat scroll 100% 12px transparent;
}

.sidebar ul.menu li a {
    cursor: pointer;
    text-decoration: none;
    padding: 10px 23px 10px 22px;
    display: block;
    background: #CCC;
}

background-position could be changed like:

.sidebar ul.menu li a {
  background: url("1-default/bullet.png") no-repeat scroll 202px 12px transparent;
}

and then padding adjusted to make room for the icon:

.sidebar ul.menu li a {
   cursor: pointer;
   text-decoration: none;
   padding: 10px 22px 10px 0;
   display: block;
   background: #CCC;
}

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