首页 > 解决方案 > 使用颜色使 div 顶部边框宽度增加到底部

问题描述

有人可以从以下内容中帮助我吗

在此处输入图像描述

到下面这个

在此处输入图像描述

我无法red用 CSS 制作这个边框。帮助表示赞赏。忽略 div 的宽度。我唯一需要帮助的是red背景部分。到目前为止我的代码:

.location-dtls {
    position: relative;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;

    display: flex;
    flex: 0 0 15%;
    max-width: 15%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 80px;
    overflow-wrap: break-word !important;
    cursor: pointer;
    text-align: center;
    margin-bottom: 1.5rem;
    margin: 0.5rem;
    border-width: 0.001rem;
    border-style: solid;
    border-radius: 1rem;
    border-color: #e4e2e2;
  }
<div class="location-dtls">
  <div>Location 5</div>
  <div>Location 5 FN</div>
</div>

标签: htmlcss

解决方案


您可以使用 pesudo 元素来执行此操作:

.location-dtls {
    position: relative;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;

    display: flex;
    flex: 0 0 15%;
    max-width: 15%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 80px;
    overflow-wrap: break-word !important;
    cursor: pointer;
    text-align: center;
    margin-bottom: 1.5rem;
    margin: 0.5rem;
    border-width: 0.001rem;
    border-style: solid;
    border-radius: 1rem;
    border-color: #e4e2e2;

}
 
.location-dtls::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 10px;
    background-color: red;
    border-radius: 1rem;
}
<div class="location-dtls">
  <div>Location 5</div>
  <div>Location 5 FN</div>
</div>


推荐阅读