html - 在 DIV 内对齐 DIV 组居中

标签 html css

我正在寻找类似 this 的东西但对于多个 DIV?我已经上传了一个页面,显示了我目前拥有的内容,可以找到 here .

同样在 Dreamweaver 上,它显示每个元素周围有 20 像素的填充,但是在 Google Chrome 上它显示不一样。我不确定这是为什么?

结论:

  1. 寻找一种使 DIV 在 DIV 中居中的方法。 (即使页面宽度发生变化。)

  2. 找出为什么元素没有像我在 Dreamweaver 中创建的那样显示。

HTML:

<html>
<head>
    <title>HELP</title>
    <link rel="stylesheet" href="../_scripts/stylesheet.css" />
    <link rel="stylesheet" href="../_scripts/stylesheet_divs.css" />
    <link rel="stylesheet" href="../_scripts/stylesheet_header.css" />
    <link rel="stylesheet" href="../_scripts/stylesheet_content.css" />
    <link rel="stylesheet" href="../_scripts/stylesheet_footer.css" />
</head>
<body>
<div class="background-image-1">
    <div align="justify" class="content-products">
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
        <div class="product-cell-bg padding-20">
            <div class="float-left product-cell"><img src="../_assets/fender.png" width="150" height="150"></div>
            <div class="float-left product-cell">Fenders</div>
        </div>
    </div>
</div>
</body>
</html>

最佳答案

听起来您需要将嵌套的 div 组显示为内联元素,然后在父 div 上声明 text-align: center > 元素。

.child {
    min-height: 50px;
    min-width: 250px;
    display: inline-block;
    background: #d2d2d2;
    padding: 10px;
    box-sizing: border-box;
    margin-top: 10px;
}

.parent {
    text-align: center;
}
<div class="parent">
  <div class="child">Child element</div>
  <div class="child">Child element</div>
  <div class="child">Child element</div>
  <div class="child">Child element</div>
  <div class="child">Child element</div>
</div>

关于html - 在 DIV 内对齐 DIV 组居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37905103/

相关文章:

c# - 如何更改下拉列表项的子字符串的颜色

html - CSS:赋予元素与 "grandparent"元素相同的宽度

css - Nivo 背景位置被忽略

php - 自动 <p> 正则表达式 - 需要修复

php - 使用图像作为文本

php - 如何删除自豪地由 Wordpress 条目 (RSS) 和评论 (RSS) 提供支持的网站名称

javascript - 阻止屏幕尺寸打开网站

html - Bootstrap 面板在整个页面 View 中对齐和组织

html - 3列布局的结构

html - CSS网格: Don't expand grid items