Westagram - 2. main page html/css/Js

quokkaยท2021๋…„ 10์›” 24์ผ
0

Project

๋ชฉ๋ก ๋ณด๊ธฐ
2/6
post-thumbnail

๐ŸŒˆ Instagram clone์ฝ”๋”ฉ์„ ํ•ด๋ณด์•˜๋‹ค.

๐ŸŒ€ main page
๐Ÿ“Œ mainํŽ˜์ด์ง€ ๋Œ“๊ธ€์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ์— ๋Œ“๊ธ€์ฐฝ์— ๋Œ“๊ธ€์ด ์ž…๋ ฅ๋˜๊ฒŒ ๊ตฌํ˜„
๋‚ด๊ฐ€ ๊ตฌํ˜„ํ•ด๋ณธ main page ๐Ÿ‘‡

โœ๏ธ main.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=3.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>westagram</title>
    
    <!-- ์™ธ๋ถ€ ์Šคํƒ€์ผ์‹œํŠธ ์—ฐ๊ฒฐ -->
    <link rel="icon" type="image/png" href="imgs/favicon.png" />
    <link rel="stylesheet" href="common.css">
    <link rel="stylesheet" href="style.css">
    <style type="text/css"></style>
    
    <!-- ์™ธ๋ถ€ ์Šคํฌ๋ฆฝํŠธ ์—ฐ๊ฒฐ -->
    <script src="index.js" defer></script>
    
    <!-- ํฐํŠธ์–ด์ธ -->
    <script src="https://kit.fontawesome.com/684e97b7f2.js" crossorigin="anonymous"></script>

</head>

