制作<a> tag same width as text

时间:2016-11-08 21:41:11

标签: html css flexbox

I have a menu option with two links. When the line wraps, the <a> tag is wider than the text it contains, making the second '+' link too far away. Can I make the <a> tag just as wide as the text it contains?

<li class="has-submenu">
  <a href="/pages/litigation">Litigation & Dispute Resolution</a>
  <a class="expand-nav" href="#">+</a>
</li>

The <li> is display: flex, the <a>'s are display: inline-block.

When text is on one line, the width is fine When the text breaks to a newline, the the <a> tag is wider than the text

1 个答案:

答案 0 :(得分:0)

尝试将此添加到CSS中。这将阻止文本进入下一行,并使其占用所需的所有空间。

.has-submenu a:nth-child(1){
     white-space:nowrap;
     width:auto;
}