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...
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;
}
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);
});
});
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.