【问题标题】:Bootstrap CSS button fixed position after textBootstrap CSS按钮在文本后固定位置
【发布时间】:2017-08-21 03:35:57
【问题描述】:

我正在尝试在列中设置带有信息的卡片。由于显示的文本有不同的长度,我想修复与卡片末尾相关的 Learn More 按钮的位置,因此无论之前发生什么,按钮始终对齐。

此外,我想在行之间分隔卡片,但我还没有找到解决方案,因为如果我更改边距,它只会应用于最后一行。

这是我的代码:

<div class="row my-flex-card">
    <div class= "col-xs-4 col-sm-4 col-md-4 col-lg-4" ng-repeat="woman in women">
        <!--Card-->
          <div class="card">
              <!--Card image-->
              <img class="img-fluid" ng-src="{{woman.image_url}}" alt="{{woman.name}}">
              <!--Card content-->
              <div class="card-body inline-block">
                  <!--Title-->
                  <h4 class="card-title">{{woman.name}}</h4>
                  <!--Text-->
                  <p class="card-text"> <h5>{{woman.field}}</h5> <br> {{woman.job}}</p>
                  <a class="btn btn-success" href="#!/women/details/{{woman._id}}">Learn more</a>
              </div>

          </div>

          <!--/.Card-->
    </div>
  </div>

我的 CSS:

.my-flex-card > div > div.card {
  height: calc(100% - 15px);
  margin-bottom: 15px;
}

.row {
  margin-bottom: 50px;
}

那个 .row 功能不起作用。

这就是我的网站现在的样子:

谢谢你:)

【问题讨论】:

  • 我建议为.card-text 设置一个固定的height 值,而不是进行定位。它可能正是你想要的。如果段落包含太多文本,您也可以使用text-overflow: ellipsis 来避免溢出。
  • 我试过了,但是没有用,因为它在标题和文本之间创建了一个巨大的空间然后显示它......此外,我想显示整个段落,它出现了在按钮后面。

标签: html css twitter-bootstrap


【解决方案1】:

.parent {
  display: flex;
  flex-direction: row;
  padding: 10px;
}
.parent .child {
  padding-right: 10px;
  flex-grow: 1;
  width: 33%;
  position:relative;
}
.parent .child .content {
  height: 100%;
  box-shadow: 0 0 1em gray;
}
.content img{
 background-size:cover;
 width:100%;
}
.content h3,p{
padding:10px;
}
.content input{
position:absolute;
bottom:5px;
margin-left: 35%;
margin-top:10px;
}
<div class="parent">
  <div class="child">
    <div class="content">
      <div>
        <img  src="https://www.w3schools.com/html/pic_mountain.jpg"/>
        <h3> test 3</h3>
        <p>text text text text text text text text text text text text text text text text text text text</p>  
        </div>
         <div><input type="button" value="click" /></div> 
      </div>
    </div>
  <div class="child">
    <div class="content">  
       <div>
         <img  src="https://www.w3schools.com/html/pic_mountain.jpg"/>
         <h3> test 2</h3>
         <p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text tex </p>
        </div>
         <div><input type="button" value="click" /></div> 
     </div>
 </div>
  <div class="child">
    <div class="content">
       <div>
         <img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
         <h3> test 1</h3>
         <p>text text  text text text text text text text text text text tex</p>  
       </div>
       <div><input type="button" value="click" /></div> 
    </div>
  </div>
</div>

【讨论】:

    【解决方案2】:

    制作相对位置的盒子类:

    .boxClassName{
    position:relative
    }
    

    然后使用以下内容制作按钮类:

      .buttonClassName{
        position:absolute;
        bottom:0;
        }
    

    【讨论】:

    • 谢谢!它可以工作,按钮是对齐的(不居中 -.-'),但现在文本继续在它们后面,所以看起来很糟糕
    • .card 上设置一个padding-box: 60px 之类的东西来创建一些空间。
    • 不工作。 Css 无法识别 padding-box,可能是因为我使用的是 bootstrap 4??
    猜你喜欢
    • 2012-12-29
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2011-07-13
    • 2014-10-30
    相关资源
    最近更新 更多