使用flex在垂直和水平居中时从跨度中删除下划线

时间:2019-03-21 18:53:44

标签: html css css3 flexbox

标签应该带下划线,但是跨度标签不能带下划线。

此解决方案不适用于我的情况:https://stackoverflow.com/a/13856365/11106685 当我使用flex将标签居中放置时。

https://jsfiddle.net/sebastian3495/sdbuz71v/

html, body {
  width: 100%;
  height: 100%;
}
.wrapper {
  background: rgba(0,0,0,0.3);
  width: 200px;
  height: 200px;
  display: flex;
}
.center {
  background: lightgreen;
  display: flex;
  align-items: center;
  flex-grow: 1;
  justify-content: center;
}
span {
  display: inline-block;
  text-decoration: none;
}
<div class="wrapper">
  <a class="center" href="https://stackoverflow.com/questions/19026884/flexbox-center-horizontally-and-vertically">
    Center me <span> <-- </span>
  </a>
</div>

1 个答案:

答案 0 :(得分:1)

a标记中删除下划线,将内容包装为跨度中的下划线,并在该特定跨度中添加下划线。

这里是有效的示例https://jsfiddle.net/whnbLfuo/

标签应该带下划线,但是跨度标签不能带下划线。

此解决方案不适用于我的情况:https://stackoverflow.com/a/13856365/11106685 当我使用flex将标签居中放置时。

https://jsfiddle.net/sebastian3495/sdbuz71v/

html, body {
  width: 100%;
  height: 100%;
}
.wrapper {
  background: rgba(0,0,0,0.3);
  width: 200px;
  height: 200px;
  display: flex;
}
.center {
  background: lightgreen;
  display: flex;
  align-items: center;
  flex-grow: 1;
  justify-content: center;
}
span {
  display: inline-block;
  text-decoration: none;
}

a {
    text-decoration: none;
}

.underline {
    text-decoration: underline;
}
<div class="wrapper">
    <a class="center" href="https://stackoverflow.com/questions/19026884/flexbox-center-horizontally-and-vertically">
        <span class="underline">Center me</span> <span> <-- </span>
    </a>
</div>