【发布时间】:2017-09-13 22:21:51
【问题描述】:
在第二个框中,注意箭头在同一个位置。如何让它与 div 一起流动?
在background 属性中使用scroll right center 有效,但我想保留一些正确的填充。
我也在尽量避免使用 2 个 div 或标签。这是否可以通过 .box div 实现?
【问题讨论】:
在第二个框中,注意箭头在同一个位置。如何让它与 div 一起流动?
在background 属性中使用scroll right center 有效,但我想保留一些正确的填充。
我也在尽量避免使用 2 个 div 或标签。这是否可以通过 .box div 实现?
【问题讨论】:
.right-align-background {
background-position: center right;
}
【讨论】:
center right,箭头被推到了极限。
如果您希望背景与您在元素上设置的填充对齐,也可以使用 background-origin: content-box;。
类似这样的:
input.error {
background: no-repeat;
background-image: url('../images/field-error.png');
background-position: right center;
background-origin: content-box;
padding-right: 5px;
}
【讨论】:
使用:after 代替添加图像怎么样?
.box {
background: #a6cf83;
float:left;
color:#333;
font-weight:bold;
padding:8px;
}
.box:after {
content: url(http://cdn1.iconfinder.com/data/icons/humano2/24x24/actions/new-go-next.png);
}
【讨论】:
Calc() has 95% browser support in the US now(2017 年 9 月),并为这个问题提供了一个优雅的解决方案。
background-position: calc(100% - 24px) center;
【讨论】:
如果您需要在右侧填充,我认为您可能必须使用百分比:
background-position:95% 50%;
如果你的元素宽度相似,效果会很好。
【讨论】: