- Arawn's Dev Blog
- Outsider's Dev Story
- Toby's Epril
- Benelog
- NHN 개발자 블로그
- SK 플래닛 기술 블로그
- OLC CENTER
- 소프트웨어 경영/공학 블로그
- 모바일 컨버전스
- KOSR - Korea Operating System …
- 넥스트리 블로그
- 리버스코어 ReverseCore
- SLiPP
- 개발자를 위하여... (Nextree 임병인 수석)
- "트위터 부트스트랩: 디자이너도 놀라워할 매끈하고 직관…
- Learning English - The English…
- real-english.com
- 'DataScience/Deep Learning' 카테…
- Deep Learning Summer School, M…
- Deep Learning Courses
민서네집
Fluid width with equally spaced DIVs 본문
http://stackoverflow.com/questions/6865194/fluid-width-with-equally-spaced-divs
[Sample] http://jsfiddle.net/thirtydot/EDp8R/3/
위 예제를 보면 마치 float 처럼 가로 공간이 좁으면 box가 밑으로 내려오는데,
float를 사용하지 않고, inline-block 과
text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
를 이용한다.
[발췌]
See: http://jsfiddle.net/thirtydot/EDp8R/
- This works in IE6+ and all modern browsers!
- I've halved your requested dimensions just to make it easier to work with.
text-align: justify
combined with.stretch
is what's handling the positioning.display:inline-block; *display:inline; zoom:1
fixesinline-block
for IE6/7, see here.font-size: 0; line-height: 0
fixes a minor issue in IE6.
HTML:
<div id="container">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<span class="stretch"></span>
</div>
CSS:
#container {
border: 2px dashed #444;
height: 125px;
text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
/* just for demo */
min-width: 612px;
}
.box1, .box2, .box3, .box4 {
width: 150px;
height: 125px;
vertical-align: top;
display: inline-block;
*display: inline;
zoom: 1;
}
.stretch {
width: 100%;
display: inline-block;
font-size: 0;
line-height: 0;
}
.box1, .box3 {
background: #ccc;
}
.box2, .box4 {
background: #0ff;
}
The extra span
(.stretch
) can be replaced with :after
.
This still works in all the same browsers as the above solution. :after
doesn't work in IE6/7, but they're using distribute-all-lines
anyway, so it doesn't matter.
See: http://jsfiddle.net/thirtydot/EDp8R/3/
There's a minor downside to :after
: to make the last row work perfectly in Safari, you have to be careful with the whitespace in the HTML.
Specifically, this doesn't work:
<div id="container">
..
<div class="box3"></div>
<div class="box4"></div>
</div>
And this does:
<div id="container">
..
<div class="box3"></div>
<div class="box4"></div></div>
You can use this for any arbitrary number of child div
s without adding a boxN
class to each one by changing
.box1, .box2, .box3, .box4 { ...
to
#container > div { ...
This selects any div that is the first child of the #container
div, and no others below it. To generalize the background colors, you can use the CSS3 nth-order selector, although it's only supported in IE9+ and other modern browsers:
.box1, .box3 { ...
becomes:
#container > div:nth-child(odd) { ...
See here for a jsfiddle example.
'WEB (HTML, CSS)' 카테고리의 다른 글
jQuery Ajax IE8,9 Cross Domain Security Issue (0) | 2014.12.09 |
---|---|
css로 속이 빈 역삼각형 만들기 (0) | 2014.11.21 |
개인정보취급방침 회원가입약관 만들기를 도와주는 웹사이트 소개 (0) | 2014.10.31 |
Gradation CSS 만들어주는 사이트 (1) | 2014.10.22 |
IE CSS Hack (0) | 2014.10.20 |