简体   繁体   English

在JQuery移动ListView中格式化文本

[英]Formatting text in JQuery mobile ListView

I would like to have the "lorem ipsum" text extend as far as possible to the right. 我希望“ lorem ipsum”文本尽可能向右扩展。 However, when I add the "Some Text" label to the right side of the listview, the "lorem ipsum" text no longer breaks as far to the right as it did without it. 但是,当我将“ Some Text”标签添加到列表视图的右侧时,“ lorem ipsum”文本不再像没有它时那样折断到右侧。 How do I have to override the CSS classes in order to get the desired format? 我必须重写CSS类以获得所需的格式吗? (I have tried to override the JQ mobile CSS files (.ui-li-aside formats the label I believe). See the jsfiddle link for an example with the label and without. (我尝试覆盖JQ移动CSS文件(.ui-li-aside格式化我相信的标签)。有关带标签和不带标签的示例,请参见jsfiddle链接。

http://jsfiddle.net/soa9k46w/1/ http://jsfiddle.net/soa9k46w/1/

<div data-role="content">
    <ul data-role="listview" data-icon="false">
        <li>    <a href="#">

                      <h2>Some Title</h2>

                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

                      </a>

            <p class="ui-li-aside ui-li-count"><strong> Some Text</strong>
            </p>
        </li>
    </ul>
</div>

To make it match the second example in your fiddle, you could override the class that is being assigned to the anchor element with children, eg: 为了使其与小提琴中的第二个示例匹配,您可以使用子项覆盖分配给anchor元素的类,例如:

.ui-listview > .ui-li-has-count > .ui-btn {
    padding-right: 1em !important;
}

Example

Note: using !important is not ideal , but in this case it is required to override the default jQuery Mobile style that is adding a 2.8125em padding-right value to that anchor. 注意:使用!important 并不理想 ,但是在这种情况下,需要覆盖默认的jQuery Mobile样式,该样式将2.8125em padding-right值添加到该锚点。

Another (possibly better) alternative is to use jQuery to remove the ui-li-has-count class from any li elements that have been given it: 另一个(可能更好)的替代方法是使用jQuery从ui-li-has-count任何li元素中删除ui-li-has-count类:

$('.ui-btn').closest('li').removeClass('ui-li-has-count');

If you don't want this to affect your entire site, make it specific, eg 如果您不希望这影响到您的整个网站,请具体说明,例如

$('#your_container').find('.ui-btn').closest('li').removeClass('ui-li-has-count');

Example

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

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