Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show first 3 lines in HTML paragraph

Tags:

html

css

I want to show only the first 3 lines of the paragraph below using HTML formatting. I am searching on W3Schools but it doesn't show how to do it.

<body>

loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlor
loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore

</body>
like image 461
yakusha Avatar asked Mar 25 '13 10:03

yakusha


Video Answer


3 Answers

Set the height of the paragraph to three line-heigths. Like -

p{
  line-height:1.2em;
  height:3.6em;
  overflow:hidden;
}

Set overflow to hidden to hide overflowing text

like image 110
svineet Avatar answered Nov 16 '22 01:11

svineet


You can use -webkit-line-clamp property with div.

div {
  width: 100%;
  line-height: 1.2em;
  height: 3.6em;
  background-color: gainsboro;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}
<div>
  loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
  loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
  loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
  loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
  loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlore
</div>
like image 37
Penny Liu Avatar answered Nov 16 '22 00:11

Penny Liu


You can give the container a height and line-height and set its overflow property to hidden:

HTML

<p>loremloremlorem...</p>

CSS

p {
    height:60px;
    line-height:20px; /* Height / no. of lines to display */
    overflow:hidden;
}

JSFiddle example.

like image 37
James Donnelly Avatar answered Nov 16 '22 01:11

James Donnelly