0

我想要一种简单的方法,可以针对低于 18px 的所有字体大小来应用较低的font-weight值。

目前这在 CSS 上可行吗?

4

2 回答 2

1

由于您没有提到内联样式或 css 样式,因此这是一种解决方案。虽然不优雅.. :) 对于内联样式(即使它不是使用内联样式的标准方式)

http://jsfiddle.net/J3x4j/

html

<p style="font-size:11px;">11</p>
<p style="font-size:12px;">12</p>
<p style="font-size:13px;">13</p>
<p style="font-size:14px;">14</p>
<p style="font-size:15px;">15</p>
<p style="font-size:16px;">16</p>

CSS

[style*=font-size\:11px],[style*=font-size\:12px],[style*=font-size\:13px],[style*=font-size\:14px],[style*=font-size\:15px]
{
    color: blue;
    font-weight:normal !important;
}
p
{
font-weight:bold;
}

对于 css 样式,您必须使用 jquery 或 javascript,据我所知,使用 css 您可以量化或应用数字表达式。 http://jsfiddle.net/J3x4j/11/

$('p').each(function(){
    //replace px or em or whatever unit
    var fontsize = parseInt($(this).css('font-size').replace('px'));
    if(fontsize < 18)
    {
        $(this).css('font-weight','normal');
    }
});
于 2013-04-10T02:20:13.917 回答
1

所以基本上,您希望 18px 以下的所有文本都不是粗体?基本上,所有超过 18px 的文本都是粗体。最简单的方法(最容易理解)就是制作不同的类。例如:

.twentypnt{
font-size:20px;
font-weight:bold;
}

.twelvepnt{
font-size:12px;
}

或者,您可以编写一个 javascript 语句。

function checkWeight(){
if(parseInt(document.getElementById('thing').style.fontsize) > 18)
document.getElementById('thing').style.fontweight = "bold";
}

我认为这行得通,但是你必须为每组文本运行它。

于 2013-04-10T02:22:07.643 回答