我有兩個元素;即一個跨度,然後是一個div。跨度的內容應該具有長度爲25到30個字符的最大值,並且div的內容可以是段落(並且這兩個內容都是動態的)。我的客戶想要的是將div的寬度設置爲與跨度相同(不存在高度問題)。現在我使用JS實現了這一點,並且工作正常,我們可以使用CSS來做到這一點,這樣我的生活將會變得更加輕鬆嗎?根據前一跨度的寬度將動態寬度設置爲div
感謝您的回覆。
Tismon Varghese。
編輯:請參考下面
<div class="wrapper">
<span class="summary-headder"> Header Header Header Header Header </span>
<div class="summary-comment" style="width: 495px;">
test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment
</div>
</div>
var summary_headder_width = $('.summary-headder').width();
$('.summary-comment').css('width', summary_headder_width + 'px');
我們可以看到代碼做呢? – Naele
請參閱編輯部分 – user2869757