加入收藏 | 设为首页 | 会员中心 | 我要投稿 厦门站长网 (https://www.0592zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 如何在span中插入换行符?

发布时间:2020-12-24 14:06:42 所属栏目:资源 来源:网络整理
导读:现在我想在Q1上打破这一行并将此Q1移到摘要旁边.有办法吗?以下是按钮的CSS. span {display: inline-block;font-size: 80%;line-height: normal;width: 100%;line-height: 2rem;border: 1px solid #019ed5;border-radius: 25px;cursor: pointer;} 解决方法

现在我想在Q1上打破这一行并将此Q1移到摘要旁边.有办法吗?以下是按钮的CSS.

span {
display: inline-block;
font-size: 80%;
line-height: normal;
width: 100%;
line-height: 2rem;
border: 1px solid #019ed5;
border-radius: 25px;
cursor: pointer;
}

解决方法

尝试添加:
display: inline-block;

注意:它可能会改变一些行为.

在HTML中:

<span>JAN-MAR <br /> Q1 Summary</span>

您也可以使用js,以获得更加动态的方法:

<span class="q-span">JAN-MAR Q1 Summary</span>

你可以使用jQuery来做到这一点:

$(document).ready(function(){
    $(".q_header").each(function(){
        // Get content
        var 
            content = $(this).text(),// get first word
            first_w = content.match(/([w-]+)/);

        // replace the first word with first word and break
        var new_cnt = content.replace(first_w[0],first_w[0] + "</br>");

        // add the css to make it inline-block
        $(this).css("display","inline-block").html(new_cnt);

    });

});

(编辑:厦门站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读