【问题标题】:Seperator line between two divs两个 div 之间的分隔线
【发布时间】:2015-02-20 11:51:43
【问题描述】:

我正在尝试在 div/列之间实现分隔线,如下图所示。我尝试过应用带有 padding 和 margin 的边框,但这些都不起作用。我想知道实现这一目标的最佳方法是什么?

小提琴:

http://jsfiddle.net/Lr5d096n/1/

html

<div class="container-col">
    <div></div>
<div class="column-center">
    <div class="top-div">
        <img src="http://static.squarespace.com/static/523ce201e4b0cd883dbb8bbf/t/53bf2302e4b06e125c374401/1405035267633/profile-icon.png"></img>
     </div>
    <div class="bottom-div">
        <h5>headline</h5>
                <div class="game-table">
        <div class="game-item">
            <div class="game-home">home Team</div>
            <div class="game-vs">Vs.</div>
            <div class="game-away">away team</div>
        </div>
        </div>
        Nibh voluptua eleifend sed ne, ex melius maiorum vix, ea case percipit sit. Quo in scripta prodesset, ex nam sonet theophrastus. Read More ...
    </div>

</div>
<div class="column-left">
        <div class="top-div">
        <img src="http://static.squarespace.com/static/523ce201e4b0cd883dbb8bbf/t/53bf2302e4b06e125c374401/1405035267633/profile-icon.png"></img>
    </div>
    <div class="bottom-div">
        <h5>headline</h5>
                <div class="game-table">
        <div class="game-item">
            <div class="game-home">home Team</div>
            <div class="game-vs">Vs.</div>
            <div class="game-away">away team</div>
        </div>
        </div>
        Nibh voluptua eleifend sed ne, ex melius maiorum vix, ea case percipit sit. Quo in scripta prodesset, ex nam sonet theophrastus. Read More ...
    </div>
    </div>
<div class="column-right">

        <div class="top-div">
        <img src="http://static.squarespace.com/static/523ce201e4b0cd883dbb8bbf/t/53bf2302e4b06e125c374401/1405035267633/profile-icon.png"></img>
    </div>
    <div class="bottom-div">
        <h5>headline</h5>
        <div class="game-table">
        <div class="game-item">
            <div class="game-home">home Team</div>
            <div class="game-vs">Vs.</div>
            <div class="game-away">away team</div>
        </div>
        </div>
        Nibh voluptua eleifend sed ne, ex melius maiorum vix, ea case percipit sit. Quo in scripta prodesset, ex nam sonet theophrastus. Read More ...
    </div>
    </div>
</div>

css

.container-col { 高度:自动;显示:表格;边距底部:20px;}

.column-left{ float: left; width: 33.333%;  height: auto; padding-bottom: 20px; }
.column-right{ float: right; width: 33.333%; height: auto; padding-bottom: 20px; }
.column-center{ display: inline-block; width: 33.333%;  height: auto; padding-bottom: 20px; }

.top-div {

    height: auto;
}

.bottom-div {
  line-height: 18px;
    height:auto;
}

.bottom-div h5 {
    margin-top: 0px;
    margin-bottom: 10px;
    text-align: center;

}

.top-div img {
    width:100%;
    height: auto;
}

.game-table {
border-top: 1px dotted #aaa;
margin-bottom: 10px;
}


.game-item {
    padding: 8px 0px;
    border-bottom: 1px dotted #aaa;
    height: auto;

}

.game-home {
 float: left;
    width: 44%;
    margin-right: 2%;
    text-align: right;
}

.game-vs {
    width: 8%;
    margin-right: 2%;
     display: inline-block;
    text-align: center;

}

.game-away {
    float: right;
   width: 44%;
    text-align: left;

}