<!-- body start -->
<body>
    <main>
        <!-- ํ—ค๋” -->
        <header>
            <nav>
            <!-- ๋กœ๊ณ  -->
            <div class="logo">
                <div onClick="location.href='#'">
                    <a><i class="fab fa-instagram"></i></a>
                </div>
                <div class="wefont">
                <h3 class="we"><a>WESTAGRAM</a></h3> 
                </div>
            </div>
            <!-- ๊ฒ€์ƒ‰ -->
            <div class="searchbar">
                <input type="text" placeholder="๊ฒ€์ƒ‰">
            </div>
            <!-- ์•„์ด์ฝ˜๋“ค -->
            <div class="nav">
                <div class="navo" onClick="location.href='#'"></div>
                <div class="navt" onClick="location.href='#'"></div>
                <div class="navh" oncCick="location.href='#'"></div>  
            </div>
            </nav>
        </header>

        <!-- ์ธ์Šคํƒ€๊ทธ๋žจ ํ”ผ๋“œ & ์Šคํ† ๋ฆฌ  -->
        <article>
            <!-- ์ธ์Šคํƒ€๊ทธ๋žจ ํ”ผ๋“œ -->
            <section class="peedleft">
                <!-- peedleft์˜ ํ—ค๋”๋ถ€๋ถ„ -->
                <div class="top">
                    <div class="toplogo">
                        <div class="topimg">
                            <a><img src="https://i.ibb.co/CQGw903/Kakao-Talk-Image-2021-10-14-18-01-43.jpg" alt=""></a>
                        </div>
                        <h4 class="memberid"><a>Cello_daily.0</a></h4>
                    </div>
                    <a><i class="fas fa-ellipsis-h"></i></a>

                </div>
                <!-- ํ”ผ๋“œ์ด๋ฏธ์ง€ -->
                <div class="peedimg"></div>
                <!-- ์ด๋ฏธ์ง€ ์•„๋ž˜ ๋ถ€๋ถ„ -->
                <div class="peedundericons">
                    <div class="underleft">
                        <a><i class="fas fa-heart"></i></a>
                        <a><i class="far fa-comment"></i></a>
                        <a><i class="fas fa-external-link-alt"></i></a>
                    </div>
                    <div class="underight">
                        <a><i class="far fa-bookmark"></i></a>
                    </div>
                </div>
                <!-- ํ”ผ๋“œ ์•„์ด๊ณค ์•„๋ž˜ ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค ๋ถ€๋ถ„ -->
                <div class="peedunderlikes">
                    <div class="likesleft">
                        <a><img src="https://i.ibb.co/CQGw903/Kakao-Talk-Image-2021-10-14-18-01-43.jpg" alt=""></a>
                        <p><a href="#">cookies</a>๋‹˜ ์™ธ<a href="#"> 10๋ช…์ด</a> &nbsp;์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค</p>
                    </div>
                </div>
                <!-- ํ”ผ๋“œ ์•„๋ž˜ ํ…์ŠคํŠธ ๋ถ€๋ถ„ -->
                <div class="peedtext">
                    <p class="canon"><a href="#">canon_mj</a> ์œ„์›Œํฌ์—์„œ ์ง„ํ–‰ํ•œ ๋ฒ ์ดํ‚น ํด๋ž˜์Šค...<a> ๋” ๋ณด๊ธฐ</a></p>
                    <div class="id2flexbox">
                        <p class="id2"><a href="#">neceosecius</a> ๊ฑฐ๋ด ์ข‹์•˜์ž–์•„~~~ ๐ŸŒ ๐ŸŒ</p>
                        <a><i class="far fa-heart"></i></a>
                    </div>
                    <span class="minit">
                        <p><a href="#">42๋ถ„ ์ „</a></p>
                    </span>
                    <ul id="commentLists">
                        <li></li>
                    </ul>
                </div>
                <!-- ํ”ผ๋“œ์•„๋ž˜ ๋Œ“๊ธ€ ๋‹ค๋Š” ๋ถ€๋ถ„ + ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ ์—ฐ๋™ํ•ด์•ผํ•˜๋Š” ๋ถ€๋ถ„ -->
                <div class="comment">
                    <input id="name" clss="names" type="text" placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...">
                    <button class="upload" id="submit">๊ฒŒ์‹œ</button>
                </0>
                </div>

            </section>

        <!-- ์ธ์Šคํƒ€๊ทธ๋žจ ์˜ค๋ฅธ์ชฝ ์Šคํ† ๋ฆฌ๋ถ€๋ถ„ -->
        <!-- ์‚ฌ์ด๋“œ ์˜ค๋ฅธ์ชฝ ๋ถ€๋ถ„ -->
        <section class="side-right">
            <div class="side-container"  onclick="location.href='#'">
                <div>
                </div>
                <div>
                    <div>
                    <p>wecode_bootcamp<br>
                    <p>WeCode<span>์œ„์ฝ”๋“œ</span></p>
                </div>
                </div>
            </div>

            <div class="side-story">
                <div class="side-navigation">
                    <p>์Šคํ† ๋ฆฌ</p>
                    <div onclick="location.href='#'" class="see-all">
                        ๋ชจ๋‘ ๋ณด๊ธฐ
                    </div>
                </div>

                <div class="story" onclick="location.href='#'">
                    <div class="story-img-one"></div>
                    <div class="story-text">
                        <p class="bold">god_jaewon</p>
                        <p class="color">2์‹œ๊ฐ„ ์ „</p>
                    </div>
                </div>
                <div class="story" onclick="location.href='#'">
                    <div class="story-img-two"></div>
                    <div class="story-text">
                        <p class="bold">soyoon</p>
                        <p class="color">33๋ถ„ ์ „</p>

                    </div>
                </div>

                <div class="story" onclick="location.href='#'">
                    <div class="story-img-three"></div>
                    <div class="story-text">
                        <p class="bold">ujinSin</p>
                        <p class="color">10์‹œ๊ฐ„ ์ „</p>
                    </div>
                </div>

                <div class="story" onclick="location.href='#'">
                    <div class="story-img-four"></div>
                    <div class="story-text">
                        <p class="bold">selina</p>
                        <p class="color">20๋ถ„ ์ „</p>
                    </div>
                </div>
            </div>
            <!-- ์ถ”์ฒœ ์‹œ์ž‘ -->
            <div class="side-pick">
                <div class="side-navigation">
                    <p>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</p>
                    <div onclick="location.href='#'" class="see-all">
                        ๋ชจ๋‘ ๋ณด๊ธฐ
                    </div>
                </div>

                <div class="side-wrap">
                    <div class="sidewraps">
                        <div class="side-img side-wrap-img1"></div>
                        <div cass="side-childs">
                            <p class="name">ockNim</p>
                            <p class="info">hoo๋‹˜ ์™ธ 7๋ช…์ด ํŒ”...</p>
                        </div>
                    </div>

                    <button>ํŒ”๋กœ์šฐ</button>
                </div>

                <div class="side-wrap">
                    <div class="sidewraps">
                        <div class="side-img side-wrap-img2"></div>
                        <div cass="side-childs">
                            <p class="name">dragonYong</p>
                            <p class="info">god_jaewon๋‹˜ ์™ธ...</p>
                        </div>
                    </div>

                    <button>ํŒ”๋กœ์šฐ</button>
                </div>

                <div class="side-wrap">
                    <div class="sidewraps">
                        <div class="side-img side-wrap-img3"></div>
                        <div cass="side-childs">
                            <p class="name">yeju</p>
                            <p class="info">Hwayeon ์™ธ 4๋ช…์ด...</p>
                        </div>
                    </div>

                    <button>ํŒ”๋กœ์šฐ</button>
                </div>
            </div>

            <div class="footer-wrapper">
                <p>Instagram ์ •๋ณด ยท ์ง€์› ยท ํ™๋ณด์„ผํ„ฐ ยท API ยท <br>์ฑ„์šฉ์ •๋ณด
                ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ ยท ์•ฝ๊ด€ ยท<br> ๋””๋ ‰ํ„ฐ๋ฆฌ ยท ํ”„๋กœํ•„ ยท ํ•ด์‹œํƒœ๊ทธ ยท ์–ธ์–ด</p>
                <p>โ“’ 2019 INSTAGRAM</p>
            </div>
        </section>


        </article>

    </main>
    <script src="index.js" defer></script>
