1. 程式人生 > 其它 >2021/10/29

2021/10/29

HTML頁面

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/header.css"/>
    </head>
    <body>
        <div class="head">
            <div class="line1"
> <span class="log"> <img src="img/logo/yinLogo.png" > </span> <ul> <li><a href="#">官方微博</a></li> <li><a href="#">關注微信</a></li>
<li><a href="reading.html" target="_top">購物須知</a></li> //如果使用a標籤連結,則必須使用target="_top" </ul> </div> <div class="line2"> <span class="log"> <img src="img/logo/shop-logo-v1.png"
> </span> <div> <input type="text" class="search" placeholder="搜尋偶像、商品" /> <span class="btn"></span> </div> <ul> <li><img src="img/icon/avatar.png" class="login"><a href="login.html">登入</a></li> <li><a href="#">我的訂單</a></li> <li><img src="img/icon/cart-logo-v1.png" class="cart"><a href="#">購物車</a></li> </ul> </div> <hr > <div class="line3"> <span class="title"><a href="">藝人分類</a></span> <ul> <li><a href="index.html" target="_top" class="active">首頁</a></li> <li><a href="list.html" target="_top">專輯</a></li> <li><a href="#">明星周邊</a></li> <li><a href="#">明星同款</a></li> <li><a href="#">個護美妝</a></li> <li><a href="#">影漫周邊</a></li> <li><a href="#">食品</a></li> <li><a href="#">服裝配飾</a></li> </ul> </div> </div> </body> </html>

CSS頁面

body{
    margin: 0;
}
.head{
    background-color: #222;
}
.head ul{
    padding-left: 0;
}
.head ul li{
    display: inline-block;
}
.head a{
    text-decoration: none;
    color: white;
    display: block;
    font-size: 14px;
    /* display: block;填充父元素 */
}
.head .line1{
    background-color: #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.head .line1 .log{
    margin-left: 200px;
}
.head .line1 ul{
    margin-right: 200px;
}
.head .line1 li{
    width: 100px;
    border-right: 1px solid #999;
    text-align: center;
} 
.head .line1 li a{
    color: #999;
}
.head .line1 li:last-child{
    border: none;
}
.head .line2{
    width: 1000px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.head .line2 div{
    position: relative;//相對定位
}
.head .line2 .search{
    display: inline-block;
    width: 447px;
    height: 40px;
    background: url(../img/icon/search_icon.png);
    background-position: 0px -43px;
    color: #999;
    border: none;
    outline: none;
    padding-left: 16px;
    font-size: 16px;
}
.head .line2 .search:focus{
    background-position: 0 1px;
    color: #333;
}
.head .line2 .btn{
    display: inline-block;
    width: 32px;
    height: 40px;
    background: url(../img/icon/search_icon.png);
    background-position: -454px 0px;
    position: absolute;
    right: 25px;
}
.head .line2 .search:focus + .btn{
    background-position: -456px -42px;
}
.head .line2 ul li{
    margin: 0 15px;
}
.head .line2 ul li a{
    display: inline-block;
}
.head .line2 li img{
    display: inline-block;
    width: 20px;
    height: 20px;
    vertical-align: middle; //垂直居中對齊
    margin-right: 10px;
}
.head hr{
    border: none; //hr本來就有上下邊框(各1px),所以需要設定border:none;
    border-top: 1px solid #999;//相當於hr有1px的高度
    margin-bottom: 0;
}
.head .line3{
    width: 1000px;
    margin: 0 auto;
//flex佈局 display: flex; justify-content: space-between; //兩端對齊 align-items: center; //子元素居中對齊 } .head .line3 .title a{ display: block; background-color: #000000; line-height: 53px; width: 90px; text-align: center; } .head .line3 ul{ margin: 0; } .head .line3 li{ width:90px ; line-height: 53px ; text-align: center; } .head .line3 li a:hover{ color: #DE4767; border-bottom: 3px solid #DE4767; line-height: 46px; } .head .line3 .active{ color: #DE4767; border-bottom: 3px solid #DE4767; line-height: 46px; }