Skip to content

Commit 19c01dd

Browse files
committed
Add Make A Block Of Text Respect New Lines as a css til
1 parent e27048e commit 19c01dd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
1010
For a steady stream of TILs from a variety of rocketeers, checkout
1111
[til.hashrocket.com](https://til.hashrocket.com/).
1212

13-
_717 TILs and counting..._
13+
_718 TILs and counting..._
1414

1515
---
1616

@@ -94,6 +94,7 @@ _717 TILs and counting..._
9494
- [Dry Up SCSS With Mixins](css/dry-up-scss-with-mixins.md)
9595
- [Lighten And Darken With CSS Brightness Filter](css/lighten-and-darken-with-css-brightness-filter.md)
9696
- [Lighten And Darken With SCSS](css/lighten-and-darken-with-scss.md)
97+
- [Make A Block Of Text Respect New Lines](css/make-a-block-of-text-respect-new-lines.md)
9798
- [Parameterized SCSS Mixins](css/parameterized-scss-mixins.md)
9899

99100
### Devops
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Make A Block Of Text Respect New Lines
2+
3+
Generally when we fill a `div` tag full of text, it will display it one long
4+
strand irrespective of any line breaks that are included. This is a great
5+
default, but not necessarily what we want when we are displaying text from
6+
another source, such as our users.
7+
8+
We can convince a block of text to respect new lines by adding a couple CSS
9+
properties.
10+
11+
```css
12+
.multiline-text {
13+
word-wrap: break-word;
14+
white-space: pre-line;
15+
}
16+
```
17+
18+
The first rule, `word-wrap: break-word`, ensures that long lines of text
19+
uninterrupted by new lines respect the boundaries of our wrapping element.
20+
The second rule, `white-space: pre-line`, handles squashing of extra white
21+
space and respecting of new lines.
22+
23+
See a [working example here](https://codepen.io/anon/pen/bQpKyv).

0 commit comments

Comments
 (0)