본문 바로가기

Web

HTML, CSS를 활용하여 화면 만들기

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <title>푸드파이터</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="../static/firebase2.js" type="module"></script>

    <style>
        @import url('https://fonts.googleapis.com/css2?family=Gowun+Dodum&family=Nanum+Pen+Script&display=swap');
        @import url('https://fonts.googleapis.com/css2?family=Black+Han+Sans&family=Gowun+Dodum&family=Nanum+Pen+Script&display=swap');

        * {
            font-family: "Gowun Dodum", sans-serif;
        }

        body {
            background-color: white;
            color: black;
        }

        .header {
            background-size: cover;
            background-image:
                url('https://images.unsplash.com/photo-1531697218799-ed0ae884c6c8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2080&q=80');
            background-position: right;
            height: 600px;
            display: flex;
            flex-direction: column;
        }

        .header h1 {
            font-size: 40px;
            font-family: "Black Han Sans", sans-serif;
        }

        .header div {
            font-size: 18px;
        }

        .header p {
            width: 400px;
        }

        .form-button {
            width: 150px;
            height: 40px;
            background-color: transparent;
            border: 1px solid tr;
            color: black;
            font-size: 15px;
            margin: 20px 10px 0px 0px;
        }

        .form-button:hover {
            border: 2px solid black;
        }

        .info-button {
            margin: 20px 0 0 15px;
            height: 40px;
            font-size: 14px;
        }

        .form-floating input,
        .form-floating textarea {
            color: black;
            background-color: white;
        }

        .button2 {
            display: flex;
            justify-content: flex-end;
            margin-top: 15px;
        }

        .button2>button {
            margin-right: 10px;
        }

        .mycards {
            width: 1400px;
            margin: 30px auto 10px auto;
            flex-direction: row;
            align-items: center;
        }

        .card {
            border-radius: 30px;
            width: 400px;
            border: none;
            color: black;
            margin: 10px auto 10px auto
        }

        .card-img-top {
            object-fit: cover;
            height: 220px;
            border-radius: 20px;
        }

        .card-title {
            margin-top: 10px;
            font-size: 18px;
        }

        .card-body {
            border: blanchedalmond 2px solid;
            border-radius: 20px;
            height: 170px;
        }

        .card-text {
            color: black;
        }

        .comment {
            color: black;
        }

        .play-button {
            display: flex;
            justify-content: flex-start;
            margin-top: 15px;
        }

        a.nav-link {
            color: #F17228;
            font-size: large;
        }

        .icon {
            height: 50px;
        }

        .card-button {
            background-color: orange;
            color: white;
            text-align: center;
            padding: 10px 15px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
        }

        .card-title {
            font-weight: bold;
        }

        .card-button> :hover {
            background-color: darkorange;
        }

        #input-card {
            width: 430px;
            margin: 0px 0px 0px 100px;
            padding: 20px;
            background-color: #f9f9f9;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            float: left;
        }

        .form-floating input,
        .form-floating textarea {
            color: black;
            background-color: #f9f9f9;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-bottom: 10px;
            padding: 10px;
            width: 100%;
        }

        .form-floating label {
            color: #333;
        }

        .input-group button,
        .input-group select {
            background-color: rgb(168, 161, 161);
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 10px;
        }

        .input-group button:hover,
        .input-group select:hover {
            background-color: gray;
        }

        .button2 {
            text-align: right;
        }

        .button2 button {
            background-color: #F17228;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        .button2 button:hover {
            background-color: #f3620f;
        }

        .jumbotron-message {
            margin-left: 150px;
            font-size: 1500px;
        }

        #explain {
            margin-top: 10px;
            margin-left: 100px;
            height: 200px;
        }

        #order_btn {
            background-color: #f3620f;
        }
    </style>
    <script>
        function addFood() {
            let img = $('#food_img').val()
            let name = $('#food_title').val()
            let star = $('#food_star').val()
            let res = $('#food_res').val()

            temp = `
            <div class="col">
              <div class="card h-100">
                <img src="${img}" class="card-img-top" alt="...">
                <div class="card-body">
                  <h5 class="card-title">${name}</h5>
                  <p class="food-star">${star}</p>
                  <p class="card-text">${res}</p>
                  <button class="card-button">주문하기</button>
                </div>
              </div>
            </div>
            `

            $('#cards').append(temp)
        }
    </script>
</head>

