【问题标题】:Vertical align button while it is floating right向右浮动时的垂直对齐按钮
【发布时间】:2021-09-03 00:55:00
【问题描述】:

我正在尝试vertical-align 我的按钮,但我似乎无法让它工作。下面是我正在使用的 CSS。

我尝试过positionvertical-align 等,但没有任何效果。

这里是我想要的图片供参考:

.item-card {
  display: block;
  font-family: Titillium Web, sans-serif;
  box-shadow: rgba(0, 0, 0, 0.15) 0 5px 20px;
}

.item-card:focus {
  border: #b20c1c solid;
}

.item-card:hover {
  box-shadow: rgba(0, 0, 0, 0.35) 0 5px 15px;
}

.justified-list {
  padding: 5px;
  width: 100%;
  margin: 0;
}


button {
  background: none;
  color: inherit;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  outline: inherit;
}

button:hover:active:focus {
  background-color: white;
  color: #61070f;
}

.jl-item {
  padding: 10px 10px 10px;
  display: block;
}

.jl-item:focus {
  border: #61070f solid;
}

.btn-hent-pass {
  color: #b20c1c;
  text-decoration: none;
}

.float {
  max-width: 1200px;
  margin: 0 auto;
}

.float:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}


.last {
  float: right;
}
<div class="item-card float">
  <ul class="justified-list">
    <li class="jl-item float-item" tabindex="0">06/12/2022</li>
    <li class="jl-item float-item" tabindex="0" *ngIf="additionalText.length > 0">1/2</li>
    <li class="jl-item last float-item"><button class="btn-hent-pass" (click)="btnClick.emit()"  ><span style="margin-right: 5px">Get Data</span></button>
    </li>

  </ul>
</div>

【问题讨论】:

标签: html css


【解决方案1】:

Div 元素是 display: "block" 这意味着它们占据了页面的整个宽度。

要修复您的排列,您将需要某种网格布局或弹性容器。

我建议你阅读this(网格)和this(弹性)。

更新:由于 OP 要求,对于旧版支持的网格,您可以找到更多信息 here

一个简单的例子...

HTML:

<div class="row">
  <ul class="col-1">
    <li>test</li>
    <li>test 2</li>
  </ul>
  <button class="col-2">
    Get Data
  </button>
</div>

CSS:

.row {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}
.col-1 {
    width: 40%;
    float: left;
}
.col-2 {
    width: 40%
    float: right;
}

【讨论】:

  • 有什么我可以不使用这两个,因为我需要旧版支持:(
  • 我对 flex / grid 真的很陌生,你能给我一个例子来说明我如何用这些来解决它吗? (对不起,如果我问的太多了)
  • 刚刚更新了我的答案,看看吧。这是一个简单的示例,可能并不完美,但它应该对您的情况有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-06
  • 1970-01-01
相关资源
最近更新 更多