본문 바로가기
CSS3

한줄, 여러줄 말줄임 처리

by hjcode 2020. 11. 16.
<div class="wrap">
  <p class="line2">
  Lorem Ipsum is simply dummy text of the printing and typesetting 
  industry. Lorem Ipsum has been the industry's standard dummy 
  text ever since the 1500s, when an unknown printer took 
  a galley of type and scrambled it to make a type specimen book.
  </p>
</div>

한줄 처리는 아래처럼 간단하게 처리할 수 있습니다.

<p class="line1">
Lorem Ipsum is simply 
dummy text of the printing and typesetting industry. 
Lorem Ipsum has been the industry's standard dummy 
text ever since the 1500s, when an unknown 
printer took a galley of type and scrambled it 
to make a type specimen book.
</p>
.line1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

 

여러줄 말줄임 처리는 -webkit-line-clamp CSS 속성을 사용하면 됩니다.
콘텐츠를 지정한 줄 수만큼으로 제한합니다.
display 속성을 -webkit-box 또는 -webkit-inline-box로, 
그리고 -webkit-box-orient 속성을 vertical로 설정한 경우에만 동작합니다.

 

<div class="wrap">
  <p class="line2">
  Lorem Ipsum is simply dummy text of the printing and 
  typesetting industry. Lorem Ipsum has been the 
  industry's standard dummy text ever since the 1500s, 
  when an unknown printer took a galley of type and 
  scrambled it to make a type specimen book.
  </p>
</div>
.wrap {
  padding: 10px;
  border:1px solid #333;
  width: 150px;
  height: 60px;
}
.line2 {
  display: -webkit-box;
  margin:0;
  word-wrap: break-word;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow:hidden;
  text-overflow: ellipsis;
  line-height: 20px;
}

 

 

 

 

IE에서는 여러줄 ... 처리는 되지 않습니다..

 

반응형

'CSS3' 카테고리의 다른 글

:is() 와 :where()  (0) 2022.05.02
CSS방법론 SMACSS (Scalable and Modular Architecture for CSS)  (0) 2021.08.06
:focus-within  (0) 2020.10.12
익스에서 scale 떨림  (0) 2019.09.29
flex를 이용한 반응형 레이아웃  (0) 2019.09.29