简体   繁体   English

CSS div宽度问题

[英]Css div width problem

i have div with 500px width which contains multiple anchors... problem anchors not wrapping in to multiple lines.... i tried using table as well same problem.... 我有500px宽度的div,其中包含多个锚点...问题锚点没有包裹到多行中。...我尝试使用表格以及同样的问题...。

<div  style="width:500px;">
    <a href="#procrit">procrit</a>&nbsp;
    <a href="#doxil">doxil</a>&nbsp;
    <a href="#prezista">prezista</a>&nbsp;
    <a href="#simponi">simponi</a>&nbsp;
    <a href="#reopro">reopro</a>&nbsp;
    <a href="#topamax">topamax</a>&nbsp;
    <a href="#invega">invega</a>&nbsp;
    <a href="#axert">axert</a>&nbsp;
    <a href="#aciphex">aciphex</a>&nbsp;
    <a href="#concerta">concerta</a>&nbsp;
    <a href="#risperdal">risperdal</a>&nbsp;
    <a href="#remicade">remicade</a>&nbsp;
    <a href="#velcade">velcade</a>&nbsp;
    <a href="#doxil">doxil</a>&nbsp;
    <a href="#regranex">regranex</a>&nbsp;
    <a href="#nucynta">nucynta</a>&nbsp;
    <a href="#duragesic">duragesic</a>&nbsp;
    <a href="#leustatin">leustatin</a>&nbsp;
    <a href="#invega">invega</a>&nbsp;
    <a href="#sustenna">sustenna</a>&nbsp;
    <a href="#reminyl">reminyl</a>&nbsp;
    <a href="#natrecor">natrecor</a>&nbsp;
</div>

Try replacing &nbsp; 尝试更换&nbsp; with just a space character. 只是一个空格字符。 &nbsp; prevents the browser from wrapping words it is attached to. 防止浏览器包装其附加的单词。 Each <a> will not appear on a new line, but it will successfully wrap if it no longer fits its container if using normal spaces. 每个<a>不会出现在新行上,但是如果使用常规空格,如果它不再适合其容器,它将成功包装。

If there is no white-space between the anchors, it is considered all one string and therefore can not wrap. 如果锚点之间没有空格,则将其视为所有一个字符串,因此无法换行。 You could try to use the CSS rule word-wrap to help with this, but some browsers may not honor such a setting. 您可以尝试使用CSS规则word-wrap来解决此问题,但是某些浏览器可能不支持这种设置。

Simple solution is to change &nbsp; 简单的解决方案是更改&nbsp; to an actual spaces. 到一个实际的空间。 Or use a <ul> and have the <li> display: inline; 或使用<ul>display: inline; <li> display: inline; . The latter is arguably more semantic. 后者可以说是更具语义的。

Use float:left;margin-right:5px 使用float:left;margin-right:5px

&nbsp; is a naughty way to force spacing; 是强制间隔的顽皮方法; you'll get much more consistent and professional results with good CSS (in this case, margin ). 良好的CSS(在这种情况下为margin ),您将获得更加一致和专业的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM