学成在线项目-head学习

学成在线项目-head学习

1、先看看原图

2、我们先看看html的源码

<!DOCTYPE html>
<html lang="en">
<head>
    <!--在项目中我们一般都是通过引入外部css链接的形式-->
    <link rel="stylesheet" href="./css/index.css">
    
    <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>
</head>

<body>
    <!-- 网站的首页,所有网站的首页都叫index.html,因为服务器找首页都是找index.html -->
    <!-- 布局,从上到下,从左到右 -->
    <!-- css:浮动/display;盒子模型;文字样式 -->

    <!-- 头部header:负责头部区域的样式,wrapper只负责版心的效果 -->
    <div class="header wrapper">
        <h1>
            <a href="#"><img src="./images/logo.png" alt=""></a>
        </h1>

        <!-- 导航 -->
        <div class="nav">
            <ul>
                <li><a href="#">首页</a></li>
                <li><a href="#">课程</a></li>
                <li><a href="#">职业规划</a></li>
            </ul>
        </div>

        <!-- 搜索 -->
        <div class="search">
            <input type="text" placeholder="输入关键词"><button></button>
        </div>

        <!-- 用户 -->
        <div class="user">
            <img src="./images/user.png" alt="">
            <span>汪涛</span>
        </div>

    </div>

</body>
</html>

3、css的代码如下:

/* index.css是用来美化首页的 */
* {
    margin: 0;
    padding: 0;
    /* 内减模式 */
    box-sizing: border-box;
}

/* 去除小li的前面的点 */
li {
    list-style: none;
}
/* 去掉超链接的下划线 */
a {
    text-decoration: none;
}

.clearfix:before,.clearfix:after {
    content:"";
    display:table; 
  }
  .clearfix:after {
    clear:both;
  }

/*设置总体背景的背景色*/
.body {
    background-color: rgb(248, 245, 242);
}

/* wrapper 主要是控制板心的位置和宽度*/
.wrapper {
    width: 1200px;
    margin: 0 auto;
    /* background-color: antiquewhite; */
}

.header {
    /*设置高度为42像素*/
    height: 42px;
    /*margin:30px auto; 这里设置上下空30像素,左右居中版心*/
    margin: 30px auto;
}

/*关于浮动,一浮动全部浮动*/
h1{
    float: left;
}

/* 导航 */
.nav {
    float: left;
    margin-left: 70px;
    height: 42px;
}
.nav li {
    float: left;
    margin-right: 26px;
}

.nav li a {
    display: block;
    padding: 0 9px;
    height: 42px;
    line-height: 42px;
    /* border-bottom: 2px solid #00a4ff; */

    font-size: 18px;
    color: #050505;
}

/* 鼠标移动到标签上,变成蓝色 */
.nav li a:hover {
    border-bottom: 2px solid #00a4ff;
}

.search {
    float: left;
    margin-left: 59px;
    width: 412px;
    height: 40px;
    border: 1px solid #00a4ff;
}

.search input {
    float: left;
    padding-left: 20px;
    /* 左右加一起的尺寸要小于等于410 */
    width: 360px;
    height: 38px;
    border: 0;
}

/* 控制placeholder的样式 */
.search input::placeholder {
    font-size: 14px;
    color: #bfbfbf;
}

.search button {
    float: left;
    width: 50px;
    height: 38px;
    background-image: url(../images/btn.png);
    border: 0;
}

.user {
    float: right;
    margin-right: 35px;
    height: 42px;
    line-height: 42px;
}

.user img {
    /* 调节图片垂直对齐方式, middle:居中 */
    vertical-align: middle;
}

4、结果如下:

posted @ 2022-12-06 10:09  a-tao必须奥利给  阅读(84)  评论(0编辑  收藏  举报