順序付けられていないリストにいくつかの画像があります。
<ul>
<li id='chain'>
<a href="">
<span class='fade'></span>
<div class='title'>TITLE</div>
<img src="img/bike/chain.jpg" alt="" width="550" height="440" />
</a>
</li>
<li id='grips'>
<a href="">
<span class='fade'></span>
<div class='title'>TITLE</div>
<img src="img/bike/grips.jpg" alt="" width="275" height="440" />
</a>
</li>
<li id='tires'>
<a href="">
<span class='fade'></span>
<div class='title'>TITLE</div>
<img src="img/bike/tires.jpg" alt="" width="175" height="220" />
</a>
</li>
</ul>
各セットのスパンと div に、すべての項目を手書きするのではなく、ループで表現されるように同じ幅を与える css が必要です
#chain .fade, #chain .title {width:550px}
#grips .fade, #grips .title {width:275px}
#tires .fade, #tires .title {width:175px;}
質問: jQuery を使用して CSS を動的に作成できますか? そうでない場合、この css を作成し、PHP を使用して幅の値を割り当てるにはどうすればよいですか?
リスト項目は頻繁に変更されるため、ループまたは .each ステートメントを使用したいと考えています。
言い換えれば、各アイテムのリストを作成したくないのです
が、li ID と IMG ディメンションを取得して動的に css
疑似コードを作成する方法はありますか?
var w = $('ul li').each(find img width).assign it to> .css(this .fade, this .title {width:w + "px"});
または
、php を調べて、各 ul li IMG の出力をエコーする必要がありますか?