如何修改我的四个象限以允许它们之间有一些“喘息空间”(HTML / CSS)?

时间:2016-08-09 18:12:52

标签: html css twitter-bootstrap margin padding

我已经能够根据接受的答案here在我的页面上创建四个等尺寸/形状的象限。

所以页面现在看起来像这样:

enter image description here

我现在想给象限一些“肘部空间” - 边缘周围有一些空白区域。我尝试在他们使用的类中添加边距:

.topleft {
  background-color: blue;
  margin: 4;
}
.topright {
  background-color: red;
  margin: 4;
}
.bottomleft {
  background-color: green;
  margin: 4;
}
.bottomright {
  background-color: yellow;
  margin: 4;
}

没有做任何事;我尝试了添加填充:

.topleft {
  background-color: blue;
  padding: 4;
}
.topright {
  background-color: red;
  padding: 4;
}
.bottomleft {
  background-color: green;
  padding: 4;
}
.bottomright {
  background-color: yellow;
  padding: 4;
}

......那也没有做任何事。

我需要做些什么来保持相同的1/4空间,但通过在它们之间增加边距或在它们周围填充来有效地“挤压”它们?

这是整个html / css:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>eServices Customer Dashboard</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>    <!--[if IE]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!-- Inline CSS (don't tell the CSS-Whisperers I did this!) -->
<style>
body {
    background-color: azure;
}
.body-content {
    -webkit-box-shadow: -1px 0 5px 0 #000000;
    -webkit-box-shadow: -1px 0 5px 0 rgba(0, 0, 0, .25);
    box-shadow: -1px 0 5px 0 #000000;
    box-shadow: -1px 0 5px 0 rgba(0, 0, 0, .5);
   padding-left: 1px;
   padding-right: 1px;
   padding-bottom: 15px;
}
.jumbotronjr {
  padding: 12px;
  margin-bottom: -16px;
  font-size: 21px;
  font-weight: 200;
  color: inherit;
  background-color: white;
}
.addltopmargin {
    margin-top: 8px;
}
.sectiontext {
    font-size: 1.5em;
    font-weight: bold;
    font-family: Candara, Calibri, Cambria, serif;
}
.bottommarginbreathingroom {
    margin-bottom: 2px;
}
.marginaboveandbelow {
    margin-top: 15px;
    margin-bottom: 15px;
}
.rightjustifytext {
  text-align: right;
}
table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
.contents{
  height:50%;
  width:100%;
}
redfont {
    color: red;
}
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-wrap: wrap;
}
.container div {
  display: inline-block;
  width: 50vw;
  height: 50vh;
  overflow-y: scroll;
}
.topleft {
  background-color: blue;
  padding: 4;
}
.topright {
  background-color: red;
  padding: 4;
}
.bottomleft {
  background-color: green;
  padding: 4;
}
.bottomright {
  background-color: yellow;
  padding: 4;
}
</style>
</head>

<body>

<div class="contents">
<div class="row">
<div class="col-md-6 topleft">
<h2>Top 10 Items Purchased</h2>
        <div>
            <input type="date" class="bottommarginbreathingroom" id="daterangefrom2" name="daterangefrom2">
            </input>
            <label> to </label>
            <input type="date" class="bottommarginbreathingroom" id="daterangeto2" name="daterangeto2">
            </input>
        </div>

        <table>
            <tr>
                <th>Item Code</th>
                <th>Description</th>
                <th>Qty</th>
            </tr>

            <tr>
                <td>Item Code 1</td>
                <td>Description 1</td>
                <td>Qty 1</td>
            </tr>
            <tr>
                <td>Item Code 2</td>
                <td>Description 2</td>
                <td>Qty 2</td>
            </tr>
            <tr>
                <td>Item Code 3</td>
                <td>Description 3</td>
                <td>Qty 3</td>
            </tr>
            <tr>
                <td>Item Code 4</td>
                <td>Description 4</td>
                <td>Qty 4</td>
            </tr>
            <tr>
                <td>Item Code 5</td>
                <td>Description 5</td>
                <td>Qty 5</td>
            </tr>
            <tr>
                <td>Item Code 6</td>
                <td>Description 6</td>
                <td>Qty 6</td>
            </tr>
            <tr>
                <td>Item Code 7</td>
                <td>Description 7</td>
                <td>Qty 7</td>
            </tr>
            <tr>
                <td>Item Code 8</td>
                <td>Description 8</td>
                <td>Qty 8</td>
            </tr>
            <tr>
                <td>Item Code 9</td>
                <td>Description 9</td>
                <td>Qty 9</td>
            </tr>
            <tr>
                <td>Item Code 10</td>
                <td>Description 10</td>
                <td>Qty 10</td>
            </tr>
        </table>
</div>

