<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Responsive Navigation Bar</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css">

<link href="https://fonts.googleapis.com/css?family=Titillium+Web&display=swap" rel="stylesheet">

<link rel="stylesheet" href="css/style.css">

</head>

 

<body>

    <nav>

        <input type="checkbox" id="check">

        <label for="check" class="checkBtn"><i class="fas fa-bars"></i></label>

        

        <h1 class="logo">DesignX</h1>

        <ul>

            <li><a href="#">home</a></li>

            <li><a href="#">about</a></li>

            <li><a href="#">services</a></li>

            <li><a href="#">contact</a></li>

            <li><a href="#">feedback</a></li>

        </ul>

    </nav>

</body>

</html>

 

-----------------reset.css

@charset "utf-8";

/*reset.css*/

 

@import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@300;400;700&display=swap');

 

*margin:0padding:0box-sizing:border-box; }

body { 

    font-family'Titillium Web'sans-serif;            font-size:15pxcolor:#333

    backgroundurl(../imgs/bg.jpgno-repeat center;

    background-attachmentfixed;

    background-sizecover;

}

h1h2h3h4h5h6 { font-family'Merriweather'serif; }

ul li { list-style:nonefloat:left; }

a { display:blocktext-decoration:none; }

img { width:100%; }

.clear { clear:both; }

 

--------------------style.css

 

@charset "utf-8";

 

@import url('reset.css');

 

/*모든 디바이스에 적용할 스타일 시트*/

nav { height80pxpadding:0 50pxbackground:#263;}

nav .logo { 

    displayinline-block

    font-size34pxcolor#fffline-height80px;

}

nav ul { floatrightmargin-top25px;}

nav ul li a { 

    padding:5px 20px;

    color#ffftext-transformuppercaseborder-radius:5px;

    transitionbackground 0.4s ease-in;

}

nav ul li a:hover { background:#797border-radius:5px;}

 

.checkBtn {

    display:nonefloat:right

    font-size:32pxcolor:#fffline-height:80px

    cursorpointer;

}

#check {displaynone;}

 

@media screen and (max-width:1920px) { /*desktop*/

    nav .logo {font-size30px;}

}

@media screen and (max-width:800px) { /*mobile*/

    .checkBtn { display:block; }

    nav ul { 

        position:fixedleft-100%top:55px;

        width100%height100vh;

        text-aligncenter;

        background:rgba(0,0,0,0.7);

        transitionall 0.4s ease-in;

    }

    nav ul li { floatnonepadding35px 0; }

    nav ul li:first-child {margin-top45px;}

    nav ul li a { font-size20px; }

    a:hover { color:#053background:none; }

 

    #check:checked ~ ul { left:0; }

}

 

 

-----------------------html

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title></title>

<link rel="stylesheet" href="css/mediaSpace.css">

</head>

<body>

    <header>

        <h1>logo</h1>

        <nav>

            <ul>

                <li><a href="#">menu1</a></li>

                <li><a href="#">menu2</a></li>

                <li><a href="#">menu3</a></li>

                <li><a href="#">menu4</a></li>

            </ul>

        </nav>

    </header>

</body>

</html>

 

--------mediaSpace.css

 

@charset "utf-8";

 

@import url(reset.css);

 

header { height:60px;  background:#028; }

header h1a { color:#f4f4f4 }

header h1 { float:leftline-height:60px; }

header nav { float:right; }

header a { text-transform:uppercase; }

header a:hover { color:#06fbackground:#fc0border-radius5px; }

 

/*Laptop(1440px), Notebook(1920px), Desktop(FHD:1920px, 4K:2084px, 8K:4096px)*/

@media screen and (min-width:1400px) {

    header { padding:0 50px; }

    header nav { margin-top:15px; }

    header a { padding:5px 25px; }

}

 

/*iPad Pro(1024px), HD(1024px), Desktop(1280px), Notebook(1366px)*/

@media screen and (min-width:1000px) and (max-width:1399px) {

    header { padding:0 30px; }

    header nav { margin-top:15px; }

    header a { padding:5px 25px; }

}

 

/*iPad(768px)*/

@media screen and (min-width:760px) and (max-width:999px) {

    header { padding:0 20pxbackground:#36f; }

    header h1 { line-height:60px; }

    header nav { margin-top:15px; }

    header a { padding:5px 25px;  }

}

 

@media screen and (min-width:570px) and (max-width:759px) {

    header { padding:0 20pxbackground:#36f; }

    header h1 { line-height:60px; }

    header nav { margin-top:15px; }

    header a { padding:5px 25px; }

}

 

/*SmartPhone*/

@media screen and (max-width:569px) {

    header { height:100vh

        background:url(../imgs/bg.jpgno-repeat center;

        background-attachmentfixed;

        background-sizecover; }

    header h1 { 

        position:absoluteleft:50%top:100px;

        font-size54pxcolor:rgba(255,255,255,0.7);

        transform:translateX(-50%); z-index9

    }

    header nav { 

        position:absoluteleft:0top:0width:100%height:100%background:rgba(0,0,0,0.6);

    }

    header ul {width250pxmargin:250px auto 0;}

    header a { 

        width:250pxmargin:15px 0padding:10px 0pxtext-align:centerbackground:rgba(0,0,0,0.3); border-radius5px

    }

}

 

'Coding' 카테고리의 다른 글

CSS 선수학습(12)  (0) 2021.07.27
CSS 선수학습(11)  (0) 2021.07.26
CSS 선수학습(10)  (0) 2021.07.21
CSS 선수학습(9)  (0) 2021.07.21
CSS 복습/실습  (0) 2021.07.20

<!--

※ 반응형 웹 디자인

1.메타 코드 작성

<meta name="viewport" content="sidth=device-width, initial-scale=1">

2.미디어 쿼리(Media Query) 적용: 디바이스의 스크린 크기에 따라 다른 스타일 시트를 적용하는 것.

    2-1. 미디어 쿼리 적용방법

        a. <link> 로 적용

        <link rel="stylesheet" href="./css/fhd-1400.css" media="screen and (min-width:1400px) and (max-width:1920px)">

        <link rel="stylesheet" href="./css/hd-1000.css" media="screen and (min-width:1000px) and (max-width:1399px)">

        <link rel="stylesheet" href="./css/tb-768.css" media="screen and (min-width:760px) and (max-width:999px)">

        <link rel="stylesheet" href="./css/sm.css" media="screen and (max-width:759px)">

 

        b. @media 로 적용

        @media screen and (min-width:1400px) { }

        @media screen and (min-width:1000px) and (max-width:1399px) { }

        @media screen and (min-width:760px) and (max-width:999px) { }

        @media screen and (max-width:759px) { }

 

        ★ <link>보단 @media 를 주로 사용한다.

 

    2-2. 반응형 이미지

        이미지를 선택자로 선택한 후 width를 100%로 지정한다.  

 

    2-3. 부트스트랩(Bootstrap5)의 미디어 쿼리 중단점

        a.576px 미만(xs)

        b.576px 이상(sm)

        c.768px 이상(md)

        d.992px 이상(lg)

        e.1200px 이상(xl)

        f.1400px 이상(xxl)

-->

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="sidth=device-width, initial-scale=1">

<meta charset="utf-8">

<title></title>

<link rel="stylesheet" href="./css/media.css">

</head>

 

<body>

    <h2>media query</h2>

    <div></div>

</body>

</html>

 

----------------media.css

@charset "utf-8";

/*media.css*/

 

@import url("reset.css");

 

h2 { padding-top:100pxfont-size:42pxcolor:#06ftext-align:centertext-transform:uppercase; }

div { width:95%height:500pxmargin:100px autobackground:#fc0; }

 

@media screen and (max-width:576px) { 

    body { background:#000; }

    h2 { font-size32pxcolor:#fff; }

    div { width:100%; }

}

/**/

 

@media screen and (min-width:576px) { 

    body { background:#a50; }

    h2 { font-size32pxcolor:#fff; }

    div { width:100%; }

}

/**/

 

@media screen and (min-width:768px) { 

    body{background:#999;}

}

/*tb:768px*/

 

@media screen and (min-width:1000px) { 

    body { background:#0a8; }

    h2 { color:#fff; }

    div { width:950px; }

}

/*hd:1024px*/

 

@media screen and (min-width:1400px) { 

    body { background:#06f; }

    h2 { color:#fff; }

    div { width:1350px; }

}

/*fhd:1920px*/

 

----------------reset.css

 

@charset "utf-8";

/*reset.css*/

 

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;700&display=swap');

@import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@300;400;700&display=swap');

 

*margin:0padding:0box-sizing:border-box; }

body { font-family'Noto Sans KR'sans-seriffont-size:15pxcolor:#333background:#fff;}

h1h2h3h4h5h6 { font-family'Merriweather'serif; }

ul li { list-style:nonefloat:left; }

a { display:blocktext-decoration:none; }

img { width:100%; }

.clear { clear:both; }

 

 

-----------------------

 

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="sidth=device-width, initial-scale=1">

<meta charset="utf-8">

<title></title>

<link rel="stylesheet" href="./css/header.css">

</head>

 

<body>

    <header>

        <div class="btn"></div>

        <h1>logo</h1>

 

        <nav>

            <ul>

                <li><a href="#">menu01</a></li>

                <li><a href="#">menu02</a></li>

                <li><a href="#">menu03</a></li>

                <li><a href="#">menu04</a></li>

            </ul>

        </nav>

    </header>

</body>

</html>

 

-----------------header.css

 

@charset "utf-8";

/*media.css*/

 

@import url("reset.css");

 

header {

    height70pxpadding0 50px;

    background#000;

}

h1 { position:absolutetop:15pxfont-size28pxcolor#ffftext-transformuppercase;}

a { padding0 20pxcolor#fff; }

a:hover { color#fc0; }

.btn { floatleftwidth40pxheight40pxmargin:15pxbackground#fffborder-radius5px; }

 

@media screen and (max-width:576px) { 

    header {displayblockpadding0; }

    h1 { left50%transformtranslateX(-50%); }

    nav {displaynone;}

}

/*sm:375px*/

 

@media screen and (min-width:576px) { 

    header {

        displayblock;

        padding0background#550;

    }

    h1 { left50%transformtranslateX(-50%); }

    nav {displaynone;}

}

/**/

 

@media screen and (min-width:768px) { 

    header

        background#086;}

    h1{left:80px;}

    a {padding0 15px;}

    nav {displayblockfloat:rightmargin-top25pxmargin-right50px;}

    .btn {displaynone;}

}

/*tb:768px*/

 

@media screen and (min-width:1000px) { 

    headerbackground#049;}

    a {padding0 30px;}

}

/*hd:1024px*/

 

@media screen and (min-width:1400px) { 

    header { background:#006;}

}

/*fhd:1920px*/

'Coding' 카테고리의 다른 글

CSS 선수학습(13)  (0) 2021.07.27
CSS 선수학습(11)  (0) 2021.07.26
CSS 선수학습(10)  (0) 2021.07.21
CSS 선수학습(9)  (0) 2021.07.21
CSS 복습/실습  (0) 2021.07.20

+ Recent posts