Different CSS for divs in jQuery loop

This question already has an answer here:

  • What are valid values for the id attribute in HTML? 21 answers

  • You can give margin for each ids

    CSS:

    #a2 { margin-left: 200px; }
    #a3 { margin-left: 400px; }
    

    HTML :

    <div id="main">
       <div id="one" class="trip">Item1</div>
       <div id="two" class="trip">Item2</div>
       <div id="three" class="trip">Item3</div>
    </div>
    

    DEMO Here


    You can't start id's with a number in CSS. Try this

    HTML

    <div id="main">
        <div id="one" class="trip">Item1</div>
        <div id="two" class="trip">Item2</div>
        <div id="three" class="trip">Item3</div>
    </div>
    

    CSS

    #two{position:absolute; left:100px;top:100px;}    
    #three{position:absolute; left:200px;}
    

    或者你可以动态地给他们保证金,有些事情是这样的:

    function go() {
        $elem.eq(i % l).fadeIn(700, function() {
            $elem.css( { marginLeft :( (i+1) * 100)+ "px", marginRight :((i+1) * 100) + "px" } );
            $elem.eq(i % l).fadeOut(700, go);
            i++;
        })
    }
    
    链接地址: http://www.djcxy.com/p/15452.html

    上一篇: getElementById:IE问题

    下一篇: jQuery循环中div的不同CSS