</body>
</html>

โœ๏ธ main.css

/* header start */
header {
    width: 100%;
    height: 90px;
    background-color: rgb(255, 255, 255);
    border-bottom: 1px solid rgb(235, 233, 233);
    position: fixed;
    background-color: white;
    z-index: 999;
    top: 0;
    left: 0;
}
nav {
    width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    padding-top: 20px;
}
/* header logo */
.logo {
    width: 300px;
    display: flex;
    padding-top: 5px;
}
.logo .fa-instagram {
    font-size: 2rem;
    color: black;
    padding-right: 1.1rem;
    border-right: 2px solid black;
}
.logo .wefont {
    padding-left: 1rem;
    padding-top: 0.3rem;
}
.we {
    font-family: 'Lobster', cursive;
    color: black;
    font-size: 1.6rem;
}
/* ํ—ค๋” ๊ฒ€์ƒ‰๋ฐ” */
.searchbar {
    width: 250px;
    /* position: relative; */
}
.searchbar input {
    width: 100%;
    padding: 0.5rem 2rem;
    margin-top: 6px;
    background-color: rgba(238, 235, 235, 0.288);
    border: 1px solid rgba(218, 217, 217, 0.767);
}
.searchbar input::placeholder{
    font-size: 1rem;
    color: silver;
    text-align: center;
    background: url(https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/search-512.png) no-repeat 35% center/20px 20px;
    filter: invert(0.5);
}
input:focus {
    outline: 1px solid rgb(179, 179, 179);
}
/* ํ—ค๋” ์šฐ์ธก ์•„์ด์ฝ˜๋“ค  */
.nav {
    width: 135px;
    height: 45px;
    display: flex;
    justify-content: space-between;
    position: relative;
}
.nav div {
    display: block;
    width: 33px;
    /* height: 35px; */
}
.navo{
    background: url(https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/explore.png) no-repeat;
    background-size: 100%;
    background-position: center;
}
.navt {
    background: url(https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/heart.png) no-repeat;
    background-size: 100%;
    background-position: center;
}
.navh {
    background: url(https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/profile.png) no-repeat;
    background-size: 100%;
    background-position: center;
}
.navt::after {
    content: "";
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: red;
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
}
/* ํ”ผ๋“œ ๋ถ€๋ถ„ */
article {
    width: 1200px;
    height: 100%;
    margin: 5rem auto;
    display: flex;
    justify-content: space-between;
}

