How to Insert a Line Break in Span Using Css? [Closed]

Now I want to break the line on Q1 and move this Q1 next to Summary. Is there a way to do it? Following is the CSS for the button.

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

Try adding:

display: inline-block;

Note: it may change the behavior a bit.

in the html:

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

You may also use js, for a more dynamic approach:

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

and you can use jQuery to do it:

$(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);

    });

});
4

Use

display:block;

OR
span is an inline element, as such styling attributes such as width or margin don't work. You can fix that by either changing the span to a block element (such as div), or by using padding instead.

1
David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest