CSS 레이아웃 기초 - 완성형 예제

css_layout_basic.jpg
"일모리의 CSS 쉽게 배우기" 사이트를 보다가 간단하게 한번 짜보았습니다.
전체너비 700픽셀 가운데 정렬이며 충분히 실전에 사용가능한 심플한 예제입니다.
<!-- content exp --> 에서 <!-- /content exp --> 까지는 content 영역에 여러번 복제해서 사용해도 되도록 했습니다.
부족한 부분은 코멘트를 통해 보충해주시면 고맙겠습니다.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> CSS 레이아웃 예제 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">

<style type="text/css">
/*기본코드*/
html {
    background: none;
    padding: 0;
    margin: 0;
    text-align: center;
    font-family: tahoma, verdana, gulim, 굴림,sans-serif;
    font-size: 12px;
}

body {
    margin: 0;
    text-align: center;/*가운데 정렬*/
}

a {
    text-decoration: none;
    color: black;
}
/*wrap */
#wrap {
    background: #eee url(wrap.gif) no-repeat top left;
    width: 700px;
    padding: 0;
    margin: 0 auto;
    text-align: left;
}
/*wrap ie - ie에서는 width, height값에 padding, border 값등을 더한 값을 주어야 한다 */
* html #wrap {
    width: 710px;
}
/* header 부분 */

/* id= header 로 정해진곳을 부릅니다 */
#header {
    background: #aaa url(header.gif);
    border: 1px solid #ddd;
    width: 600px;
    height: 70px;
    padding: 0;
    margin: 0;
}

/*sidebar 부분 */
.sidebar {
    width: 90px;
    padding: 0;
    margin: 0;
    background: #eee url(sidebar.gif) no-repeat top left;
    float:left; /*왼쪽으로 붙입니다*/
}
.sidebar ul  {
    padding: 0;
    margin: 0px;
}
.sidebar ul li {
    padding: 0;
    margin: 0;
    list-style-image: none;
    list-style-type: none;
}

/* menu 의 링크 꾸미기 없게*/
.sidebar ul li a {
    text-decoration: none;
}

/* content 부분 */
#content {
    float: left;
    width: 500px;
    padding: 0;
    margin: 0;
    text-align: left;
    background: #bbb;
}

#content .mid {
    float: left;
    width: 245px;
    padding: 0;
    margin: 0;
    text-align: left;
    background: #ddd;
}

#content .right {
    float: left;
    width: 245px;
    padding: 0;
    margin: 0;
    text-align: left;
    background: #ccc;
}

.writing {
    line-height: 150%;
    letter-space: .2em;
    margin:0;
    width: 245px;
}

.hspace {
    float: left;
    width: 10px;
    height: auto;
    margin: 0;
    padding: 0;
    background: #fff;/*transparent*/
}
.vspace {
    width: auto;
    height: 10px;
    margin: 0;
    padding: 0;
    background: #fff;/*transparent*/
    clear:both;
}

/* id= footer 로 정해진곳을 부릅니다 */
#footer {
    background: #ccc url(footer.gif);
    border: 1px solid #ddd;
    width: 600px;
    height: 70px;
    padding: 0;
    margin: 0;
}
</style>

</head>

<body>

