2011-01-24 48 views
0

我想要的.nivo-controlNav寬度自動適應寬度+餘量.nivo-controlNav a如何定義(使用PHP或jQuery)一個div的寬度以適應錨內標籤的寬度+邊距?

代碼:

.nivo-controlNav { 
    margin: 480px auto 0; 
    overflow: hidden; 
    width: 200px; 
} 
.nivo-controlNav a { 
    background: url(images/bullets.png) no-repeat; 
    border: 0; 
    float: left; 
    text-indent: -9999px; 
    margin-right: 3px; 
    width: 22px; 
    height: 22px; 
} 
+0

看起來好像你真的想自動化.nivo-controlNav的對中 – kjy112 2011-01-24 19:28:41

+1

@ kjy112它變成了一種癡迷。 – alexchenco 2011-01-24 19:31:21

+0

如果我沒有記錯,那麼在nivo-slider上有一個github回購。也許你想嘗試那裏。 https://github.com/gilbitron/Nivo-Slider – kjy112 2011-01-24 19:34:41

回答

0

我終於做到了:

// calculate outerWidth of .nivo-controlNav 
    var customWidth = $j('.nivo-controlNav a').outerWidth(true); 
    // Returns the number of matched elements 
    var customNumber = $j('.nivo-controlNav a').size(); 
    $j('.nivo-controlNav').css("width", customWidth*customNumber); 
0

我不知道這是否是你問什麼,而是你可以使用jQuery outerWidth()

$(document).ready(function(){ 
var customWidth = $('.nivo-controlNav a').outerWidth(true); 
$('.nivo-controlNav').css("width",customWidth); 
}); 
0

難道你不能只告訴.nivo-controlNavfloat:left?聽起來你正在使用某種框架,這可能需要一些解決方法,但它似乎比使用JavaScript更穩定。

相關問題