저는 CSS의 두 가지 그룹화를 작성해야 함에도 불구하고 그것을 만족스럽게 해결했다고 생각합니다. 트릭은 동일한 선에서 여러 선택기를 사용할 수 있다는 것입니다. 이는 설정 된 선택 사항 사이에서 공용체를 만드는 것과 같습니다.
세 아래 인 외에 http://jsfiddle.net/MY4cD/
더 완벽한 솔루션에 예를 들어 작업 (및 기타 배수까지 확장.
다음 HTML을 감안할 때 (그리고 임의의 수)
<div class="container">
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
<div class="cell">7</div>
<div class="cell">8</div>
</div>
에 대한
다음 CSS는 "나머지"div가 빨간색으로 강조 표시된 세 행을 만듭니다.
.cell {
width: 33.33%;
}
.cell:nth-last-child(-n+2):nth-child(3n+1):nth-last-child(1){
background:red;
}
.cell:nth-last-child(-n+2):nth-child(3n+1):nth-last-child(2){
background:red;
}
.cell:nth-last-child(-n+2):nth-child(3n+2):nth-last-child(1){
background:red;
}
다시 다음과 같은 CSS 이런 식으로
.cell {
width: 25%;
}
/* accounts for when there is 1 remainder */
.cell:nth-last-child(-n+3):nth-child(4n+1):nth-last-child(1){
background:red;
}
/* accounts for the first of 2 remainders */
.cell:nth-last-child(-n+3):nth-child(4n+1):nth-last-child(2){
background:red;
}
/* accounts for the second of 2 remainders */
.cell:nth-last-child(-n+3):nth-child(4n+2):nth-last-child(1){
background:red;
}
/* accounts for the first of 3 remaidners */
.cell:nth-last-child(-n+3):nth-child(4n+1):nth-last-child(3){
background:red;
}
/* accounts for the second of 3 remainders */
.cell:nth-last-child(-n+3):nth-child(4n+2):nth-last-child(2){
background:red;
}
/* accounts for the third of 3 remainders */
.cell:nth-last-child(-n+3):nth-child(4n+3):nth-last-child(1){
background:red;
}
를 사용할 수 있습니다 행 당 4 명 개의 div가 있고 나머지를 선택하고자한다면, 당신은 패턴이 점점 더 복잡 성장할 것입니다 볼 수 있습니다 더 높이 올라간다. 그러나 확실히 어떤 숫자라도 가능하다.
이 패턴을 미디어 쿼리와 함께 사용하여 새로운 CSS 플렉스 플로 : 행 줄 바꿈의 효과를 시뮬레이션했습니다. 크로스 브라우저 호환성을 위해 float를 사용하는 명령. 여기에서 전체 데모를 볼 수 있습니다 : http://codepen.io/msorrentino/full/chHnu/
최소한이 문제를 해결하기 위해 노력한 방법에 대해 최소한의 노력을 시도하십시오. SO는 코드 작성 서비스가 아닙니다. –
n 번째 자녀와 함께 할 수 있습니까? 나는 누군가가 무엇이 올 수 있는지 궁금하다. – Huangism
일종의 - [** nth-last-child **] 일 수있다. (http://stackoverflow.com/questions/4844456/is-it-possible-to -select-the-last-n-items-with-nth-child? rq = 1) - [** Jsfiddle **] (http://jsfiddle.net/7XJhF/). –