2016-11-08 51 views
1

我有一個帶有兩個鏈接的菜單選項。當行換行時,<a>標籤比它包含的文本寬,使第二個'+'鏈接太遠。我可以使<a>標籤與其包含的文本一樣寬嗎?使<a>標記與文本寬度相同

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

<li>display: flex,所述<a>的是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

可能你必須包括你的代碼。 – Dragonmon

+2

可能的重複:[使容器縮小到適合子元素,因爲他們換行](http://stackoverflow.com/q/37406353/3597276) –

回答

0

嘗試將此添加到您的CSS。這將阻止文本進入下一行,並將使其佔用所需的所有空間。

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