css 메뉴 분할

조회수 1762회

안녕하세요.

기초적인 CSS 같은데 제가 문외한이라 도움을 요청드립니다.

아래 메뉴바 보시면 메뉴 1과 메뉴2가 일정한 크기로 왼쪽으로 쏠려 있는데요

메뉴1과 메뉴2를 50% 나누어 보이게 하려면 어디를 수정해야 하는지요.. 전체크기(100%)에서 50%는 메뉴1 나머지 50%는 메뉴 2로 하고 싶습니다.

도움 부탁드립니다.

이미지

<!DOCTYPE html>
<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
    border-right:1px solid #bbb;
}

li:last-child {
    border-right: none;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: #111;
}

.active {
    background-color: #4CAF50;
}
</style>
</head>
<body>

<ul>
  <li><a class="active" href="#home">메뉴1</a></li>
  <li><a href="#news">메뉴2</a></li>

</ul>

</body>
</html>

1 답변

  • ul의 width를 100%로 가득채우고 display를 table로 하고,

    li에서 float:left를 대신에 display: table-cell를 지정하시면,

    각 li들이 table 형식에 맞게 보여집니다.

    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #333;
    
        width: 100%;
        display: table;
    }
    
    li {
        border-right:1px solid #bbb;
    
        display: table-cell;
    }
    
    
    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)