【问题讨论】:

  • 你可以用border-right来实现...
  • 试试这个 .column-center{ display: inline-block;宽度:32%;高度:自动;底部填充:20px;左边框:1px 实心#CCCCCC;右边框:1px 实心#CCCCCC; }
  • 您可以使用表格。或者,如果您不支持 IE,请使用带有边框(左/右)的 box-sizing: border-box;

标签: html css


【解决方案1】:

为了实现这一点,我在.center元素上使用了border-leftborder-right,我还整理了.column-left.column-rightcolumn-center元素的共同属性:

.column-left,
.column-right,
.column-center {
  width: 33.333333%;
  height: auto;
  /* causes the padding, and borders, to be included in the calculated
     width of the elements: */
  box-sizing: border-box;
  /* setting padding for the elements top, right, bottom, left: */
  padding: 0 0.5em 20px 0.5em;
  // setting the border for all elements: */
  border: 1px solid transparent;
}
.column-center {
  display: inline-block;
  /* overriding the transparent colour for the left and right borders: */
  border-left-color: #aaa;
  border-right-color: #aaa;
}

.container-col {
  height: auto;
  display: table;
  margin-bottom: 20px;
}
.column-left,
.column-right,
.column-center {
  width: 33.333333%;
  height: auto;
  box-sizing: border-box;
  padding: 0 0.5em 20px 0.5em;
  border: 1px solid transparent;
}
.column-left {
  float: left;
}
.column-right {
  float: right;
}
.column-center {
  display: inline-block;
  border-left-color: #aaa;
  border-right-color: #aaa;
}
.top-div {
  height: auto;
}
.bottom-div {
  line-height: 18px;
  height: auto;
}
.bottom-div h5 {
  margin-top: 0px;
  margin-bottom: 10px;
  text-align: center;
}
.top-div img {
  width: 100%;
  height: auto;
}
.game-table {
  border-top: 1px dotted #aaa;
  margin-bottom: 10px;
}
.game-item {
  padding: 8px 0px;
  border-bottom: 1px dotted #aaa;
  height: auto;
}
.game-home {
  float: left;
  width: 44%;
  margin-right: 2%;
  text-align: right;
}
.game-vs {
  width: 8%;
  margin-right: 2%;
  display: inline-block;
  text-align: center;
}
.game-away {
  float: right;
  width: 44%;
  text-align: left;
}
<br>
<div class="container-col">
  <div></div>
  <div class="column-center">
    <div class="top-div">
      <img src="http://static.squarespace.com/static/523ce201e4b0cd883dbb8bbf/t/53bf2302e4b06e125c374401/1405035267633/profile-icon.png"></img>
    </div>
    <div class="bottom-div">
      <h5>headline</h5>

      <div class="game-table">
        <div class="game-item">
          <div class="game-home">home Team</div>
          <div class="game-vs">Vs.</div>
          <div class="game-away">away team</div>
        </div>
      </div>Nibh voluptua eleifend sed ne, ex melius maiorum vix, ea case percipit sit. Quo in scripta prodesset, ex nam sonet theophrastus. Read More ...</div>
  </div>
  <div class="column-left">
    <div class="top-div">
      <img src="http://static.squarespace.com/static/523ce201e4b0cd883dbb8bbf/t/53bf2302e4b06e125c374401/1405035267633/profile-icon.png"></img>
    </div>
    <div class="bottom-div">
      <h5>headline</h5>

      <div class="game-table">
        <div class="game-item">
          <div class="game-home">home Team</div>
          <div class="game-vs">Vs.</div>
          <div class="game-away">away team</div>
        </div>
      </div>Nibh voluptua eleifend sed ne, ex melius maiorum vix, ea case percipit sit. Quo in scripta prodesset, ex nam sonet theophrastus. Read More ...</div>
  </div>
  <div class="column-right">
    <div class="top-div">
      <img src="http://static.squarespace.com/static/523ce201e4b0cd883dbb8bbf/t/53bf2302e4b06e125c374401/1405035267633/profile-icon.png"></img>
    </div>
    <div class="bottom-div">
      <h5>headline</h5>

      <div class="game-table">
        <div class="game-item">
          <div class="game-home">home Team</div>
          <div class="game-vs">Vs.</div>
          <div class="game-away">away team</div>
        </div>
      </div>Nibh voluptua eleifend sed ne, ex melius maiorum vix, ea case percipit sit. Quo in scripta prodesset, ex nam sonet theophrastus. Read More ...</div>
  </div>
</div>

参考资料:

【讨论】:

  • 是否可以在不删除分隔符的情况下删除左列的左填充和右列的右填充?
  • 当然应该,是的。
  • 从什么时候开始我只应用填充:0 0.5em 20px 0.5em;在中心列上,它们将是图像大小的差异到填充差异
  • 我明白你的意思;在这种情况下(经过一些实验),我会将我的回答修改为:“是的,可能;但不容易”,我还没有弄清楚如何做。
猜你喜欢
  • 2010-10-26
  • 2021-12-30
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 1970-01-01
  • 1970-01-01
  • 2012-06-23
  • 2018-07-01
相关资源
最近更新 更多