본문 바로가기

DEVELOP

[css] 반응형 table 대응

728x90

PC table
Tablet table
Mobile table

반응형 테이블은 <table></table> 태그를 사용하여 퍼블리싱하기 어렵다.

<ul><li></li></ul>를 사용하여 퍼블리싱하면 훨씬 수훨하다.

 

HTML

<ul class="board-list-title">
    <li class="txt-14">번호</li>
    <li class="txt-14">카테고리</li>
    <li class="board-title-con txt-14">제목</li>
    <li class="txt-14">첨부파일</li>
    <li class="txt-14">작성일</li>
    <li class="txt-14">상태</li>
</ul>
<ul class="board-list">
    <li>
        <ul class="board-list-inner">
            <li class="board-num">
                <span class="tag-square red">공지</span>
            </li>
            <li>
                <span class="tag">카테고리</span>
            </li>
            <li class="board-title-con txt-l">
                <a href="javascript:;">
                    <span class="title-row2 txt-16"><span class="icon-lock"></span>비밀 공지사항 제목입니다.</span>
                </a>
            </li>
            <li>
                <p class="date">홍길동</p>
            </li>
            <li>
                <p class="date">2022.01.01</p>
            </li>
            <li><span class="state-box">대기</span></li>
        </ul>
    </li>
    <li>
        <ul class="board-list-inner">
            <li class="board-num">
                <span class="tag-square red">공지</span>
            </li>
            <li>
                <span class="tag">카테고리</span>
            </li>
            <li class="board-title-con txt-l">
                <a href="javascript:;">
                    <span class="title-row2 txt-16"><span class="icon-lock"></span>비밀 공지사항 제목입니다.</span>
                </a>
            </li>
            <li>
                <p class="date">홍길동</p>
            </li>
            <li>
                <p class="date">2022.01.01</p>
            </li>
            <li><span class="state-box">대기</span></li>
        </ul>
    </li>
</ul>

 

 

CSS

.board-list-title,
.board-list-inner {
    display: table;
    table-layout: fixed;
    overflow: hidden;
    width: 100%;
}

.board-list-title {
    border-top: 1px solid #000;
    border-bottom: 1px solid #e0e0e0;
}

.board-list-title > li {
    display: table-cell;
    height: 52px;
    padding: 15px 7px;
    box-sizing: border-box;
    color: #424242;
    font-weight: 400;
    text-align: center;
}

.board-list-inner > li {
    display: table-cell;
    box-sizing: border-box;
    padding: 23px 7px;
    text-align: center;
}

.board-list-inner > li,
.board-list-inner > li span,
.board-list-inner > li p,
.board-list-inner > li a {
    font-size: 1.4rem;
    font-weight: 400;
    line-height: 2.4rem;
}

.board-list-title > li.board-title-con,
.board-list-inner > li.board-title-con {
    width: 700px;
}

.title-row2 {
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    display: -ms-flexbox;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    width: 100%;
    /* height: 5rem; */
    margin-bottom: 8px;
    color: #000;
    font-size: 1.8rem;
    font-weight: 600;
    line-height: 2.5rem;
    height: 5rem;
}

.title-row2 > a:hover{
    text-decoration: underline;
}

.board-list-inner > li.board-title-con .title-row2 {
    display: block;
    -webkit-line-clamp: 1;
    height: 25px;
    margin-bottom: 0;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
}

.tag {
    display: inline-block;
    padding: 16px 0 8px;
    color: #e90000;
    font-size: 1.4rem;
    line-height: 2.4rem;
}

.date {
    padding-left: 8px;
    color: #9e9e9e;
    font-size: 1.4rem;
    font-weight: 400;
    line-height: 2.4rem;
}

.board-list-inner .tag {
    padding: 0;
}

.board-list-inner .date {
    font-weight: 300;
}

.board-list > li {
    height: 68px;
    box-sizing: border-box;
    border-bottom: 1px solid #e0e0e0;
}

.board-list > li span {
    vertical-align: middle;
}

.board-list .tag-square {
    padding: 4px 15px;
    height: 28px;
    line-height: 1.9rem;
    font-size: 1.3rem;
}

.board-num {
    color: #9e9e9e;
}
@media all and (min-width: 1025px) and (max-width: 1240px) {
    .board-list-title > li:first-child,
    .board-list-title > li:nth-child(4),
    .board-list-inner > li:first-child,
    .board-list-inner > li:nth-child(4) {
        width: 8%;
    }

    .board-list-title > li:nth-child(2),
    .board-list-title > li:last-child,
    .board-list-inner > li:nth-child(2),
    .board-list-inner > li:last-child {
        width: 12%;
    }

    .board-list-title > li.board-title-con,
    .board-list-inner > li.board-title-con {
        width: 60%;
    }
}

@media all and (max-width: 1024px) {
	.board-list-title {
        display: none;
    }
    .board-list {
        border-top: 1px solid #000;
    }
    .board-list > li {
        position: relative;
        height: initial;
        margin-top: 23px;
    }
    .board-list-inner {
        padding: 0 8px 23px;
    }
    .board-list-inner > li {
        display: block;
        float: left;
        padding: 0;
    }
    .board-list-inner > li:first-child,
    .board-list-inner > li:nth-child(4),
    .board-list-inner > li:nth-child(2),
    .board-list-inner > li:last-child,
    .board-list-inner > li.board-title-con {
        width: initial;
    }
    .board-list-inner > li.board-title-con {
        clear: both;
        float: none;
        width: 90%;
        padding-top: 8px;
    }
    .board-list-inner > li:nth-child(4),
    .board-list-inner > li:last-child {
        position: absolute;
        right: 8px;
        top: 0;
    }
    .board-list-inner > li:nth-child(4) {
        top: 29px;
    }
    .icon-clip {
        width: 18px;
        height: 18px;
    }
    .board-list-inner > li.board-num {
        line-height: 24px;
    }
    .board-list-inner .tag-square {
        height: 24px;
        padding: 4px 7px;
        font-size: 1.1rem;
        line-height: 13px;
    }
    .board-list-inner .tag {
        padding: 0;
        padding-left: 16px;
        line-height: 24px;
    }
    .board-list-inner > li,
    .board-list-inner > li span,
    .board-list-inner > li p,
    .board-list-inner > li a {
        font-size: 1.2rem;
        line-height: 1.8rem;
    }
    .board-list-inner > li.board-title-con .title-row2 {
        display: -webkit-box;
        white-space: break-spaces;
        -webkit-line-clamp: 2;
        height: 20%;
    }
}

*포인트*

ul 태그에 display: table; table-layout: fixed; width: 100%;

li 태그에 display: table-cell;를 주어 해당 디자인에 맞춰 사용하면 된다.

😊

'DEVELOP' 카테고리의 다른 글

[React.js] 컴포넌트 종류  (0) 2022.02.22
[Javascript] async와 await  (0) 2022.02.22
[javascript] Swiper ie 호환 버전 확인  (0) 2022.01.13
[javascript] ES6 ie 호환  (0) 2022.01.13
[javascript] ES6 문법 ie에서 사용하기  (0) 2022.01.05