简体   繁体   English

替换文本行的背景色

[英]Alternate the background color of lines of text

Our project calls for alternately shaded lines (gray-white-gray-white ...) of texts of different lengths, viewed at different sizes, etc., for on-screen and print viewing. 我们的项目要求以不同的大小交替显示不同长度的文本的阴影线(灰白色,灰白色...),以便在屏幕和打印上查看。

I don't think alternating table rows or divs is a solution because the # of words on a line (or in a row/div/span) may change with font sizes and browser resizing. 我不认为交替使用表格行或div是解决方案,因为一行(或行/ div /跨度)中的单词数量可能会随着字体大小和浏览器大小而改变。

Thanks very much Stephen 非常感谢Stephen

Here you go, jsFiddle . jsFiddle到了

Set a line-height on the font, then set a background-size to exactly twice that height. 在字体上设置行高,然后将背景尺寸设置为该高度的两倍。 Put a linear gradient on the background with a 50% hard color stop, and set it to repeat. 在背景上放置线性渐变,并使用50%的硬色标,然后将其设置为重复。

The jsFiddle is just a quick thing I threw together to display this in Webkit browsers. 我将jsFiddle整合在一起,以在Webkit浏览器中显示它。 You'll need to add in vendor specific code for all other browsers, of course. 当然,您需要为所有其他浏览器添加供应商特定的代码。

p {
    line-height: 16px;
    background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, lightgray), color-stop(51%, white));
    background-size: 100% 32px;
}​

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

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