css - 为什么 div 标签不能与 css 一起使用

标签 css

我在为我的产品列表页面设计 GridView 时遇到问题。我想要的是以每行显示四个产品并且每页最多三行的方式设置样式。目前,我拥有的是垂直显示的产品。有什么帮助吗? 我的 product.php 代码是:

<?php
                $result=mysql_query("select * from products") or die("select * from products"."<br/><br/>".mysql_error());
                while($row=mysql_fetch_array($result)){
            ?>  
        <div id="product-grid"> 
        <div class="product-item">
                <div class="product-image"><img src="<?php echo $row['picture']?>" /></div>
               <div><strong><?php echo $row['name']?></strong></div>
                        <div class="product-description"><?php echo $row['description']?></div>
                        Price:
                            <div class="product-price">$<?php echo $row['price']?></div>
                        <div><input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['serial']?>)" /></div>

            <?php } ?>.

我的风格是这样的,但是效果不理想。

body{width:610px;}
#product-grid {border-top: #F08426 2px solid;margin-bottom:30px;}
#product-grid .txt-heading{background-color: #FFD0A6;}
.product-item { float:left; background:#F0F0F0; margin:15px;    padding:5px;}
.product-price {color:#F08426;}
.product-image {height:100px;background-color:#FFF;}

我们将不胜感激。

最佳答案

你可以使用 flex

结帐下面的演示

demo

#product-grid {
  display: flex;
  flex-wrap:wrap;
}
.product-item {
  display: inline-block;
  background: #ccc;
  margin:10px 0 0 10px;    
  width: calc(100% * (1/4) - 12px - 1px)
}

关于css - 为什么 div 标签不能与 css 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36441317/

相关文章:

javascript - iCheck 插件无法在 ipad 和 iphone 上正常工作

html - 如何堆叠 div 列表以便没有垂直间隙?

HTML-多个不正确的水平对齐

html - 如何为 Google 表单创建自定义主题?

javascript - 如何在移动浏览器上有效地模糊视频?

javascript - 用类 'ul:first-child' 替换选择器 '.list_wrapper:first-child'

css - Drupal Omega 主题 : Centering the logo image

javascript - jquery函数不显示动画

html - 响应式图像 css 没有响应

html - 如何将 Div 精确限制为屏幕大小