0

私のデザインには、お客様の声があればそれを動的に取り込む右側のサイドバーがあります。

HTML は次のようになります。

<h4> dynamic content</h4>

ここに私のCSSがあります:

#testimonials {
    background: #eeeeee; 
    padding: 30px; 
    width: auto; 
    height: auto;
}

#testimonials h4{
    font-size: 20px;
    line-height: 30px;
    font-family: "freight-big-pro";
    font-style: italic; 
    border-bottom: 1px solid #666; 
    padding-bottom: 20px; 
    padding-top: 20px;
}

#testimonials h4 strong{
    display: block; 
    font-family:"freight-sans-pro", sans-serif; 
    font-style: normal; 
    font-size: 12px; 
}

問題は、要素にコンテンツがない場合<h4>でもスタイルが選択され、CSS で指定されたとおりに背景と境界線が追加されることです。h4を生成していると仮定しています。コンテンツがない場合に空にする方法はありますか?

アップデート:

私はこれを試していますが、jsfiddleでは機能するようですが、ファイルでは機能しません:

<script type="text/javascript"> $(document).ready(function(){ if ($("#testimonials").text().length < 65) { $('#testimonials').hide(); } });</script>

内部の HTML をテキストとしてカウントすると思います。

4

4 に答える 4

1

これは、必要のないときの多くのフロントサイド作業のようです。コンテンツを h4 に出力できる場合は、タグを追加して出力できます。

<section id="testimonials"></section>

サーバー側のプッシュアウト:

<h4>all my content</h4>

その後、CSS は js からの作業なしで機能します。

証言ごとに 1 つずつ持っている可能性が高いですか?

于 2013-08-13T20:06:08.490 に答える