1
我一直在尝试将伪元素图像添加到标题标题。我设法让它显示在我想要的位置,但我真的很努力使图像与标题大小动态缩放。因此,当标题为H1时,图像很好,但将标题缩小为H5,图像保持相同大小并与其他内容重叠。问题的确定伪元素图像的大小以匹配容器
实施例:
的HTML:
<h1 class="title brand" id="id">some content <small>a sub header</small></h1>
<h5 class="title brand reverse" id="id">some content <small>a sub header</small></h5>
少:
/*
* Headers
*/
h1,h2,h3,h4,h5,h6 {
font-family: @font-family-emphasis;
font-weight: 400;
margin: .75em 0;
display: block;
}
h1 {
font-size: @font-size-h1;
}
h2 {
font-size: @font-size-h2;
}
h3 {
font-size: @font-size-h3;
}
h4 {
font-size: @font-size-h4;
}
h5 {
font-size: @font-size-h5;
}
h6 {
font-size: @font-size-h6;
}
h1,h2,h3,h4,h5,h6 {
strong {
font-weight: 500;
}
&.light {
font-weight: 200;
}
&.title {
border-bottom: solid 1px @color-interface-grey-light;
}
&.page-title {
border-bottom: solid 1px @color-interface-grey;
margin-bottom: 0.25em;
}
.small,small {
color: darken(@color-interface-grey, 25%);
font-size: .65em;
}
&.brand {
padding: .5em 0 .5em;
margin: 0.5em 0 .5em 2.5em;
&:after{
content: url("../img/brand-mark.svg");
position: absolute;
left:0.5em;
}
&.reverse {
padding: .5em 0 .5em;
margin: 0.5em 2.5em .5em 0em;
&:after{
content: '';
}
&:before{
content: url("../img/brand-mark-reverse.svg");
position: absolute;
right:0.5em;
}
}
}
}
任何人都可以指向正确的方向吗?
可以在设置高度为100%?或者将其设置为背景图片,然后使用背景大小的属性 – Pete 2014-10-01 11:12:54
@Pete我可以使用background-size属性来构建解决方案,因此您的表达正确无误。由于内容不被视为内联替换元素,因此使用100%的高度似乎不起作用,所以通常的技巧不适用,因为伪元素在常规内容流之外。 – 2014-10-01 11:29:30