私のデザインには、お客様の声があればそれを動的に取り込む右側のサイドバーがあります。
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 をテキストとしてカウントすると思います。