填充物从何而来?柔性盒为何重叠?

时间:2019-02-21 05:39:08

标签: html css flexbox

所以我从下而上自学HTML和CSS。我只是想自学CSS Flexbox。

我想开始做两个简单的专栏,但是由于某种原因它们重叠了,我不知道为什么。

正如您所看到的,我几乎在所有尝试中都尝试使用padding:0和margin:0来摆脱它,但是我似乎无法修复它,所以这一定是我还没有学过的属性< / p>

以下是代码:

http://jsfiddle.net/58cshkzy/14/

html:

<!doctype html>
<html lang="en">
  <html>
  <link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width = device-width, initial scale = 1">
    <title>My Webpage</title>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="styles/main.css">
  </head>

  <body>
    <div class="flex-container">
      <div class="row">
        <div class="flex-item">1</div>
        <div class="flex-item">2</div>
        <div class="flex-item">3</div>
        <div class="flex-item">4</div>
      </div>
      <div class="row2">
        <div class="flex-item">1</div>
        <div class="flex-item">2</div>
        <div class="flex-item">3</div>
        <div class="flex-item">4</div>
      </div>
    </div>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  </body>

  </html>

CSS:

html,
body {
  height: 100%;
  padding: 0px;
  width: 100%;
}

body {
  margin: 0;
  padding: 0px;
}

.flex-container {
  height: 100%;
  padding: 0;
  margin: 0;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
}

.row {
  width: 50%;
  border: 1px solid blue;
  padding: 0px;
  height: 100%;
}

.row2 {
  width: 50%;
  border: 1px solid blue;
  padding: 0px;
  margin-right: 0px;
  height: 100%;
}

.flex-item {
  background-color: tomato;
  padding: 0px;
  width: 20px;
  height: 20px;
  margin: 10px;
  line-height: 20px;
  color: white;
  font-size: 1em;
  font-weight: bold;
  text-align: center;
}

2 个答案:

答案 0 :(得分:2)

Bootstrap还具有一个名为array.map { |x| [:name, :number].zip(x.sub(',', ' ').split(',')).to_h } # => [{:name=>"John Doe", :number=>11222019}, {:name=>"Mark King", :number=>11232019}, {:name=>"Angle Darma", :number=>11242019}] 的类,该类的样式覆盖了您的样式。

因此将div类从row重命名为row1以查看效果。

也更改css文件中的类名。

row

答案 1 :(得分:0)

您使用引导程序,因此请使用引导程序类来制作此flexbox

html,
body {
  height: 100%;
  padding: 0px;
  width: 100%;
}

body {
  margin: 0;
  padding: 0px;
}

.wrap{
  border: 1px solid blue;
}


.flex-item {
  background-color: tomato;
  padding: 0px;
  width: 20px;
  height: 20px;
  margin: 10px;
  line-height: 20px;
  color: white;
  font-size: 1em;
  font-weight: bold;
  text-align: center;
}
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="container">    
  <div class="row">
      <div class="col-xs-6 wrap">
        <div class="flex-item">1</div>
        <div class="flex-item">2</div>
        <div class="flex-item">3</div>
        <div class="flex-item">4</div>
      </div>
      <div class="col-xs-6 wrap">
        <div class="flex-item">1</div>
        <div class="flex-item">2</div>
        <div class="flex-item">3</div>
        <div class="flex-item">4</div>
      </div>
    </div>
</div>