Welcome Guest, Not a member yet? Register   Sign In
foreach alternate like table
#5

[eluser]cideveloper[/eluser]
not sure what you are using this for but if its just to style alternating divs then you can use the nth child selector for css

HTML
Code:
<div id="alternating">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
</div>

CSS
Code:
#alternating>div{
    width: 50px;
    margin: 20px;
    padding: 20px;
    background-color: red;
}

#alternating>div:nth-child(2n) {
    background-color: blue;
}

The 2n means every second child of the parent selector gets these attributes. This type of selection can also be use with jquery.

So your code would look like this
Code:
<div id="alternating">
&lt;?php foreach($list as $item):?&gt;
<div>
code
</div>
&lt;?php endforeach;?&gt;
</div>


Messages In This Thread
foreach alternate like table - by El Forum - 01-12-2011, 04:07 PM
foreach alternate like table - by El Forum - 01-12-2011, 04:11 PM
foreach alternate like table - by El Forum - 01-12-2011, 04:13 PM
foreach alternate like table - by El Forum - 01-12-2011, 04:17 PM
foreach alternate like table - by El Forum - 01-12-2011, 07:43 PM
foreach alternate like table - by El Forum - 01-13-2011, 07:51 AM
foreach alternate like table - by El Forum - 01-13-2011, 01:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB