简体   繁体   English

背景图像左对齐

[英]Background image aligned left

Let's say i have a css class called 'author' like in this code : 假设我在这段代码中有一个名为“author”的css类:

.author {
    background:url('img/user91.png');
    background-size:10px 10px;
    background-repeat:no-repeat;
    color:#62c6ff;
    bottom: 0;
    font-family: sans-serif;
    text-decoration: none;
    text-transform: lowercase;
    font-size: 9px;
    margin-left: 20px;
    margin-top: 70px;
}

and html : 和HTML:

<p class="author"><a href="#">@jimmy</a></p>

I want @jimmy to be displayed in ap and in the left side of @jimmy to appear the image background. 我希望@jimmy显示在ap和@jimmy的左侧以显示图像背景。
这是一个示例图片

You should use background-position to place the image on the left side: 您应该使用背景位置将图像放在左侧:

background-position: left center; 背景位置:左中心;

or 要么

background-position: 0 0; background-position:0 0;

And then play with padding to place the link to the author: 然后使用padding将链接放到作者:

padding-left: 15px; padding-left:15px;

you need to add 你需要添加

background-position: 0 0; padding-left: 10px /*this should be equal to image width*/

to .author class 到.author类

Hope this helps! 希望这可以帮助!

do you need any fiddle link to show this up? 你需要任何小提琴链接来展示这个吗?

只需使用它

 `background:url("img/user91.png") no-repeat right 0px; `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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