doujupa7567 2014-12-14 08:21
浏览 13
已采纳

CSS / PHP:如何使下一个div出现在侧面

I'm stuck on the project that I am doing right now. I made a php that outputs a single div, this div will output multiple times depending on the number of items that I have in my database, my problem is that, I want the next div to be outputted on the left side of the previous div, just like this:

 -----   -----   -----
|div 1| |div 2| |div 3|
 -----   -----   -----
 -----   -----   -----
|div 4| |div 5| |div 6|
 -----   -----   -----

But I can't think of any ways to do it, it's outputting as it should be like this:

 -----
|div 1|
 -----
 -----
|div 2|
 -----
 -----
|div 3|
 -----
and so on...

Hope you guys can help me, thanks.

PHP:

$results = $mysqli->query("SELECT * FROM content");
    if ($results) { 

    //fetch results set as object and output HTML
    while($obj = $results->fetch_object())
        {
        echo '<div class="content">'; 
        echo '</div>';
        }
    }

CSS:

.content{
    margin-bottom: 10px;
    height: 300px;
    background: #F0F0F0;
    padding: 10px;
    border: 1px solid #DDD;
    border-radius: 5px;
    box-shadow: 2px 2px 2px #F8F8F8;

}

展开全部

  • 写回答

2条回答 默认 最新

  • dpa0760 2014-12-14 08:26
    关注

    need a wrap div for class="content"

    $results = $mysqli->query("SELECT * FROM content");
        if ($results) { 
    
        //fetch results set as object and output HTML
        while($obj = $results->fetch_object())
            {
            echo '<div class="box"><div class="content">'; 
            echo '</div></div>';
            }
        }
    

    and the css

    .box{
         width: 33.333333333%;
         box-sizing: border-box;
         float: left;
         }
    

    here is demo http://jsfiddle.net/taunj8m0/2/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部