javascript - 可折叠列表 - 使用多行显示所有标题

标签 javascript jquery html css jquery-mobile

我在修改以下代码以使其在移动设备上正确显示时遇到问题,我从 W3 Schools 可折叠列表教程中复制了它并针对桌面设备正确修改了它。

但是在移动设备上,一半的文字被省略号 chop 了。

桌面

Desktop Image

移动

Mobile Image

我们将不胜感激任何帮助。 理想情况下,我想让标题部分跨越多行。

查看下面的代码了解更多信息。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>

<div data-role="page" id="pageone">

    <div data-role="collapsible">
    <h4>Do I need to buy now?</h4>
No. Sign up for a free 30-day trial now. With NO obligations.
    </div>

    <div data-role="collapsible">
    <h4>Is the free trial fully functional?</h4>
Yes. The free trial comes with all of S2L features. You can give it a test run before you buy.
    </div>

    <div data-role="collapsible">
    <h4>Do I need a credit card to sign up for the trial?</h4>
No. We do not collect payment information until you are ready to buy.
    </div>

    <div data-role="collapsible">
    <h4>Do you provide a discount for yearly plans?</h4>
     Yes. You save 10% if you choose to pay yearly.
    </div>

    <div data-role="collapsible">
    <h4>How do I activate my trial to a paid version?</h4>
Once you have entered your payment information, you will receive an activation code by mail. <br>
Enter the code into the application and you are ready to go.
    </div>

  </div>
</body>
</html>

最佳答案

好吧,现在它在溢出时使用带有 white-space: nowrap; 的省略号,而不是换行。给你的文本一个 white-space: normal;

CSS:

#pageone > div a {
  white-space: normal;  
}

#pageone > div a {
  white-space: normal;  
}
<!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    </head>
    <body>

    <div data-role="page" id="pageone">

        <div data-role="collapsible">
        <h4>This title is super long and will overflow to a new line instead of using an ellipsis.</h4>
    No. Sign up for a free 30-day trial now. With NO obligations.
        </div>

        <div data-role="collapsible">
        <h4>This title is super long and will overflow to a new line instead of using an ellipsis.</h4>
    Yes. The free trial comes with all of S2L features. You can give it a test run before you buy.
        </div>

        <div data-role="collapsible">
        <h4>This title is super long and will overflow to a new line instead of using an ellipsis.</h4>
    No. We do not collect payment information until you are ready to buy.
        </div>

        <div data-role="collapsible">
        <h4>This title is super long and will overflow to a new line instead of using an ellipsis.</h4>
         Yes. You save 10% if you choose to pay yearly.
        </div>

        <div data-role="collapsible">
        <h4>This title is super long and will overflow to a new line instead of using an ellipsis.</h4>
    Once you have entered your payment information, you will receive an activation code by mail. <br>
    Enter the code into the application and you are ready to go.
        </div>

      </div>
    </body>
    </html>

关于javascript - 可折叠列表 - 使用多行显示所有标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37926784/

相关文章:

javascript - VueJS 2 v-for表单输入单选按钮检查属性不起作用

javascript - 如何将 GUID 从 View 传递到 JavaScript?

javascript - 按特定顺序进行数组打印

javascript - 突出显示 slider 中的中间 div

javascript - 用javascript检测Android(不是chrome)?

javascript - 通过单击相应行上的按钮获取特定的表行值

jquery - div位置固定在滚动条上,在页面顶部之前开始

javascript - 按字典序排列

php - Jquery jTable PHP+MySQL 不更新

jquery - 如何截断/剪辑位于其下方的文本形状的div?