我认为答案是否定的,但是你可以用CSS定位背景图像,这样它就是远离右边的固定数量的像素吗?
如果我设置background-positionx和y的值,那么它们似乎只分别从左侧和顶部进行固定像素调整.
我想将图像作为网页的背景,但是它相对于中心偏移了一些像素.
我怎样才能做到这一点?
我想要:
background-image: url("bg.png");
background-position: 25% center;
background-attachment: fixed;
background-repeat: no-repeat;
Run Code Online (Sandbox Code Playgroud)
但不是25%,我想要的东西是"中心 - 50px".这有什么解决方案吗?
我有一个500x500像素的图像,在我的网站上设置为背景图像(作为背景图像<body>)但我需要这个图像位于网页的右下角.我怎样才能做到这一点?(用css方法更好)
谢谢.
在这种情况下
li {background: url("../img/grey-arrow-next.png") no-repeat right center;
border-bottom: 1px solid #D4E8EB}
Run Code Online (Sandbox Code Playgroud)
我想20px在背景图像之前的右侧空间,我不能给边距,li因为border应该触摸边缘.
所以我需要设置,20px但它需要20px从左侧而不是右侧.
li {background: url("../img/grey-arrow-next.png") no-repeat 20px center;
border-bottom: 1px solid #D4E8EB}
Run Code Online (Sandbox Code Playgroud) 我想设置一个背景图像一个div,在某种程度上,这是在上RIGHT的div,但有固定10px的顶部和右侧的距离.
如果想要它在div 的上部LEFT中,我将如何做到这一点:
background: url(images/img06.gif) no-repeat 10px 10px;
反正是有达到同样的效果,但显示在上背景RIGHT?
据我所知,不可能从任何块的右边框放置CSS背景图像1em,也不可能从底部放置图像1em.
以下代码从左侧放置背景图像1em,从顶部放置2em.
<div class="foo" style="background: url('bar.png') no-repeat 1em 2em">
Some text here
</div>
Run Code Online (Sandbox Code Playgroud)
如果框的大小是动态的并且假设您无法更改HTML,那么在CSS中是否有任何方式指定背景图像应该"远离右边缘"?
(百分比不起作用,因为盒子可以改变大小)
如果无法做到这一点,那么您需要对HTML进行的最小更改量是多少?
这是我提出的解决方法:
<style>
div.background
{
float: right;
background: url('bar.png') no-repeat top left;
margin-right: 1em;
width: 16px;
height: 16px;
}
</style>
<div class="foo">
<div class="background" style=""> </div>
Some text here
</div>
Run Code Online (Sandbox Code Playgroud) 我有一个元素,我希望应用背景,虽然我希望背景图像基于其正确的坐标定位.
我可以使用容器div来表示背景,尽管在这种情况下它并不真实.
我现在有以下规则:
.myelem {
background-image: url("myelem.png");
background-position: 5% 60%;
background-repeat: no-repeat;
}
Run Code Online (Sandbox Code Playgroud)
由于图像的大小,大多数情况下都有效.如果可能的话,我想要一些东西来指明背景的相对位置middle而不是left.
就像使用 CSS 从右侧偏移背景图像一样,我想shape相对于容器的右边缘定位我的一些绝对值。
clip-path: polygon(0 0, right 1em 0, 100% 50%, right 1em 100%, 0 100%, 0 0);
Run Code Online (Sandbox Code Playgroud)
这应该从右边的元素切出一个三角形,它是 1em 长。
我不能使用 % ,因为这样三角形的大小将取决于元素的长度,这是我不想要的。
不幸的是,它不能以这种方式工作。还有其他解决方案吗?