.peedleft{
    width: 66%;
    border: 1px solid #e6e6e6;
    margin-top: 80px;
}

.topimg img{
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.top {
    display: flex;
    justify-content: space-between;
    padding: 10px 20px;
}

.toplogo {
    display: flex;
    
}

.memberid a {
    margin-top: 15px;
    margin-left: 15px;
    color: black;
    display: block;
}

.fa-ellipsis-h {
    color: black;
    font-size: 1rem;
    margin-top: 15px;
}

.peedimg {
    width: 100%;
    height: 750px;
    background: url(https://i.ibb.co/Np3sttL/10209-D38-C65-C-4-CEC-B871-43459-D788-A06.jpg) no-repeat;
    background-size: cover;
    background-position: 100%;
}

/* ํ”ผ๋“œ ์•„์ด์ฝ˜๋“ค */
.peedundericons {
    display: flex;
    padding: 10px 0px;
}

.underleft {
    width: 96%;
    display: flex;
    padding-left: 3px;
}

.underleft a {
    display: block;
    font-size: 1.5rem;
    margin-left: 13px;
    color: rgb(145, 145, 145);
}

.underight a {
    display: block;
    font-size: 1.2rem ;
    color: srgb(145, 145, 145);
}

.fa-heart {
    color: red;
}

.fa-comment {
    transform: rotateY(180deg);
}

.fa-bookmark {
    font-size: 1.4rem;
}

/* ์ข‹์•„์š”๋ถ€๋ถ„ */
.likesleft {
    display: flex;
    padding: 0 15px;
    margin-bottom: 0.5rem;
}

.likesleft img {
    width: 25px;
    height: 25px;
    border-radius: 50%;
}

.likesleft p {
    padding-top: 5px;
    margin-left: 8px;
    font-weight: normal;
}

.likesleft p a {
    color: black;
    font-weight: 800;
}

/* ๋Œ“๊ธ€ ๋‹ฌ๋ฆฐ ๋ถ€๋ถ„ */
.peedtext {
    padding-left: 17px;
    border-bottom: 1px solid #e6e6e6;
    padding-bottom: 10px;
}

.canon {
    margin-bottom: 3px;
}

.id2flexbox {
    margin-top: 5px;
    margin-bottom: 5px;
    display: flex;
}

.id2flexbox p {
    width: 96%;
}

.id2flexbox>:nth-child(2) i{
    color: silver;
}

.minit a{
    color: rgb(153, 153, 153);
    font-weight: normal;
}
/* form  ๋Œ“๊ธ€ ๋‹ค๋Š” ๋ถ€๋ถ„*/
.comment {
    width: 100%;;
    position: relative;
}

.comment input {
    width: 90%;
    border: none;
    padding:20px 0;
    padding-left: 15px;
}

.comment input:focus {
    outline: none;
}

.upload {
    padding: 15px 15px;
    border: none;
    font-size: 0.8rem;
    position: absolute;
    color: rgba(113, 147, 238, 0.747);
    background-color: none;
    right: 0px;
    top: 6px;
}

.upload:hover {
    background: none;;
    color: rgba(113, 147, 238, 0.747);
}

#commentLists {
    margin-top: 0.6rem;
    margin-bottom: 0.7rem;
}

#commentLists li {
    width: 100%;
    margin-bottom: 0.3rem;
    position: relative;
    color: black;
}

