CSS基础- 3.17背景图练习

页面效果图

在这里插入图片描述

  • 所用到的图片如下:
  1. 导航栏背景图
    在这里插入图片描述

  2. logo
    在这里插入图片描述

  3. button
    在这里插入图片描述

  4. 背景图
    在这里插入图片描述

  5. 1.jpg
    在这里插入图片描述

  6. 2.jpg
    在这里插入图片描述

  7. 3.jpg
    在这里插入图片描述

  8. 4.jpg
    在这里插入图片描述

HTML代码

<!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>魔兽</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/index.css">
</head>

<body>
    <header class="header">
        <nav>
            <a href="">进入官网</a>
            <a href="">账号注册</a>
            <a href="">充值管理</a>
            <a href="">游戏下载</a>
            <a href="">官方论坛</a>
            <a href="">客户中心</a>
        </nav>
        <!-- 一般logo用a元素表示,因为可以点击 -->
        <a href="" class="logo">
            <!-- 该文字在样式上要被隐藏,该文字主要是给浏览器看的 -->
            <h1>魔兽世界</h1>
        </a>
    </header>

    <div class='menu'>
        <a href="" class='detail'>
             <!-- 该文字在样式上要被隐藏,该文字主要是给浏览器看的-->
            <span>了解详情</span>
        </a>
        <a href="" class="download">
             <!-- 该文字在样式上要被隐藏,该文字主要是给浏览器看的-->
           <span>客户端下载</span> 
        </a>
    </div>

    <div class="adv">
        <div class="item clearfix">
            <div class="title">
                <h2>
                    <a href="">点卡兑换现已开启</a>
                </h2>
            </div>
            <div class="img">
                <a href="">
                    <img src="./img/1.jpg" alt="">
                </a>
            </div>
        </div>

        <div class="item">
            <div class="title">
                <h2>
                    <a href="">直升110级现已开启</a>
                </h2>
            </div>
            <div class="img">
                <a href="">
                    <img src="./img/2.jpg" alt="">
                </a>
            </div>
        </div>

        <div class="item">
            <div class="title">
                <h2>
                    <a href="">客户端下载</a>
                </h2>
            </div>
            <div class="img">
                <a href="">
                    <img src="./img/3.jpg" alt="">
                </a>
            </div>
        </div>

        <div class="item">
            <div class="title">
                <h2>
                    <a href="">免费注册</a>
                </h2>
            </div>
            <div class="img">
                <a href="">
                    <img src="./img/4.jpg" alt="">
                </a>
            </div>
        </div>

    </div>
</body>

</html>

CSS代码

.clearfix::after{
    content: '';
    display: inline;
    clear: both;
}
body{
    /* 先写位置,如center,或者左右,上边为0 0 ,再写尺寸,或者不设置尺寸 */
    background: url('../img/bg.jpg') no-repeat center top;/* 左右居中 上下为0 */
}

.header{
    width: 1198px;
    height: 73px;
    line-height: 73px;
    color: #f8b770;
    background-color: red;
    margin: 0 auto;
    margin-top: 45px;
    background: url('../img/bg_nav.jpg') no-repeat 0 0/100% 100%;
    /* header元素有上下边框,没有左右边框 */
    border:1px solid #3f2a22;
    border-left: none;
    border-right: none;
    position: relative;
}

.header nav a{
    float: left;
    width: 161px;
    height: 73px;
    text-align: center;
    /* 边框要占据尺寸,最好设置一下box-sizing */
    box-sizing: border-box;
    border: 1px solid #3f2a22;
    /* a元素有左右边框,没有上下边框 */
    border-top: none;
    border-bottom: none;
}

.header nav a:nth-child(3){
    margin-right:232px;
}

.header .logo{
    position: absolute;
    width: 238px;
    height: 118px;
    background: url('../img/logo.png') no-repeat;    /* 设置背景图 */
    /* 相对于header元素水平居中 */
    left: 0;
    right: 0;
    margin: 0 auto;
    /* 进行背景图元素微调 */
    top:-37px;
    left:7px;
}
/* 隐藏文字 */
.header .logo h1{
    display: none;
}

.menu{
    /* 只要是行盒居中,设置text-align即可 */
    text-align: center;
    margin-top: 473px;
}
.menu a {
    display: inline-block;
    width: 330px;
    height: 130px;
    background-color: red;
    /* 给两个a元素设置同一个背景图,使用background-position来选取所要的部分 */
    background: url('../img/btns.png') no-repeat;
}
.menu a span{
    display: none;
}
/* 使用background-position来选取所要的部分*/
.menu .detail{
    background-position: 5px 0;
}
.menu .download{
   background-position: -325px 0;
} 
.adv{
    width:1203px;
    margin: 76px auto;
}
.adv .item{
    float:left;
    width: 290px;
    height: 200px;
    margin-right: 13px;
    outline: 1px solid #3f2a22;/* 使用外边框 不占据尺寸 */
}
.adv .item:last-child{
    margin-right: 0px;
}
.adv .item .title{
    height:50px;
    line-height: 50px;
    text-align: center;
    background-color: #211510;
    color: #f8b700;
    border-bottom: 1px solid #3f2a22;
    box-sizing: border-box;
}
.adv .item .img{
    height: 150px;
}
/* 设置img类中的img元素 */
.adv .item .img img{
    width: 290px;
    height: 150px;
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值