【问题标题】:How to touch the inner's div border to the outer's div bottom side?如何将内部的 div 边框触摸到外部的 div 底部?
【发布时间】:2019-05-22 14:54:19
【问题描述】:

我想将内部的 div 边框触摸到其外部的 div 底部,但不幸的是我不知道该怎么做。这是我的代码:

.clr {clear:both;}

#timeline {padding-top:50px; display:table;}
.timeline_cont {width:90%;}

.timeline_date_cont {/*float:left;*/ height:100%; width:200px; background:red; display:table-cell;}
.timeline_line_1 {border-right:2px dashed #c3c5c8; height:20px; width:50%;}
.timeline_line_2 {border-right:2px dashed #c3c5c8; height:100%; width:50%;}
.timeline_icon {background:#fff; border:1px solid #000; border-radius:50%; height:20px; line-height:20px; margin:0 auto; padding:3px; text-align:center; width:20px;}
.timeline_date {background:#fff; border-radius:10px; color:#2585fe; margin:0 auto; padding:5px; text-align:center; width:120px;}

.timeline_box_cont {/*float:left;*/ padding-bottom:50px; width:600px; background:blue;display:table-cell;}
.timeline_box {background:#fff; border-radius:10px; box-shadow:0px 0px 20px #c9cbce; line-height:20px; margin:0 auto; padding:20px; position:relative; }
<div id="timeline">
    <div class="timeline_cont">
        <div class="timeline_date_cont">
            <div class="timeline_icon">$</div>
            <div class="timeline_line_1">&nbsp;</div>
            <div class="timeline_date">6 days ago</div>
            <div class="timeline_line_2">&nbsp;</div>
        </div>
    <div class="timeline_box_cont"><div class="timeline_box customer_progress_list"><div class="customer_progress_menu_btn">&nbsp;</div><div></div><div class="customer_progress_info">update</div></div></div>
    <div class="clr"></div>
    </div>
    
    <div class="timeline_cont">
        <div class="timeline_date_cont">
        <div class="timeline_icon">$</div>
        <div class="timeline_line_1">&nbsp;</div>
        <div class="timeline_date">6 days ago</div>
        <div class="timeline_line_2">&nbsp;</div>
        </div>
        <div class="timeline_box_cont"><div class="timeline_box customer_progress_list"><div class="customer_progress_menu_btn">&nbsp;</div><div>lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is, lets see how good this porgress is,</div><div class="customer_progress_info">update</div></div></div>
        <div class="clr"></div>
    </div>
    <div class="timeline_cont">
        <div class="timeline_date_cont">
        <div class="timeline_icon">$</div>
        <div class="timeline_line_1">&nbsp;</div>
        <div class="timeline_date">6 days ago</div>
        <div class="timeline_line_2">&nbsp;</div>
        </div>
        <div class="timeline_box_cont"><div class="timeline_box customer_progress_list"><div class="customer_progress_menu_btn">&nbsp;</div><div></div><div class="customer_progress_info">update</div></div></div>
    <div class="clr"></div>
    </div>
</div> 

您可以看到美元符号下方的虚线边框。实际上我想扩展这个虚线边框并用下一个美元圆圈触摸它。我正在使用display:tabledisplay:table-cell 使div 的timeline_date_cont 和timeline_box_cont 的高度相等。但真的不知道如何扩展timeline_line_1 和timeline_line_2 的边界以相互接触顶部和底部。有什么想法吗?

【问题讨论】:

  • 我一直在试图摆弄,我现在只能告诉你的是display: table-cell 导致你的元素有某种margin,这会阻止线路连接。我尝试使用 Bootstrap 来解决这个问题,但要正确完成它似乎相当具有挑战性。您可能不想使用与使文档表现得像表格相关的任何东西。

标签: html css


【解决方案1】:

Do you want to get something like this?

.timeline_cont {
  display: flex;
}

.left {
  padding: 30px 0 30px 0;
  background: tomato;
  width: 200px;
  color: white;
  position: relative;
}

.left:after {
  content: '';
  width: 1px;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 1px dashed #ccc;
  z-index: 0;
}

.timeline_cont:first-child .left:after {
  top: 30px;
}



.timeline_cont:last-child .left:after {
  bottom: 30px;
}


.right {
    background: blue;
    width: 200px;
}

.timeline_icon {z-index: 2;position:relative;color:black;background:#fff; border:1px solid #000; border-radius:50%; height:20px; line-height:20px; margin:0 auto; padding:3px; text-align:center; width:20px;}
.timeline_date {z-index: 2;position:relative;background:#fff; border-radius:10px; color:#2585fe; margin:20px auto 0 auto; padding:5px; text-align:center; width:120px;}
<div class="timeline">
  <div class="timeline_cont">
      <div class="left">
        <div class="timeline_icon">$</div>
        <div class="timeline_date">6 days ago</div> 
      </div>
      <div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.      
      </div>
  </div>

  <div class="timeline_cont">
      <div class="left">
        <div class="timeline_icon">$</div>
        <div class="timeline_date">6 days ago</div>         
      </div>
      <div class="right">update</div>
  </div>  


  <div class="timeline_cont">
      <div class="left">
        <div class="timeline_icon">$</div>
        <div class="timeline_date">6 days ago</div>         
      </div>
      <div class="right">update</div>
  </div>   
</div>

【讨论】:

  • @10750057 虽然您的解决方案可以满足我的需要,但仍然存在一个问题。你给timeline_cont:first-child .left:aftertimeline_cont:last-child .left:after 提供了固定的顶部和底部。该值取决于&lt;div class="right"&gt; 中的内容。由于内容来自数据库并且由于本质上是动态的,因此这些用于第一个和最后一个 div 的 topbottom 无法正常工作。有时虚线不会触及圆形美元框,有时甚至会穿过“6 天前”div。有什么办法解决吗?
  • 我还发现 top 属性总是有效,但它的 bottom 属性有时会由于内容大小而失败。
  • 哦,这似乎很奇怪,因为我故意添加了“Lorem ipsum ...”文本来考虑这种情况。您也可以添加对齐项目:拉伸;到 .timeline_cont
  • 我从来没有听说过这个属性。我找不到任何其他解决方案来解决这个奇怪的罕见问题。
  • 好的,如果你从未听说过 align-itmes,你可以阅读更多关于 flexbox 的信息。我相信它可以帮助您找到解决方案css-tricks.com/snippets/css/a-guide-to-flexbox
【解决方案2】:

click the image to see your answer

你可以像这样改变css你也可以参考图片

.timeline_line_2 {
border-right: 2px dashed #c3c5c8;
height: 53px;
width: 74px;
/* padding: 13px 0px 0px 0px; */
background-color: green;
position: absolute;

}

【讨论】:

  • 绝对错误的答案。您刚刚给出了固定高度 53px,它只修复了第一个 div 边框。由于内容是动态的,我们无法提供预先固定的高度,因此您的解决方案将永远无法工作。
  • 我的解决方案是针对静态内容的,现在您可以使用 css 修改您的动态内容。请给我一些时间以获得更好的解决方案,抱歉让您回到错误的解决方案
【解决方案3】:

您可以按照我在另一篇文章中找到的this 解决方案做一些事情:

/* Reset Bootstrap props where needed: */

#timeline>.row .col-3,
#timeline>.row .col-9 {
  padding: 0;
}

#timeline .timeline-icon {
  box-sizing: content-box;
}

#timeline>.row:first-of-type .col-3:first-of-type>.left {
  padding-top: 10px;
}


/* Actual coding: */

.left {
  background-color: red;
}

.right {
  background-color: blue;
}

.left,
.right {
  height: 100%;
}

.timeline-icon {
  background-color: #fff;
  width: 20px;
  text-align: center;
  border: 1px solid #000;
  border-radius: 50%;
  padding: 3px;
  margin: 0 auto;
  z-index: 1;
  position: relative;
}

.timeline_date {
  background: #fff;
  border-radius: 10px;
  color: #2585fe;
  margin: 0 auto;
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 5px;
  text-align: center;
  width: 120px;
  position: relative;
  z-index: 1;
}

.timeline-box {
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 10px;
}

.left:after {
  content: "";
  position: absolute;
  z-index: 0;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 2px dashed #c3c5c8;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" id="timeline">
  <div class="row">
    <div class="col-3">
      <div class="left">
        <div class="timeline-icon">
          $
        </div>
        <div class="timeline_date">
          6 days ago
        </div>
      </div>
    </div>
    <div class="col-9">
      <div class="right">
        <div class="timeline-box">
          Foo
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-3">
      <div class="left">
        <div class="timeline-icon">
          $
        </div>
        <div class="timeline_date">
          6 days ago
        </div>
      </div>
    </div>
    <div class="col-9">
      <div class="right">
        <div class="timeline-box">
          Bar
        </div>
      </div>
    </div>
  </div>
</div>

JSFiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 2017-01-30
    • 2018-02-08
    • 2011-01-09
    • 2011-06-25
    • 2020-03-15
    • 2013-12-30
    相关资源
    最近更新 更多