테두리를 축소하는 방법 (div에서)?


81

http://jsfiddle.net/R8eCr/1/ 과 같은 마크 업이 있다고 가정합니다.

<div class="container">
    <div class="column">
        <div class="cell"></div>
        <div class="cell"></div>
        <div class="cell"></div>
    </div>
    <div class="column">
        <div class="cell"></div>
        <div class="cell"></div>
        <div class="cell"></div>
    </div>
    <div class="column">
        <div class="cell"></div>
        <div class="cell"></div>
        <div class="cell"></div>
    </div>
    ...
</div>

그런 다음 CSS

.container {
    display: table;
    border-collapse: collapse;
}
.column {
    float: left;
    overflow: hidden;
    width: 120px;
}
.cell {
    display: table-cell;
    border: 1px solid red;
    width: 120px;
    height: 20px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

나는 외부 div와 display: table; border-collapse: collapse;셀이 있는데 display: table-cell왜 여전히 붕괴되지 않습니까? 내가 여기서 무엇을 놓치고 있습니까?

그건 그렇고 열에 가변 수의 셀이 있으므로 한쪽에만 테두리를 가질 수 없습니다.


음, <table>테이블에 친구와 함께 사용하지 그래요?
MU이 너무 짧

@muistooshort, 세포의 변수 번호 어쩌면이 왜냐하면 나는 특정 디자인에 빈 셀을하지 않으
Jiew 멩

답변:


36

여기에 데모가 있습니다

먼저 구문 오류를 수정해야합니다.

display: table-cell;

아니 diaplay: table-cell;

   .container {
    display: table;
    border-collapse:collapse
}
.column {
    display:table-row;
}
.cell {
    display: table-cell;
    border: 1px solid red;
    width: 120px;
    height: 20px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

흠 실제 코드에서는 철자가 맞습니다 ... 흠 ... 작동하지 않는 실제 코드의 다른 무언가 일 것 같습니다 ...이 문제의 원인이 무엇인지 알아
볼게요

난 이미 국경 세포에 대해 알고 떠나 폭과 높이 : 나는 진정한 내가 답을 확인하지만 난 플로트를 제거 내 실수를 수정
Hushme

1
@Hushme 그래 많은 사람들이 알고 있지만 때로는 작은 문제로 끊지 않습니다. 어쨌든 계속해, 난 문제 없어.
Bhojendra Rauniyar 2013-07-29

1
투표 시스템은 나에게 영향을 미치지 않지만 누군가 나에게 도움을 받으면 기뻐할 수 있습니다.
Bhojendra Rauniyar 2013-07-29

당신은 내가 프론트 엔드 개발자로 경험 7 년이 내 프로필을 확인 CSS의 능력을 가진 유일한 사람이 아니다
Hushme

94

디스플레이 테이블을 사용하는 대신 단순한 음수 여백을 사용하십시오.

fiddle JS Fiddle 에서 업데이트 됨

.container { 
    border-style: solid;
    border-color: red;
    border-width: 1px 0 0 1px;
    display: inline-block;
}
.column { 
    float: left; overflow: hidden; 
}
.cell { 
    border: 1px solid red; width: 120px; height: 20px; 
    margin:-1px 0 0 -1px;
}
.clearfix {
    clear:both;
}

83

대신 border사용 box-shadow:

  box-shadow: 
    2px 0 0 0 #888, 
    0 2px 0 0 #888, 
    2px 2px 0 0 #888,   /* Just to fix the corner */
    2px 0 0 0 #888 inset, 
    0 2px 0 0 #888 inset;

데모 : http://codepen.io/Hawkun/pen/rsIEp


5
이것은 실제로 내가 찾은 최고의 솔루션입니다. 데이터가 동적으로 생성되고 완벽을 보장하지는 않지만 그리드에 9 개 항목이 있다고 가정 해 보겠습니다. 대신 다른 솔루션을 사용하면 테두리가 누락되는 2 개 항목이 있습니다. 잘 했어 !
Unsparing

3
디스플레이 속성을 변경하지 않고 반응 형 레이아웃에 좋은 트릭입니다.
kosmos

3
이것은 스크린 미디어에서 잘 작동합니다. 그러나 인쇄 매체에서는 상자 그림자가 인쇄되지 않고 배경으로 간주됩니다.
Marcello Nuccio

이것은 저에게는 잘 작동했지만 처음 세 개의 그림자는 다음과 같이 수행 할 수 있습니다. 1px 1px 0 1px # 888 스프레드와 오프셋은 모서리를 처리합니다.
Matt Schuette 2016 년

1
box-shadowWindows에서 고 대비 테마를 사용할 때는 무시 (사라짐)되므로 접근성에 관심이있는 경우 항상 대안을 제공하세요.
tomasz86

5

당신은 당신의 열 display: table-row대신에 사용해야 float: left;하고 분명히 @Hushme가 당신 diaplay: table-cell을 수정해야 합니다.display: table-cell;

 .container {
    display: table;
    border-collapse: collapse;
}
.column {
    display: table-row;
    overflow: hidden;
    width: 120px;
}
.cell {
    display: table-cell;
    border: 1px solid red;
    width: 120px;
    height: 20px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

데모


여기에서 내가 이미 사용하고 있던 링크를 확인했지만 float : left jsfiddle.net/R8eCr/2 를 제거하는 것을 잊었습니다 . 링크 번호를 참조하십시오
Hushme

네, 괜찮아요. 너무 가까워.
Bhojendra Rauniyar

4

마이너스 여백을 사용할 수도 있습니다.

.column {
  float: left;
  overflow: hidden;
  width: 120px;
}
.cell {
  border: 1px solid red;
  width: 120px;
  height: 20px;
  box-sizing: border-box;
}
.cell:not(:first-child) {
  margin-top: -1px;
}
.column:not(:first-child) > .cell {
  margin-left: -1px;
}
<div class="container">
  <div class="column">
    <div class="cell"></div>
    <div class="cell"></div>
    <div class="cell"></div>
  </div>
  <div class="column">
    <div class="cell"></div>
    <div class="cell"></div>
    <div class="cell"></div>
  </div>
  <div class="column">
    <div class="cell"></div>
    <div class="cell"></div>
    <div class="cell"></div>
  </div>
  <div class="column">
    <div class="cell"></div>
    <div class="cell"></div>
    <div class="cell"></div>
  </div>
  <div class="column">
    <div class="cell"></div>
    <div class="cell"></div>
    <div class="cell"></div>
  </div>
</div>


1
동일한 방법을 사용했습니다 border-top/left: 0;. 여백은 오프셋을 만듭니다.
toster-CX

@ toster-cx 테두리를 겹치는 것보다 훨씬 낫다고 생각합니다. 좋은 생각 :-)
mpen

3

개요를 사용하지 않는 이유는 무엇입니까? 그것은 당신이 원하는 윤곽선입니다 : 1px 단색 빨강;


1
이 답변이 현재 문제를 수정하는 데 OP에 도움이되는 방법에 대한 답변과 함께 설명 추가
ρяσѕρєя K

2
여기에서는 국경 붕괴의 다양한 변형을 보여줍니다. (부트 스트랩 그리드 사용) : codepen.io/leonardo1024/pen/KgbNGr
Muslimbek

0

border-collapse 사용 예 : 분리; 같이

  • 표로 표시되는 컨테이너 :

    ol[type="I"]>li{
      display: table;
      border-collapse: separate;
      border-spacing: 1rem;
    }
    
  • 당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
    Licensed under cc by-sa 3.0 with attribution required.