탭헤더만들기

ㅇ.ㅇ·2022년 6월 14일
0

html

목록 보기
4/5
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            font-family: "Lato", sans-serif;
        }
        .tablink{
            background-color: #555;
            color: white;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            font-size: 17px;
            width: 25%;
        }
        .tablink:hover{
            background-color: #777;
        }
        .tabcontent{
            color: white;
            display: none;
            padding: 50px;
            text-align: center;
        }
        #London{
            background-color: red;
        }
        #Paris{
            background-color: blue;
        }
        #Tokyo{
            background-color: orange;
        }
        #Oslo{
            background-color: green;
        }
    </style>
</head>
<body>
    <p>탭키를 눌러보셈
    </p>
    <div id="Paris" class="tabcontent">
        <h1>파리</h1>
        <p>프랑스 수도임</p>
    </div>
    <div id="London" class="tabcontent">
        <h1>런던</h1>
        <p>영국수도임</p></div>
    <div id="Tokyo" class="tabcontent">
        <h1>도쿄</h1>
        <p>일본수도임</p>
    </div>
    <div id="Oslo" class="tabcontent"><h1>Oslo</h1>
    <p>오슬로는 노르웨이 수도임</p>
    </div>
    <button class="tablink" onclick="openCity('London','this','red')" id="defaultOpen">런던</button>
    <button class="tablink" onclick="openCity('Tokyo','this','blue')" id="defaultOpen">도쿄</button>
    <button class="tablink" onclick="openCity('Paris','this','orange')" id="defaultOpen">파리</button>
    <button class="tablink" onclick="openCity('Oslo','this','green')" id="defaultOpen">오슬로</button>
    <script>
        function openCity(cityName,elmnt,color){
            let i, tabcontent, tablinks;
            tabcontent = document.getElementsByClassName("tabcontent");
            for (let i = 0; i < tabcontent.length; i++) {
                tabcontent[i].style.display="none";
            }
            tablinks=document.getElementsByClassName("tablink");
            for (let i = 0; i < tablinks.length; i++) {
                tablinks[i].style.backgroundColor = "";
                
            }
            document.getElementById(cityName).style.display="block";
            document.getElementById("defualtOpen").click()
        }
    </script>
</body>
</html>
profile
기록과 정리하는것을 계속해서 하려고 노력중이에요 😊

0개의 댓글