.delete {
    cursor: pointer;
    position: absolute;
    right: 19px;;
}

.name {
    padding-right: 0.6rem;
    color: black;
    font-weight: bold;
}

/* ํ”ผ๋“œ ์˜ค๋ฅธ์ชฝ ์Šคํ† ๋ฆฌ */
.side-right {
    width: 368px;
    margin-top: 5.3rem;
}

.side-container {
    margin-bottom: 1rem;
    display: flex;
    cursor: pointer;
}

.side-container > :first-child {
    width: 60px;
    height: 60px;
    margin-right: 1rem;
    border-radius: 100%;
    background: url(https://pbs.twimg.com/profile_images/1109389733912666112/XX55fTPf.jpg)
no-repeat;
    background-size: cover;
    background-position: center;
}

.side-container > :last-child {
    position: relative;
}

.side-container > :last-child div {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.side-container > :last-child div > :first-child {
    margin-bottom: 0.3rem;
    font-weight: bold;
}

.side-container > :last-child div > :last-child {
    color: #bababa;
}

.side-container > :last-child div > :last-child span:before {
    content: "โ”ƒ";
}

.side-story {
    padding: 1rem;
    margin-bottom: 1rem;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 5px;
    height: 258px;
    overflow-y: hidden;
}

.side-navigation {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
}

.side-navigation p {
    color: #bababa;
}

.see-all {
    color: rgb(73, 73, 73);
    font-weight: 760;
}

.story {
    display: flex;
}

.story > :first-child {
    width: 50px;
    height: 50px;
    margin-right: 1rem;
    border: 2px solid #e56c9f;
    border-radius: 100%;
}

.side-story > :nth-child(2),
.side-story > :nth-child(3),
.side-story > :nth-child(4) {
    margin-bottom: 0.8rem;
}

.story-text {
    margin-top: 5px;
}

.story-img-one {
    background: url(https://images.unsplash.com/photo-1519764622345-23439dd774f7?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8Ym95c3xlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60)
no-repeat;
    background-size: cover;
    background-position: top;
}

.story-img-two {
    background: url(https://media.istockphoto.com/photos/teen-girl-after-her-vaccination-picture-id1311564458?b=1&k=20&m=1311564458&s=170667a&w=0&h=fK1QViaweFI1OlHtQ6G3S4VrrrMK2lMDrZK-d6yTGms=)
no-repeat;
    background-size: cover;
    background-position: center;
}

.story-img-three{
    background: url(https://images.unsplash.com/photo-1554230505-919a13968970?ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8Z2lybHN8ZW58MHx8MHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60)
no-repeat;
    background-size: cover;
    background-position: center;
}

.story-img-four{
    background: url(https://images.unsplash.com/photo-1524601500432-1e1a4c71d692?ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8Z2lybHN8ZW58MHx8MHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60)
no-repeat;
    background-size: cover;
    background-position: center;
}

.bold {
    margin-bottom: 0.3rem;
    font-weight: bold;
}

.color {
    color: #bababa;
}

/*์ถ”์ฒœ ์‹œ์ž‘*/
.side-pick {
    padding: 1rem;
    margin-bottom: 1rem;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 5px;
    position: relative;
}

.side-pick > :nth-child(2),
.side-pick > :nth-child(3) {
    margin-bottom: 0.3rem;
}

.side-wrap {
    display: flex;
    position: relative;
}

.sidewraps {
    display: flex;
}

.sidewraps>:last-child {
    margin-top: 1rem;
}

.side-img {
    width: 50px;
    height: 50px;
    margin-right: 1rem;
    border-radius: 100%;
    margin-top: 8px;
}

.side-wrap-img1 {
    background: url(https://images.unsplash.com/photo-1502307100811-6bdc0981a85b?ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8Ym95c3xlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60)
no-repeat;
    background-size: cover;
    background-position: center;
}

.side-wrap-img2 {
    background: url(https://images.unsplash.com/photo-1613852348851-df1739db8201?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTR8fGJveXN8ZW58MHx8MHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60)
no-repeat;
    background-size: cover;
    background-position: center;
}

.side-wrap-img3 {
    background: url(https://images.unsplash.com/photo-1500336624523-d727130c3328?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTB8fGdpcmxzfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60)
no-repeat;
    background-size: cover;
    background-position: center;
}

.side-wrap > :first-child > :last-child > :first-child {
    margin-bottom: 0.3rem;
    font-weight: bold;
}

.side-wrap > :first-child > :last-child > :last-child {
    color: #bababa;
}

.side-wrap > :last-child {
    padding: 1.5rem 0 1rem 1rem;
    color: #2398ff;
    background: none;
    position: absolute;
    right: 0;
    border: none;
    font-size: 0.9rem;
    font-weight: 700;
}

.footer-wrapper p {
    color: #acacac;
    line-height: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

โœ… ย ย css๋ฅผ ์ž‘์„ฑํ•˜๋ฉด์„œ
๐Ÿ‘‰ ์ฒ˜์Œ ์ธ์Šคํƒ€๊ทธ๋žจ ํด๋ก  ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ•˜๋ฉด์„œ ์˜ˆ์‹œ ์ด๋ฏธ์ง€๋ฅผ ๋ณด๊ณ  ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ต์ง€ ์•Š๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์ง€๋งŒ css๋ฅผ ํ•˜๋ฉด์„œ ์ƒ๊ฐ ํ–ˆ๋˜๊ฒƒ๋ณด๋‹ค ํ• ๊ฒŒ ๋งŽ์•˜๊ณ  ๋„์ค‘์— ํ—ท๊ฐˆ๋ ธ๋˜ ๋ถ€๋ถ„๋“ค์ด ์กฐ๊ธˆ ์žˆ์—ˆ๋‹ค. display: flex๋ฅผ ์œ„ํ•ด์„œ ํ•˜๋‚˜์”ฉ div๋ฅผ ๋” ๊ฐ์‹ธ์ฃผ๋Š”๊ฒŒ ๋งž์„์ง€, position: absolute๋ฅผ ์‚ฌ์šฉํ•ด์„œ div์˜ ๊ฐฏ์ˆ˜๋ฅผ ์ค„์ด๋Š”๊ฒŒ ๋งž์„์ง€ ๊ณ ๋ฏผํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ๋‚˜๋Š” ์ด๋ฒˆ westagram์—์„œ๋Š” flex๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ–ˆ๋‹ค.


๐Ÿ‘‰ input์ฐฝ css์— ์กฐ๊ธˆ ๋” ๊ณต๋ถ€ํ•˜๊ณ  ์•Œ๊ฒŒ๋˜๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์ ธ์„œ ์ข‹์•˜๋‹ค!. ํ•ญ์ƒ ๊นŒ๋‹ค๋กญ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์—ˆ์ง€๋งŒ ์ด๋ฒˆ์— input์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์ƒ๊ฐ๋ณด๋‹ค input์„ ์ ์šฉํ•˜๋Š”๋ฐ ์žˆ์–ด์„œ ์กฐ๊ธˆ๋” ๊ฐ€๊นŒ์›Œ ์ง„๊ฒƒ ๊ฐ™๋‹ค. input์— ๋ถ€๋ชจ ์š”์†Œ๋ฅผ ํ•˜๋‚˜ ๋” ๊ฐ์‹ผ๊ณ  ๊ฑฐ๊ธฐ์— width๊ฐ’์„ ์ค€๋‹ค์Œ์— input์˜ width: 100%๋ฅผ ํ•œ๋‹ค์Œ ๋ถ€๋ชจ ์š”์†Œ์— margin: 0 auto๋ฅผ ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์œ„์น˜ ์‹œ์ผฐ๋‹ค.

โœ๏ธ main.js

'use strict';

const commentInput = document.getElementById("name");
const submit = document.getElementById("submit");

function checkInput() {
    if(!commentInput.value.length) {
        alert("๋Œ“๊ธ€์„ ์ž…๋ ฅํ•˜์„ธ์š”");
    }else{
        registerComment(commentInput.value);
    }
}
function registerComment(value){
    const commentLists = document.getElementById("commentLists");
    const newCommentList = document.createElement("li");
    const newComment = `<span class="name">jiwon</span><span>${value}</span><span class="delete">X</span>`
    
    newCommentList.innerHTML = newComment;
    deleteComment(newCommentList);
    commentLists.appendChild(newCommentList);
    commentInput.value = "";
}

function deleteComment(newCommentList) {
    const deleteBtn = newCommentList.querySelector(".delete");
    deleteBtn.addEventListener("click", () => newCommentList.remove());
}


commentInput.addEventListener('keyup', () => {
    if (window.event.code === 'Enter') {
        checkInput();
    }else {
        submit.addEventListener("click", checkInput);
    }
});

// const init = () => {
//     submit.addEventListener("click", checkInput);
// };
// init();

const inputId = document.querySelector("#name");
const button = document.querySelector('.upload');

function commentBtn() {
    let idValu = inputId.value;

    if(idValu.length > 0) {
        button.disabled = false;
        button.style.cursor = 'pointer';
        button.style.color = '#1c7ed6';
    } else {
        button.disabled = true;
        button.style.cursor = 'default';
        button.style.color = 'skyblue  ';
    }
}
inputId.addEventListener('keyup', commentBtn);

โœ… ย ย js๋ฅผ ์ž‘์„ฑํ•˜๋ฉด์„œ
๐Ÿ‘‰ ๋Œ“๊ธ€์ฐฝ input์— ๋Œ“๊ธ€์„ ์ž…๋ ฅํ•˜๊ณ  '๊ฒŒ์‹œ'๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๊ฒฝ์šฐ๋‚˜ enterํ‚ค๋ฅผ ์ณค์„ ๊ฒฝ์šฐ์— ๋Œ“๊ธ€์ด ์ƒ์„ฑ๋˜๊ฒŒ ๋งŒ๋“ค์–ด์•ผํ–ˆ๋‹ค.
๊ทธ๋ž˜์„œ createElement๋กœ ์ƒˆ๋กœ์šด ๊ฐ’ li๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ํ•˜๊ณ  ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•œ li๋ฅผ innerHTML๋กœ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. ์ƒˆ๋กœ ์ƒ์„ฑ๋œ li๋ฅผ ์‚ญ์ œ ํ•  ์ˆ˜๋„ ์žˆ๊ฒŒ delete x๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ x๋ฅผ ๋ˆŒ๋ €์„ ๊ฒฝ์šฐ์— ๋Œ“๊ธ€์ด ์‚ญ์ œ๋  ์ˆ˜ ์žˆ๊ฒŒ๋„ ๊ตฌํ˜„ํ•ด๋ณด์•˜๋‹ค.


๐Ÿ”ฅ ๋Œ“๊ธ€ ์ฐฝ js๋Š” ๋จธ๋ฆฟ์†์—์„œ ํ˜ผ์ž ์ƒ๊ฐํ•ด๋‚ด๊ธฐ ํž˜๋“  ๋ถ€๋ถ„๋“ค์ด ์žˆ์—ˆ์ง€๋งŒ ๊ณ„์† ๊ณต๋ถ€ํ•˜๋ฉด์„œ ๋ฐœ์ „์‹œํ‚ค๊ณ  ์žˆ๋‹ค.

profile
๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๋งค์ผ๋งค์ผ์ด ๊ธฐ๋Œ€๋˜๋Š” ๊ฐœ๋ฐœ์ž ^^

0๊ฐœ์˜ ๋Œ“๊ธ€