How to Apply Padding to Every Line in Multi-Line Text

How to apply padding to every line in multi-line text?

You could use box-decoration-break property with value of clone.

box-decoration-break: clone; Each box fragment is rendered independently with the specified border, padding and margin wrapping each fragment. The border-radius, border-image and box-shadow, are applied to each fragment independently. The background is drawn independently in each fragment which means that a background image with background-repeat: no-repeat may be repeated multiple times. - MDN

See the current browser support tables at caniuse.com

jsFiddle example

h1 {  font-weight: 800;  font-size: 5em;  line-height: 1.35em;  margin-bottom: 40px;  color: #fff;}h1 span {   background-color: rgba(0, 0, 0, 0.5);   padding: 0 20px;  -webkit-box-decoration-break: clone;  box-decoration-break: clone;}
<h1><span>The quick brown fox jumps over the lazy dog.</span></h1>

How to add horizontal padding to every line in one multi-line wrapped sentence?

After struggling for some time I found a non-quirky solution with a decent fallback for older browsers – adding two CSS3-shadows to the lines of text:

span {
background:#ff0;color:#000;
box-shadow:0.2em 0 0 #ff0,-0.2em 0 0 #ff0;
-moz-box-shadow:0.2em 0 0 #ff0,-0.2em 0 0 #ff0;
-webkit-box-shadow:0.2em 0 0 #ff0,-0.2em 0 0 #ff0;
}

Multi-line text padding

Use flex to solve this, make the container div display flex.

Make sure your classes start with a letter (Which characters are valid in CSS class names/selectors?)

https://jsfiddle.net/cymozzeL/1/

.t1 {
display: flex;
}

There is a lot more you can do with this, please have a look at

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

How to include padding on a span element that has multiple lines

You can try faking the background when the span is broken by using box-shadow. Try something like this and see if it works for you:

span {    background-color: yellow;    padding: 1px 0;    box-shadow: 10px 0 0 0 yellow, -10px 0 0 0 yellow;}
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a nisi ipsum. Mauris convallis dapibus diam ac sollicitudin. Vivamus varius nulla magna, ac rutrum nulla accumsan quis. Duis placerat, elit non posuere elementum, tellus massa pellentesque nunc, eu maximus ligula metus non dui. Sed accumsan quam nec sodales sagittis.</span>

Multi line padded text with outer and inner rounded corners in CSS

This is, for me, a really good answer.
Code by https://stackoverflow.com/users/6400719/ines-montani

HTML:

<div class="edit">Edit text below</div>

<h1>
<div class="goo" contenteditable="true">This is an example of a simple headline or text with rounded corners using<br>a gooey SVG filter.</div>
</h1>

<!-- Filter: https://css-tricks.com/gooey-effect/ -->
<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop"/>
</filter>
</defs>
</svg>

CSS:

:root {
--color-bg: #34304c;
--color-bg2: #534d7a;
--color-highlight: #fff;
--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

.goo {
font-size: 3rem;
line-height: 1.35;
display: inline;
box-decoration-break: clone;
background: var(--color-highlight);
padding: 0.5rem 1rem;
filter: url('#goo');
}

.goo:focus {
outline: 0;
}

.edit {
display: inline-block;
padding: 0.5rem 1rem;
background: var(--color-bg2);
text-transform: uppercase;
font-size: 0.7rem;
color: var(--color-highlight);
border-radius: 1em;
}

body {
padding: 7.5vh 100px 0 100px;
font-family: var(--font);
background: var(--color-bg);
}

Sample Image

Link to Codepen: https://codepen.io/ines/pen/NXbmRO

Snackbar Multi-line text padding

Currently (1.1.0-beta01 and 1.2.0-alpha01) there isn't an official way to customize the padding with 2 lines.

The only workaround (but it can stop to work in the next releases) is to define in the dimens.xml

<dimen name="design_snackbar_padding_vertical_2lines">14dp</dimen>

or

  <dimen name="design_snackbar_padding_vertical_2lines">@dimen/design_snackbar_padding_vertical</dimen>

Before and after:

Sample Image
Sample Image

CSS - apply padding to inline element across two lines

Using jQuery to wrap every word inside your h1 into a span will pretty much do the trick. I have no clue how it affects SEO though to be honest.

This is what i'm using when i need to achieve this.

$("h1").each(function() 
{
var headerContent = $(this).text().split(' ');

for (var i = 1; i < headerContent.length; i++)
{
headerContent[i] = '<span class="subhead">' + headerContent[i] + '</span>';
}

$(this).html(headerContent.join(' '));
}
);

http://jsfiddle.net/Cnuzh/

I think i actually got this from an answer from a similar question here on stackoverflow a while back. I'll post the link to the original author if this is the case. I shall look into it tomorrow, but first i need my nice warm bed ^^

Hope it helped,

WJ

Applying an ellipsis to multiline text

I finally found a solution to do what I want.
As p a paragraphe and article the wrapper.
If you want to apply ellipsis to p depending on article height (which also depends on window height), you need to get the height of the article, the line-height of the p and then articleHeight/lineHeight to find the number of line-clamp that can be added dynamically then.

The only thing is the line-height should be declared in the css file.

Check the following code. If you change the height of the window, the line-clamp will change. Can be great to create a plug-in aiming to do that.

jsfiddle

function lineclamp() {  var lineheight = parseFloat($('p').css('line-height'));  var articleheight = $('article').height();   var calc = parseInt(articleheight/lineheight);  $("p").css({"-webkit-line-clamp": "" + calc + ""});}

$(document).ready(function() { lineclamp();});
$( window ).resize(function() { lineclamp();});
article {  height:60%;  background:red;  position:absolute;}
p { margin:0; line-height:120%; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><article> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque lorem ligula, lacinia a justo sed, porttitor vulputate risus. In non feugiat risus. Sed vitae urna nisl. Duis suscipit volutpat sollicitudin. Donec ac massa elementum massa condimentum mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla sollicitudin sapien at enim sodales dapibus. Pellentesque sed nisl eu sem aliquam tempus nec ut leo. Quisque rutrum nulla nec aliquam placerat. Fusce a massa ut sem egestas imperdiet. Sed sollicitudin id dolor egestas malesuada. Quisque placerat lobortis ante, id ultrices ipsum hendrerit nec. Quisque quis ultrices erat.Nulla gravida ipsum nec sapien pellentesque pharetra. Suspendisse egestas aliquam nunc vel egestas. Nullam scelerisque purus interdum lectus consectetur mattis. Aliquam nunc erat, accumsan ut posuere eu, vehicula consequat ipsum. Fusce vel ex quis sem tristique imperdiet vel in mi. Cras leo orci, fermentum vitae volutpat vitae, convallis semper libero. Phasellus a volutpat diam. Ut pulvinar purus felis, eu vehicula enim aliquet vitae. Suspendisse quis lorem facilisis ante interdum euismod et vitae risus. Vestibulum varius nulla et enim malesuada fringilla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque lorem ligula, lacinia a justo sed, porttitor vulputate risus. In non feugiat risus. Sed vitae urna nisl. Duis suscipit volutpat sollicitudin. Donec ac massa elementum massa condimentum mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla sollicitudin sapien at enim sodales dapibus. Pellentesque sed nisl eu sem aliquam tempus nec ut leo. Quisque rutrum nulla nec aliquam placerat. Fusce a massa ut sem egestas imperdiet. Sed sollicitudin id dolor egestas malesuada. Quisque placerat lobortis ante, id ultrices ipsum hendrerit nec.</p></article>


Related Topics



Leave a reply



Submit