<div class="col-md-6 topright">
<h2>Pricing Exceptions - Weekly Recap</h2>
<h3 class="redfont">Red denotes Contract Item Overages</h3>
<h3>For Weyand on the pricing week of - 7/31/2016</h3>
        <table>
            <tr>
                <th>Invoice No</th>
                <th>Invoice Date</th>
                <th>Customer</th>
                <th>Cust #</th>
                <th>Item Code</th>
                <th>Description</th>
                <th>Member Item Code</th>
                <th>Member Description</th>
                <th>Bid Price</th>
                <th>Sell Price</th>
                <th>Qty</th>
            </tr>

            <tr>
                <td>Inv No 1</td>
                <td>Inv Date 1</td>
                <td>Customer 1</td>
                <td>Cust # 1</td>
                <td>Item Code 1</td>
                <td>Descrip. 1</td>
                <td>M.I. Code 1</td>
                <td>Memb Desc 1</td>
                <td>Bid Price 1</td>
                <td>Sell Pr. 1</td>
                <td>Qty 1</td>
            </tr>
            <tr>
                <td>Inv No 2</td>
                <td>Inv Date 2</td>
                <td>Customer 2</td>
                <td>Cust # 2</td>
                <td>Item Code 2</td>
                <td>Descrip. 2</td>
                <td>M.I. Code 2</td>
                <td>Memb Desc 2</td>
                <td>Bid Price 2</td>
                <td>Sell Pr. 2</td>
                <td>Qty 2</td>
            </tr>
            <tr>
                <td>Inv No 3</td>
                <td>Inv Date 3</td>
                <td>Customer 3</td>
                <td>Cust # 3</td>
                <td>Item Code 3</td>
                <td>Descrip. 3</td>
                <td>M.I. Code 3</td>
                <td>Memb Desc 3</td>
                <td>Bid Price 3</td>
                <td>Sell Pr. 3</td>
                <td>Qty 3</td>
            </tr>
        </table>
    </div>
</div>

<div class="row">
<div class="col-md-6 bottomleft">
<h2>Forecasted Spend</h2>
        <table>
            <tr>
                <th>Item</th>
                <th>Last Week's Usage</th>
                <th>This Week's Price</th>
                <th>Forecasted Spend</th>
            </tr>

            <tr>
                <td>Item 1</td>
                <td>52</td>
                <td>TWP 1</td>
                <td>68.00</td>
            </tr>
            <tr>
                <td>Item 2</td>
                <td>49</td>
                <td>TWP 2</td>
                <td>65.00</td>
            </tr>
            <tr>
                <td>Item 3</td>
                <td>46</td>
                <td>TWP 3</td>
                <td>63.00</td>
            </tr>
            <tr>
                <td>Item 4</td>
                <td>42</td>
                <td>TWP 4</td>
                <td>60.00</td>
            </tr>
            <tr>
                <td>Item 5</td>
                <td>40</td>
                <td>TWP 5</td>
                <td>58.00</td>
            </tr>
            <tr>
                <td>Item 6</td>
                <td>42</td>
                <td>TWP 6</td>
                <td>60.00</td>
            </tr>
            <tr>
                <td>Item 7</td>
                <td>43</td>
                <td>TWP 7</td>
                <td>61.00</td>
            </tr>
            <tr>
                <td>Item 8</td>
                <td>43</td>
                <td>TWP 8</td>
                <td>61.00</td>
            </tr>
            <tr>
                <td>TOTAL</td>
                <td>314</td>
                <td></td>
                <td>$496.00</td>
            </tr>
        </table>
    </div>

<div class="col-md-6 bottomright">
<h2>Fill Rate</h2>
        <table>
            <tr>
                <th>Unit</th>
                <th>Co. Name</th>
                <th>Desc</th>
                <th>Ord</th>
                <th>Ship</th>
                <th>Var</th>
            </tr>

            <tr>
                <td>Unit 1</td>
                <td>Co. Name 1</td>
                <td>Desc 1</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 2</td>
                <td>Co. Name 2</td>
                <td>Desc 2</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 3</td>
                <td>Co. Name 3</td>
                <td>Desc 3</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 4</td>
                <td>Co. Name 4</td>
                <td>Desc 4</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 5</td>
                <td>Co. Name 5</td>
                <td>Desc 5</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 6</td>
                <td>Co. Name 6</td>
                <td>Desc 6</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 7</td>
                <td>Co. Name 7</td>
                <td>Desc 7</td>
                <td>40</td>
                <td>39</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Unit 8</td>
                <td>Co. Name 8</td>
                <td>Desc 8</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
            </tr>
            <tr>
                <td>TOTAL</td>
                <td></td>
                <td></td>
                <td>280</td>
                <td>279</td>
                <td>1</td>
            </tr>
        </table>
    </div>
</div>


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

更新

添加填充只会使象限膨胀,不会在它们之间提供任何喘息空间。它或多或少看起来好像将“顶部”属性分配给第一个元素,将其向下推进。

添加边距(16像素)会导致象限在页面上垂直排列 - 全部在左边,没有在右边。这四个部分垂直堆叠,每个部分在下一个顶部堆叠。

4 个答案:

答案 0 :(得分:3)

marginpadding都采用CSS 长度单位。有许多不同的,因为它们以绝对单位(像素或px是最常见的)或相对的(emrem是最常见的)进行分类。您也可以使用由百分比%给出的维度值,即使它不是长度值。

有关完整列表和深入说明,请参阅here

在您的情况下,padding可能会帮助您,并且您可能希望使用比4px更大的值。

答案 1 :(得分:2)

不要向包含bootstrap column类的div添加新类。而是创建一个子div并将您的样式应用于内部div。

例如: 替换

<div class="row">
  <div class="col-md-6 topleft">
    ...
  </div>
</div>

 <div class="row">
   <div class="col-md-6">
     <div class="topleft">
        ...
     </div>
  </div>
</div>

这样你就可以控制外部div中容器的整体边界,并在内部div中设置样式(添加边距,填充)。

也可以像其他人建议的那样使用px / em单位作为填充/边距。

工作码本:http://codepen.io/anon/pen/vKQwyg

答案 2 :(得分:0)

给予单位margin&amp;像padding这样的px, em属性。试着给margin: 4px;。但是4px似乎很小。

答案 3 :(得分:0)

在边距/填充中添加单位,例如px(绝对值)或em(相对值)。请参阅:http://www.w3schools.com/css/css_padding.asp