<div id="wrap">
<pre>
CSS를 활용한 레이아웃 잡기 - 기본
h-가로여백, v-세로여백
전체 기본영역 700px로 해봅니다.
ie에서는 width, height값에 padding, border 값등을 더한 값을 주어야 하는점 필히 숙지하세요.
예) * html #wrap { width:710px; }
</pre>

    <div id="header">헤더 600*70</div>

    <div class="sidebar">좌측 메뉴 90
        <ul>
            <li>menu1</li>
            <li>menu2</li>
            <li>menu3</li>
        </ul>
    </div>

    <div class="hspace">h</div>

    <div id="content">콘텐츠 500 - 콘텐츠 최상위 영역으로 실제 보이지 않음

        <div style="text-align:center;border:1px dashed #fff;">콘텐츠 상단 가로 통합영역<br><br></div>

        <div style="clear:both;"></div>

        <!-- content exp -->
        <div class="vspace" style="text-align:center;">v</div>

        <div class="mid">245 콘텐츠 좌측영역
            <div class="writing">
                 <p>writing</p>
            </div>
        </div>

        <div class="hspace">h</div>


        <div class="right">245 콘텐츠 우측영역
            <div class="writing">
                    <p>writing</p>
            </div>
        </div>

        <div style="clear:both;"></div>
        <!-- /content exp -->

        <!-- content exp -->
        <div class="vspace" style="text-align:center;">v</div>

        <div class="mid">245 콘텐츠 좌측영역
            <div class="writing">
                 <p>writing</p>
            </div>
        </div>

        <div class="hspace">h</div>


        <div class="right">245 콘텐츠 우측영역
            <div class="writing">
                    <p>writing</p>
            </div>
        </div>

        <div style="clear:both;"></div>
        <!-- /content exp -->

        <div style="text-align:center;border:1px dashed #fff;">콘텐츠 하단 가로 통합영역<br><br></div>

    </div>

    <div class="hspace">h</div>

    <div class="sidebar">우측 메뉴 90
        <ul>
            <li>menu1</li>
        </ul>
    </div>

    <div style="clear:both;"></div>

    <div id="footer">풋 600*70</div>

</div>

</body>
</html>

[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]

첨부파일

css_layout_basic.jpg (52.9 KB)
1회 2007-04-02 12:43
|

댓글 11개

고생하셨습니다.
간략하고 깔끔하게 정리를 잘 해 주셨군요~*^^*
점심 맛나게 드셨나요??
그저 많이 쓰이는 형태를 최대한 단순하게 레이아웃만 잡아봤습니다.
예전에 익히면서 적용한 곳들을 지금 보면 군더더기가 널려있는것을 봅니다만, 엄두를 못내고 있습니다.
이 역시 처음 시작이 중요한듯 합니다.
예~*
점심 맛있게 먹었습니다.

처음 시작이 미미해 보일지라도,
그 체계가 단순하고 정형화가 잘 되어 있다면,
언제라도 그것을 통해 응용 및 확장이 용이하리라 생각됩니다.

극히 단순한 레이아웃이 아닌 경우라면,
그럴듯해 보이는 css layout이라 할지라도,
그 소스코드가 방대한 경우가 대다수인데,
이러한 기본적인 틀만 가지고도 어느 정도만 이해가 가능하다면,
충분히 화려한 레이아웃 그 이상으로도 변화 & 발전시킬 수 있다고 봅니다.
아..감사합니다...이제 저도...css를..좀 주물러 봐야겠습니다.
수고하셨어요~
레이아웃은 기본적으로 잘 짜여져 있네요

그러나 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 이 있을때와
없을때는 현재 위에서 짜여진 레이아웃에도 미묘한 차이가 생길듯 합니다.
현재 그누보드에서는 선언되지 않은 일반 html 문법을 사용하고 있죠

그러므로 왜 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 를 선언했는지를
먼저 알아본 후 스타일을 이용해 레이아웃을 잡아 주시는 것이 중요해 보입니다.

그리고 위와 같이 선언했을 경우는 선언에 맞게 메타태그가 따로 놀지 않도록
<meta name="Generator" content="EditPlus" />
<meta name="Author" content="" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
태그 닫는 "/" 를 붙여 주어야 겠죠.

또 레이어 안에 내용물에 따라서도 레이어가 깨질수도 있겠군요
overflow:hidden; 을 적절하게 사용해 보세요.
http://www.cadvance.org ---> CSS ---> Page Layout Series 의
해당 서브 목록의 글들만 모두 읽어 보고
(전 읽는데 30분 정도 걸렸습니다. 그리고 실행결과를 보기위해선 익스로 접속해야 하더군요)

왜...??? doctype 을 지정하는지 어떻게 사용하는지
페이지 레이아웃을 만들때 알아두어야 하는 것들과
익스에서의 div 태그 사용시 margin, padding, border 인하여 생기는 버그에 관해서 한번 알아보고

