簡體   English   中英

如何以<a href>固定寬度</a>顯示<a href>長文本</a>

[英]How to display <a href> long text with fix width

我有固定寬度的水平外來html -list,每個列表中的文本時間都更長,我需要將文本溢出到下一行,但沒有滾動條。

HTML

  ul.horizontal-funtions-list{ list-style-type: none; width: 100%; padding-left: 0; padding-top: 10px; padding-bottom: 10px; margin: 0; overflow-x:auto; white-space: nowrap; background-color: blueviolet; } ul.horizontal-funtions-list li{ display: inline-block; zoom:1; width: 100px; margin-left: 20px; padding: 20px; background-color: greenyellow; } ul.horizontal-funtions-list li a{ display: block; width: 80px; color:gray; } 
  <ul class="horizontal-funtions-list"> <li><a href="#Function A">I am long function name</a></li> <li><a href="#home">Home</a></li> </ul> 

我試過了display:在ul.horizo​​ntal-funtions-list li a中阻止,但無法正常工作

嘗試

ul.horizontal-funtions-list li a {
  display: block;
  color:gray;
  white-space: pre-wrap; /* css-3 */    
  white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
  white-space: -pre-wrap; /* Opera 4-6 */    
  white-space: -o-pre-wrap; /* Opera 7 */    
  word-wrap: break-word; /* Internet Explorer 5.5+ */

  /* OPTIONAL - FIXED height
    overflow: hidden;
    height: 50px;
  */
}

請注意width已刪除。
這是演示輸出的代碼段。


 ul.horizontal-funtions-list{ list-style-type: none; width: 100%; padding-left: 0; padding-top: 10px; padding-bottom: 10px; margin: 0; overflow-x:auto; white-space: nowrap; background-color: blueviolet; } ul.horizontal-funtions-list li{ display: inline-block; zoom:1; width: 100px; margin-left: 20px; padding: 20px; background-color: greenyellow; } ul.horizontal-funtions-list li a{ display: block; color:gray; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ overflow: hidden; height: 50px; } 
 <ul class="horizontal-funtions-list"> <li><a href="#Function A">I am long function name</a></li> <li><a href="#home">Home</a></li> </ul> 

  ul.horizontal-funtions-list{ list-style-type: none; width: 100%; padding-left: 0; padding-top: 10px; padding-bottom: 10px; margin: 0; overflow-x:auto; white-space: nowrap; background-color: blueviolet; } ul.horizontal-funtions-list li{ display: inline-block; zoom:1; width: 100px; margin-left: 20px; padding: 20px; background-color: greenyellow; } ul.horizontal-funtions-list li a{ display: block; width: 80px; color:gray; /*new style*/ white-space: pre-wrap; } 
  <ul class="horizontal-funtions-list"> <li><a href="#Function A">I am long function name</a></li> <li><a href="#home">Home</a></li> </ul> 

只為<a>標簽添加此CSS代碼white-space: pre-wrap;

試試這個代碼。

問題(和解決方案)

  • 如果您想包裝列表,請不要包含white-space: nowrap
  • 如果您不希望使用滾動條,則不要包含overflow-x: auto
  • 如果要讓列表項包含它們具有的文本,請不要在其上設置固定的width: 100px (也不要在其內部的width: 80px的錨點上)。

演示

我主要刪除您擁有的樣式的地方,並設置適當的paddingmargin以獲取正確的間距。

 ul.horizontal-funtions-list { margin: 0; padding: 0 20px 20px 0; background-color: blueviolet; list-style-type: none; } ul.horizontal-funtions-list li { display: inline-block; margin: 20px 0 0 20px; padding: 20px; background-color: greenyellow; } ul.horizontal-funtions-list li a { color: gray; } 
 <ul class="horizontal-funtions-list"> <li><a href="#Function A">I am long function name</a></li> <li><a href="#home">Home</a></li> <li><a href="#Function B">Another long function name</a></li> <li><a href="#Function C">Yet another</a></li> <li><a href="#Function D">We can keep going</a></li> </ul> <p>Space in between.</p> <ul class="horizontal-funtions-list"> <li><a href="#Function A">Shorter list</a></li> <li><a href="#home">Doesn't wrap</a></li> </ul> 

  • 刪除空格:nowrap;
  • 刪除ul.horizo​​ntal-funtions-list li寬度:100px;
  • 更改ul.horizo​​ntal-funtions-list li max-width:100px;

 ul.horizontal-funtions-list { list-style-type: none; width: 100%; padding-left: 0; padding-top: 10px; padding-bottom: 10px; margin: 0; overflow-x: auto; /* white-space: nowrap; */ background-color: blueviolet; } ul.horizontal-funtions-list li { display: inline-block; zoom: 1; /* width: 100px; */ margin-left: 20px; padding: 15px; background-color: greenyellow; } ul.horizontal-funtions-list li a { display: block; max-width: 100px; color: gray; } 
  <ul class="horizontal-funtions-list"> <li><a href="#Function A">I am long function name</a></li> <li><a href="#home">I am long function name2</a></li> </ul> 

從鏈接中刪除width屬性,並添加white-space: pre-wrap; 而已。

    ul.horizontal-funtions-list li a{
      /* width: 80px; */
      display: block;
      white-space: pre-wrap;
      color:gray;

    }

如何縮短長網址<div id="text_translate"><p>我有時會看到很長的網址,如下所示:</p><pre> "https://www.google.de/#hl=de&amp;sclient=psy-ab&amp;q=break+long+url+css&amp;oq=break+long+url+&amp;gs_l=serp.1.1.0i30l4.3822.3822.0.5634.1.1.0.0.0.0.85.85.1.1.0...0.0...1c.Hao7HfzLitY&amp;pbx=1&amp;bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&amp;fp=48c9a29cac04fd97&amp;biw=1680&amp;bih=925"</pre><p> 它非常煩人,因為它占據了很多地方。</p><p> 在我看來,我想給出它的簡短版本,比如 -&gt; "https://www.google.de/#hl=de&amp;sclient=psy-"</p><p> 但我會點擊它,然后再次登陸這個包含完整路徑的。</p><p> 我怎么能用 html a href="" 鏈接呢???</p></div>

[英]how to short long url in <a href="" .......?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM