기록

새로 알게 된 css 본문

TIL*

새로 알게 된 css

mnmhbbb 2022. 2. 23. 15:41

1. only-of-type
사용했던 예시)

.abc p img:only-of-type {
  width: 100%;
}

p 태그 안에 img 태그가 유일한 타입일 경우 width 100% 주기

 

2. width: min-content
width가 담긴 컨텐트의 길이만큼만 

.a {
  width: min-content !important;
}

 

3. all: unset
현재 부여된 스타일을 모두 초기화시킨다.

 

4. first-child:nth-last-child(1)

li:first-child:nth-last-child(1) {
  width: 100%;
}

특정 경우에 자식 태그가 1개일 경우에만 width: 100%;을 주고 싶을 때

참조: https://serisepomme.tistory.com/entry/CSS%EB%A1%9C-%EC%9E%90%EC%8B%9D-%EC%9A%94%EC%86%8C-%EA%B0%AF%EC%88%98-%EC%95%8C%EC%95%84%EB%82%B4%EA%B8%B0

Comments