【问题标题】:how can I align some text inside a link styled as a button如何在样式为按钮的链接中对齐一些文本
【发布时间】:2021-08-28 08:30:00
【问题描述】:

我创建了一个看起来像按钮的链接,在 CSS 中具有与旁边的按钮相同的属性,但由于某种原因,看起来像按钮的链接中的文本有点高...有什么建议吗?

这是属性:

.submit,
.btn_advance_search {
  background-color: #f8f9fa;
  border: 1px solid #f8f9fa;
  border-radius: 4px;
  color: #3c4043;
  font-family: arial, sans-serif;
  font-size: 14px;
  margin: 11px 4px;
  padding: 0 16px;
  line-height: 27px;
  height: 36px;
  min-width: 54px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

我尝试了看起来像按钮的链接:

.btn_advance_search  {
   horiz-align: center;
}

没有成功。我也玩过顶部的填充,但这会使实际的按钮更大......

【问题讨论】:

  • 能否也分享一下HTML结构?
  • horiz-align 不是有效属性。它不存在。对于 flexbox,它被称为 align-items

标签: html css hyperlink alignment


【解决方案1】:

您可以使用 flex 居中对齐:

.btn_advance_search  {
   display: flex;
   flex-direction: column;
   justify-content: center;
   align-items: center;

   /* Add if the above styles don't take full height and width */
   height: 100%;
   width: 100%
}

【讨论】:

  • 您甚至可以将这些样式应用于searchadvanced search 按钮的公共类。
【解决方案2】:

您可以尝试将 line-height 更改为与元素的高度相同。确保元素上没有任何(垂直)填充。

你可以试试这个:

line-height: 36px;
height: 36px;

额外提示:如果您想防止元素在添加内边距时增长,您还可以在 CSS 中添加 box-sizing: border-box;

【讨论】:

  • 哦,非常感谢,它有效!并感谢盒子尺寸提示,不知道,非常有用!干杯!
猜你喜欢
  • 1970-01-01
  • 2015-07-06
  • 2015-07-04
  • 2021-06-01
  • 1970-01-01
  • 2022-12-29
  • 2011-10-28
  • 2020-05-06
  • 1970-01-01
相关资源
最近更新 更多