开发者

Css display 3 foreach results per row

I have thi开发者_如何学Pythons asp.net code:

 @foreach( var database in Model)
 {

        if (!(firstTime == database.DB))
        {
          <h3> @database.DB </h3>
        }

           <div class="logContainer" onclick="location.href='/logs/Details?databaseID=@database.DB&exceptionName=@database.Exception&exceptionsOccurred=@database.Count';">
                <div class="counter"><b>@database.Count</b></div> 
                <div class="exceptionName"> Exceptions of Type: @database.Exception</div>
                <div class="date">Siste: @database.LastOccurred</div>
         <hr />   </div>


     firstTime = database.DB; 
}

And this CSS:

.logContainer
{
 width:500px;

}

.logContainer:hover 
{
cursor:pointer;
background-color:#ffffcc;
}


.counter {
height: 30px;
width:35px;
float:left;
background: none repeat scroll 0 0 #E6FFDC;
border: 1px solid #BBDD66;
text-align:center;
vertical-align:middle; 
line-height:1.5em;
font-size:1.5em;
}

.exceptionName
{
width:200px;
display:inline;
padding-left: 10px;
display: inline;
}

.date
{
font-size: 0.9em;
color:gray;
width:200px;
padding-left: 47px; 
}

What it does is to display the ouput row per row, and when the Dabase.DB changes it writes it and start again.

What I want is to display the output horizontally having 3 logcontainer per row, and if I encounter a new database.DB break it, write the name of the database and start from the left.

How should I do modify the code to do it?


Just make your .logcontainer float to the left, and every 3 display, clear the floating.

currentCol = 0
@foreach( var database in Model)
{

    if (!(firstTime == database.DB))
    {
      <h3> @database.DB </h3>
      currentCol = 0
    }

        <div class="logContainer" onclick="location.href='/logs/Details?databaseID=@database.DB&exceptionName=@database.Exception&exceptionsOccurred=@database.Count';">
            <div class="counter"><b>@database.Count</b></div> 
            <div class="exceptionName"> Exceptions of Type: @database.Exception</div>
            <div class="date">Siste: @database.LastOccurred</div>
        </div>

    currentCol += 1;
    if (currentCol = 2) { //3 columns were displayed, switch row
        currentCol = 0;
        <br style="clear:both" />
    }

    firstTime = database.DB; 
}

CSS :

.logContainer
{
  width:500px;
  float:left;
}

note: if the parent container of .logContainer is less than 1500px wide, you'll end up with a row of 2 columns followed by a row of 1 column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