아래 css로 짜여진 레이아웃들을 다운받아 많이 다루어 보면 좋을듯 합니다.

http://www.freelayouts.com/
http://templates.arcsin.se/
http://www.templateworld.com/
http://www.oswt.co.uk/
http://www.cssfill.com/
http://www.oswd.org/
http://www.free-css-templates.com/
http://www.templatesbox.com/
http://www.ex-designz.net/template/
수고 많이 하셨습니다...^^

불여우에서도 잘 동작하는군요..

단, 불여우에서는 <pre> 부분도 마진을 잡아줄 경우 ... ^^

많은 참고가 될듯 합니다....감사합니다...^^
이상한것이 나타났다, 뭐지?ㅡ,.ㅡ
참~ 좋은 정보가 많군요.. 감사합니다.. ^^
좋은정보 감사합니다^^
정말 좋은글이네요 ^^
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 1,130
18년 전 조회 1,147
18년 전 조회 3,020
18년 전 조회 950
18년 전 조회 1,162
18년 전 조회 2,097
18년 전 조회 2,233
18년 전 조회 1,315
18년 전 조회 1,908
18년 전 조회 1,165
18년 전 조회 2,498
18년 전 조회 6,603
18년 전 조회 3,829
18년 전 조회 2,227
18년 전 조회 6,296
18년 전 조회 2,586
18년 전 조회 2,622
18년 전 조회 2,118
18년 전 조회 2,110
18년 전 조회 2,127
18년 전 조회 3,879
18년 전 조회 3,938
18년 전 조회 5,041
18년 전 조회 4,129
18년 전 조회 2,569
18년 전 조회 1,803
18년 전 조회 2,779
18년 전 조회 2,706
18년 전 조회 2,234
18년 전 조회 5,421
18년 전 조회 4,768
18년 전 조회 3,775
18년 전 조회 3,458
18년 전 조회 2,134
18년 전 조회 2,143
18년 전 조회 3,641
18년 전 조회 2,270
18년 전 조회 2,494
18년 전 조회 1,773
18년 전 조회 4,458
18년 전 조회 2,155
18년 전 조회 2,308
18년 전 조회 4,047
18년 전 조회 3,895
18년 전 조회 2,123
18년 전 조회 2,767
18년 전 조회 5,148
18년 전 조회 2,405
18년 전 조회 2,953
18년 전 조회 8,508
18년 전 조회 2,003
18년 전 조회 2,932
18년 전 조회 2,621
18년 전 조회 2,927
18년 전 조회 2,361
18년 전 조회 2,431
18년 전 조회 2,739
18년 전 조회 3,981
18년 전 조회 2,634
18년 전 조회 2,749
18년 전 조회 3,216
18년 전 조회 2,921
18년 전 조회 2,102
18년 전 조회 2,550
18년 전 조회 2,553
18년 전 조회 4,037
18년 전 조회 4,779
18년 전 조회 2,310
18년 전 조회 2,490
18년 전 조회 2,425
18년 전 조회 3,761
18년 전 조회 2,380
18년 전 조회 2,384
18년 전 조회 1,721
18년 전 조회 2,005
18년 전 조회 2,710
18년 전 조회 3,589
18년 전 조회 3,093
18년 전 조회 2,983
18년 전 조회 2,035
18년 전 조회 4,131
18년 전 조회 2,165
18년 전 조회 4,199
18년 전 조회 2,510
18년 전 조회 2,359
18년 전 조회 3,468
18년 전 조회 2,240
18년 전 조회 2,158
18년 전 조회 3,279
18년 전 조회 3,958
18년 전 조회 2,209
18년 전 조회 2,358
18년 전 조회 3,838
18년 전 조회 2,716
18년 전 조회 3,350
18년 전 조회 2,779
18년 전 조회 1,664
18년 전 조회 2,130
18년 전 조회 3,700
18년 전 조회 2,920
🐛 버그신고