在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 3個盒子,在一個大盒子中,怎么讓3個盒子延中線居中

3個盒子,在一個大盒子中,怎么讓3個盒子延中線居中

在一個大盒子中有三個子盒子,怎么讓3個盒子延中線居中(注意是沿y軸的中線,不是那種用vertical-align:center沿X軸居中的效果)

回答
編輯回答
終相守

CSS:

        .div-container{
            position: absolute;
            left: 50px;
            top: 50px;
            width: 500px;
            height: 200px;
            line-height: 200px;
            box-sizing: border-box;
            border: 1px solid #cccccc;
            background-color: palegoldenrod;
            font-size: 0;
        }

        .div-inline{
            display: inline-block;
            width: 50px;
            height: 100px;
            vertical-align: middle;
            background-color: red;
            margin-left: 10px;
        }

        .div-inline:first-child{
            margin-left: 0px;
        }

HTML

    <div class="div-container">
        <div class="div-inline"></div>
        <div class="div-inline"></div>
        <div class="div-inline"></div>
        <div class="div-inline"></div>
        <div class="div-inline"></div>
        <div class="div-inline"></div>
        <div class="div-inline"></div>
        <div class="div-inline"></div>
    </div>
2018年2月5日 00:47
編輯回答
愚念

flex布局

<div class="big-box">
<div class="child-box"></div>
<div class="child-box"></div>
<div class="child-box"></div>
<div>
.big-box{
    display:flex;
    align-items:center;
}
2018年9月15日 01:43
編輯回答
夏木

更新回答,垂直方向水平居中

<style>
    .box {
        height: 100px;
        /* div水平居中直接margin: auto就行 */
        margin-left: auto;
        margin-right: auto;
    }
    .b1 {
        width: 80px;
        background-color: red;
    }
    .b2 {
        width: 40px;
        background-color: green;
    }
    .b3 {
        width: 100px;
        background-color: blue;
    }
</style>

<div class="wrap">
    <div class="box b1"></div>
    <div class="box b2"></div>
    <div class="box b3"></div>
</div>

以下是水平方向垂直居中

<style>
    .box {
        display: inline-block;
        width: 100px;
        vertical-align: middle;
    }
    .b1 {
        height: 80px;
        background-color: red;
    }
    .b2 {
        height: 40px;
        background-color: green;
    }
    .b3 {
        height: 100px;
        background-color: blue;
    }
</style>

<div class="wrap">
    <div class="box b1"></div>
    <div class="box b2"></div>
    <div class="box b3"></div>
</div>
2017年4月18日 00:20
編輯回答
凝雅
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    .root {
      width: 200px;
      height: 600px;
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      align-items: center;
      border: 1px solid red;
    }

    .root > div {
      width: 100px;
      height: 80px;
      border: 1px solid #000000;
    }
  </style>
<body>

<div class="root">
  <div>

  </div>
  <div>

  </div>
  <div>

  </div>
</div>
</body>
</html>

在線調試

2017年2月4日 02:42