2

p や p.latest_news など、ページ内の多くの要素のフォント サイズと行の高さを変更する jQuery 関数があります。この関数は、p.latest_news を除く他のすべての要素で期待どおりに機能します。

p.latest_news に適用される font-size と line-height は、p no クラス (つまり$('p').css({...)と同じです。

jQuery.1.7.1

コード

    $('p.article_news').css({
            'font-size' : Math.max(11,(.9 * newFontSize)),
            'line-height' : Math.max(13,(1.1 * newFontSize))+'px'
            });
    $('p').css({
            'font-size' : Math.max(14,newFontSize),
            'line-height' : Math.max(21,(1.7 * newFontSize))+'px'
            });

私が使うだけなら

    $('p.article_news').css({
            'font-size' : Math.max(11,(.9 * newFontSize)),
            'line-height' : Math.max(13,(1.1 * newFontSize))+'px'
            });

p.article_news font-size と line-height が期待どおりに変更されました

なぜこうなった?各 p、class、および classless にどのように影響を与えることができますか?

ありがとうございました

4

4 に答える 4

4

article_news のフォント サイズを設定してから、2 番目のセレクターで再度変更しています。

必要なものは次のとおりです。

$('p.article_news').css({
        'font-size' : Math.max(11,(.9 * newFontSize)),
        'line-height' : Math.max(13,(1.1 * newFontSize))+'px'
        });
$('p:not(.article_news)').css({
        'font-size' : Math.max(14,newFontSize),
        'line-height' : Math.max(21,(1.7 * newFontSize))+'px'
        });

:not() セレクターは基本的に、クラス .active_news を持たないすべての p ノードを選択しています。

于 2012-09-07T21:11:55.950 に答える
1

関数を反転するだけです。最初にpセレクターを使用する関数を使用し、次にp.article_newsセレクターを使用する関数を使用します。

pセレクター関数がp.article_newsセレクター関数をオーバーライドしています。

于 2012-09-07T21:14:35.507 に答える
1

私はマークのソリューションが好きです。

ただし、両方の関数が一緒に呼び出される場合は、それらを反転して機能させることができます。

$('p').css({
            'font-size' : Math.max(14,newFontSize),
            'line-height' : Math.max(21,(1.7 * newFontSize))+'px'
            });
$('p.article_news').css({
            'font-size' : Math.max(11,(.9 * newFontSize)),
            'line-height' : Math.max(13,(1.1 * newFontSize))+'px'
            });

で確認するより速いかもしれません:not

于 2012-09-07T21:19:38.420 に答える
0

p.article_newsスタイルを設定するときに追加したスタイルを上書きしてpp.article_newsますpp最初にをスタイルしてから をスタイルすることも、 の代わりに をp.article_news使用することもできます。p:not(.article_news)p

于 2012-09-07T21:13:23.447 に答える