文本在 UL LI A 中没有换行

7

我有一个XSLT脚本来输出一个简单的垂直菜单,但是在我的一些链接上,文本没有换行,我不知道为什么!

Have tried to put a DIV inside the link, as well as a

to contain the text but to no avail.

Anybody had this kind of issue before?

XSLT:

    <xsl:template match="/">

  <xsl:variable name="items" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2]/* [@isDoc and string(umbracoNaviHide) != '1']"/>

<!-- The fun starts here -->
  <div id="subnavtitle">
  <xsl:value-of select="$currentPage/@nodeName" />
  </div>
<xsl:if test="count($items) &gt; 0">
<ul>
<xsl:for-each select="$items">
  <li>

    <xsl:if test="@id = $currentPage/@id">
        <xsl:attribute name="class">current</xsl:attribute>
      </xsl:if>
    <xsl:if test="@id = $currentPage/../@id">
        <xsl:attribute name="class">current</xsl:attribute>
      </xsl:if>
    <a href="{umbraco.library:NiceUrl(@id)}" >
      <p style="width: 100px;">
        <xsl:value-of select="translate(@nodeName,' ',' ')"/>
        </p>
    </a>

  </li>
</xsl:for-each>
</ul>
    </xsl:if>

</xsl:template>

CSS:

#subNavigation {
  padding-top: 10px;
  padding-right: 10px;
  padding-left: 10px;
  font-weight: bold;
  font-size: 12px;
  background-size: 100% auto;
  margin: 0px;

}
#subNavigation ul {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
}
#subNavigation ul:after {
  content: ".";
  display: block;
  font-size: 0;
  height: 0;
  clear: both;
  visibility: hidden;
}
* html #subNavigation ul {
  zoom: 1;
}
*:first-child + html #subNavigation ul {
  zoom: 1;
}
#subNavigation ul li {
  list-style-image: none;
  list-style-type: none;
  margin-left: 0px;
  white-space: nowrap;
  display: inline;
  float: left;
    background: url(Designit_Green/images/nav.png) repeat-x;
  margin-bottom: 10px;
  width: 150px;
}

#subNavigation li.current {
  background: #FFF url(Designit_Green/images/nav-item-activeXXX.png) left top repeat-x;
}
#subNavigation li.current a:hover {
  background: #FFF url(Designit_Green/images/nav-item-activeXXX.png) left top repeat-x;
}
#subNavigation li.current a {
  color: #333;
}
#subNavigation li:last-child {
  border: none;
}
#subNavigation a:link, #subNavigation a:visited {
  padding-left: 15px;
  padding-right: 0px;
  padding-top: 10px;
  padding-bottom: 10px;
  color: #FFF;
  display: block;
  text-decoration: none;

} 

You can take a look at the result here: http://bellstest.info/bar-restaurant.aspx The Issue is with the left hand navigation.


1
你应该提供输出HTML代码,而不是生成它的XSL源代码。另外,根据你的URL,左侧菜单中A元素内部有允许在HTML5中使用的P元素,但在旧浏览器中带有非HTML5解析器的情况下可能会出现问题。 - Marat Tanalin
谢谢,Marat。我把p元素放进去是为了尝试解决问题,但显然没有帮助。下次我提问时会提供HTML代码 :) - Owain Reed
XSLT中的空格处理会影响单词换行。使用display:inline-block;来控制li的宽度,使用display:block来控制锚点的宽度以控制超链接的宽度。 - Paul Sweatte
1个回答

24

你的#subNavigation ul li中有white-space: nowrap;属性,这个属性会被你的p标签继承。

将它改为white-space: normal;,或者在pa中添加white-space: normal;应该可以解决你的问题。


1
哦我的天啊 - 不知道我怎么错过了那个!!非常感谢 :D - Owain Reed
那是有史以来最好的解决方案! - Dark_Knight

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接