<body>
    <!-- Navbar -->
    <header class="p-3 text-bg-dark">
        <div class="container">
            <div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
                <a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-white text-decoration-none">
                    <svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap">
                        <use xlink:href="#bootstrap"></use>
                    </svg>
                </a>
                <ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
                    <img src="https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/food.png"
                        class="icon"></li>
                    <li><a href="#" class="nav-link px-2 text-danger">Foodcourt</a></li>
                    <li><a href="#" class="nav-link px-2 ">홈</a></li>
                    <li><a href="#" class="nav-link px-2 ">한식</a></li>
                    <li><a href="#" class="nav-link px-2 ">일식</a></li>
                    <li><a href="#" class="nav-link px-2 ">중식</a></li>
                    <li><a href="#" class="nav-link px-2 ">양식</a></li>
                </ul>
                <form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" role="search">
                    <input type="search" class="form-control form-control-dark text-bg-dark" placeholder="Search..."
                        aria-label="Search">
                </form>
                <div class="text-end">
                    <button type="button" class="btn btn-warning me-2">Login</button>
                    <button type="button" class="btn btn-warning">Sign-up</button>
                </div>
            </div>
        </div>
    </header>

    <!-- 점보 트론 적용 jumbotron -->
    <div class="header">
        <div id="explain" class="container-fluid py-5">
            <h1 class="display-5 fw-bold">스파르타 푸드파이터</h1>
            <p class="col-md-8 fs-4">본인만의 맛집을 소개하는 사이트입니다. 맛집을 소개해주세요!</p>
        </div>
        <div class="post" id="input-card">
            <div class="form-floating mb-3">
                <input type="email" class="form-control" id="food_img" placeholder="name@example.com">
                <label for="floatingInput">음식 이미지 주소</label>
            </div>
            <div class="form-floating mb-3">
                <input type="text" class="form-control" id="food_title">
                <label for="foodTitle">음식명</label>
            </div>
            <div class="input-group mb-3">
                <button class="btn btn-outline-secondary" type="button">별점</button>
                <select class="form-select" id="food_star" aria-label="Example select with button addon">
                    <option selected>별점 선택</option>
                    <option value="⭐">⭐</option>
                    <option value="⭐⭐">⭐⭐</option>
                    <option value="⭐⭐⭐">⭐⭐⭐</option>
                    <option value="⭐⭐⭐⭐">⭐⭐⭐⭐</option>
                    <option value="⭐⭐⭐⭐⭐">⭐⭐⭐⭐⭐</option>
                </select>
            </div>
            <div class="form-floating">
                <textarea class="form-control" placeholder="Leave a comment here" id="food_res"></textarea>
                <label for="floatingTextarea">추천 이유</label>
            </div>
            <div class="button2">
                <button onclick="addFood()" type="button" class="btn btn-danger" id="addBtn"> 기록하기 </button>
            </div>
        </div>
    </div>

    <!-- 부트스트랩 카드 적용-->
    <div class="mycards">
        <div class="row row-cols-1 row-cols-md-3 g-4" id="cards">
            <div class="col">
                <div class="card h-100">
                    <img src="https://cdn.dominos.co.kr/admin/upload/goods/20240214_sLfmidPm.jpg" class="card-img-top"
                        alt="...">
                    <div class="card-body">
                        <h5 class="card-title">하와이안 피자</h5>
                        <p class="food-star">⭐⭐⭐⭐</p>
                        <p class="card-text">이건 꼭 먹어봐야 해!</p>
                        <button class="card-button">주문하기</button>
                    </div>
                </div>
            </div>

            <div class="col">
                <div class="card h-100">
                    <img src="https://www.bhc.co.kr/upload/bhc/menu/%EC%96%91%EB%85%90%EC%B9%98%ED%82%A8-%EC%BD%A4%EB%B3%B4_410x271.png" class="card-img-top"
                        alt="...">
                    <div class="card-body">
                        <h5 class="card-title">양념치킨</h5>
                        <p class="food-star">⭐⭐⭐</p>
                        <p class="card-text">달달구리해용</p>
                        <button class="card-button">주문하기</button>
                    </div>
                </div>
            </div>

        </div>

    </div>

    <div class="container2">
        <footer class="row row-cols-1 row-cols-sm-2 row-cols-md-5 py-5 my-5 border-top">
            <div class="col mb-3">
                <a href="/" class="d-flex align-items-center mb-3 link-body-emphasis text-decoration-none">
                </a>
                <p class="text-body-secondary">©Teamsparta 2024</p>
            </div>
            <div class="col mb-3">
            </div>
            <div class="col mb-3">
                <h5>Section</h5>
                <ul class="nav flex-column">
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Home</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Features</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Pricing</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">FAQs</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">About</a></li>
                </ul>
            </div>

            <div class="col mb-3">
                <h5>Section</h5>
                <ul class="nav flex-column">
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Home</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Features</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Pricing</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">FAQs</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">About</a></li>
                </ul>
            </div>

            <div class="col mb-3">
                <h5>Section</h5>
                <ul class="nav flex-column">
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Home</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Features</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Pricing</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">FAQs</a></li>
                    <li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">About</a></li>
                </ul>
            </div>
        </footer>
    </div>
</body>

</html>

 

 

고민했던 점

만들면서 고민했던 부분은 각각의 컴포넌트 위치를 배치할 때, 화면이 깨지거나 간격이 너무 벌어지는 경우가 있는 것 같아서 그 부분에서 시간을 좀 썼던 것 같다.

하지만 결국 핵심은 <div> 태그로 묶여있는 컴포넌트를 확실하게 파악하고(background-color를 주면 더 확실하게 알 수 있음) width, height의 길이를 지정한 후 padding(내부여백)과 margin(외부여백)을 적절히 주는 것 인것 같다.

margin을 줄 때 margin: 20px 0px 1px 20px; 이게 동서남북인지 상하좌우 인지 헷갈렸는데 (ㅋㅋㅋ) 

순서는 시계 방향 : 위 → 오른쪽 → 아래 → 왼쪽이렇게 외우면 금방 외울 수 있었다!!

 

정리하자면 화면 만들 때 핵심은 

  • 컴포넌트의 범위 확실히 파악
  • 가로,세로 길이 주기
  • 마진, 패딩으로 적절히 위치 조절

이다~!

'Web' 카테고리의 다른 글

웹개발 종합반 5주차  (2) 2024.12.16
웹개발 종합반 4주차  (0) 2024.12.16
웹개발 종합반 3주차  (0) 2024.12.13
웹개발 종합반 2주차  (0) 2024.12.12
웹개발 종합반 1주차  (1) 2024.12.11