2011-01-24 67 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更稳定。