如何集中dinamic元素

时间:2016-08-30 20:09:35

标签: css centralized

enter image description here

我试图在div(.swat-container)上集中颜色(.attr-image-container)但没有任何作用,所以,PLZ,有人可以帮助我吗?

我试过了保证金:0px auto;在许多地方ehuehu

enter image description here

我的HTML:

<dd class="last">
<div class="input-box">
    <div class="settings-swatch-container">
        <div class="swat-container">
            <div class="attr-image-container">
                <div class="attr-image" alt="Amarelo" title="Amarelo" style="background-color:#FFF700;"></div>
            </div>
            <div class="attr-image-container">
                <div class="attr-image" alt="Azul Escuro" title="Azul Escuro" style="background-color:#005EFF;"></div>
            </div>
            <div class="attr-image-container">
                <div class="attr-image" alt="Verde" title="Verde" style="background-color:#4DFF29;"></div>
            </div>
        </div>
    </div>
</div>

Mycss

.swat-container{
    width:100%;
    height:100%;
    margin:auto;
}

.attr-image
{
    width: 30px;
    height: 30px;
    padding: 1px;
    margin-right: 5px; 
    cursor:pointer;
    border: 2px solid #00BFFF;
}

.main-swatch-container
{
    width: 100%;
    clear: both;
    margin:auto;
}

.attr-image-container
{
    float:left;
    position:relative;
    text-align: center;
}

1 个答案:

答案 0 :(得分:0)

使用flex ...

dd {
  padding: 0;
  margin: 0;
}
.swat-container {
  width: 100%;
  height: 100%;
  margin: auto;
  display: flex;
  justify-content: center;
}
.attr-image {
  width: 30px;
  height: 30px;
  padding: 1px;
  margin-right: 5px;
  cursor: pointer;
  border: 2px solid #00BFFF;
}
.main-swatch-container {
  width: 100%;
  margin: auto;
}
.attr-image-container {
  position: relative;
  text-align: center;
}
<dd class="last">
  <div class="input-box">
    <div class="settings-swatch-container">
      <div class="swat-container">
        <div class="attr-image-container">
          <div class="attr-image" alt="Amarelo" title="Amarelo" style="background-color:#FFF700;"></div>
        </div>
        <div class="attr-image-container">
          <div class="attr-image" alt="Azul Escuro" title="Azul Escuro" style="background-color:#005EFF;"></div>
        </div>
        <div class="attr-image-container">
          <div class="attr-image" alt="Verde" title="Verde" style="background-color:#4DFF29;"></div>
        </div>
      </div>
    </div>
  </div>
</dd>