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

现在我想在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);

    });

});

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些