如何将背景位置设置为绝对距离,从右开始? [英] How to set the background-position to an absolute distance, starting from right?

查看:89
本文介绍了如何将背景位置设置为绝对距离,从右开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为div设置背景图片,方式是它位于div的右上方,但距顶部和右侧的距离固定为10px。

I want to set a background image for a div, in a way that it is in the upper RIGHT of the div, but with a fixed 10px distance from top and right.

这是我如何做,如果想要它在div的上层左侧:

Here is how I would do that if wanted it in the upper LEFT of the div:

background: url(images/img06.gif) no-repeat 10px 10px;

有没有反而实现相同的结果,但显示在右上角的背景?

Is there anyway to achieve the same result, but showing the background on the upper RIGHT?

推荐答案

使用上述规则和顶部和右边距:

Use the previously mentioned rule along with a top and right margin:

background: url(images/img06.gif) no-repeat top right;
margin-top: 10px;
margin-right: 10px;

背景图片只出现在填充内容中,而不是边距。如果添加边距不是一个选项,你可能必须诉诸另一个div,虽然我建议你只使用它作为最后的手段,尽量保持你的标记尽可能精益和sementic。

Background images only appear within padding, not margins. If adding the margin isn't an option you may have to resort to another div, although I'd recommend you only use that as a last resort to try and keep your markup as lean and sementic as possible.

这篇关于如何将背景位置设置为绝对距离,从右开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