html+css学习第四节

一、relative的相对定位

1.position特性

css posiition 属性用于指定一个元素在文档中的定位方式。top、right、bottom、left属性则决定了该元素的最终位置。

2.position取值

static(默认)
relative
absolute
fixed
sticky

3.relative相对定位

1.如果没有定位偏量,对元素本身没有任何影响
2.不使元素脱离文档流
3.不影响其他元素布局
4.left top right bottom 是相当于当前元素自身进行偏移的

 <style>
    #box1{width: 100px;height: 100px;background: red;}
    #box2{width: 100px;height: 100px;background: blue;position: relative;left: 100px;top: 100px;}
    #box3{width: 100px;height: 100px;background:yellow;}
    </style>

网页显示

4.absolute绝对定位

使元素完全脱离文档流
使内联元素支持宽高(让内联具备块特性)
使块元素默认宽根据内容决定(让块具备内联的特性)
如果有定位祖先元素相对于定位祖先元素发生偏移,没有定位祖先元素相对于整个文档发生偏移(绝对、相对、固定)

#box1{width: 100px;height: 100px;background: red;position: absolute;}
    #box2{width: 200px;height: 200px;background: blue;}

网页显示

span{position: absolute;height: 100px;width: 100px;background: red;}
    div{position: absolute;background:red ;}

网页显示

#box1{width: 300px;height: 300px;border: 1px black solid;margin: 200px;}
    #box2{width: 100px;height: 100px ;background: red;position: absolute;left: 0;top: 0;}

网页显示

#box1{width: 300px;height: 300px;border: 1px black solid;margin: 200px;position: absolute;}
    #box2{width: 100px;height: 100px ;background: red;position: absolute;left: 0;top: 0;}

网页显示

5.fixed固定定位

1.使元素脱离文档流
2.使内联元素支持宽高(让内联具备块特性)
3.使块元素默认宽根据内容决定(让块具备内联的特性)
4.相对于整个浏览器窗口进行偏移,不受浏览器滚动条的影响

 body{height: 2000px;}
    #box1{width: 300px;height: 300px;border: 1px black solid;margin: 200px;position: relative;}
    #box2{width: 100px;height: 100px ;background: red;position: fixed;left: 0;top: 0;} 

网页显示

6.sticky黏性定位

在指定的位置,进行黏性操作。

 body{height: 2000px;}
    div{background: red;position: sticky;top: 0;}

网页显示

7.z-index定位层级

1.默认层级为0

#box1{width: 100px;height: 100px;background: red;position:absolute ;z-index: 1;}
    #box2{width: 100px;height: 100px;background: blue;position:absolute ;left: 50px;top: 50px;z-index: 2;}

网页显示

2.嵌套时候的层级问题

#parent{width: 100px;height: 100px;border: 1px black solid;position: absolute;z-index: -2;}
    #box1{width: 100px;height: 100px;background: red;position:absolute ;z-index: 0;}
    #box2{width: 100px;height: 100px;background: blue;position:absolute ;left: 50px;top: 50px;z-index: -1;}

网页显示

二、css添加省略号

1.width
必须有一个固定的宽

<style>
     #content{border: 1px black solid;width: 200px;}   
    </style>

2.white-space:nowrap
不让内容折行
网页显示

3.overflow:hidden
隐藏溢出的内容
网页显示

4.text-overflow:ellipsis
添加省略号
网页显示

三、CSS Sprite

特性:CSS雪碧也叫做CSS精灵,是一种网页图片应用处理的方式。它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去加载。
好处:1.可以减少图片的质量,网页的图片加载速度快
2.减少图片的请求的次数,加快网页的打开

<!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>Document</title>
    <style>
    #box1{width: 20px;height: 20px;background: url(./img/会员身份.png)no-repeat ;}
    #box2{width: 300px;height: 50px;border: 1px black solid;line-height: 50px;padding-left: 30px;background: url(./img/会员身份.png) no-repeat ; }
    </style>
</head>
<body>
    <div id="box1"></div>
    <div id="box2">会员身份</div>
</body>
</html>

网页显示

四、css圆角

border-radius:给标签添加圆角

<!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>Document</title>
    <style>
        #box{width: 200px;height: 200px;background: red;border-radius: 20px;}
    </style>
</head>
<body>
    <div id="box">
    </div>
</body>
</html>

网页显示

  #box{width: 200px;height: 200px;background: red;border-radius: 50%;}

网页显示

 #box{width: 200px;height: 200px;background: red;border-radius: 10px 20px 30px 40px;}

网页显示

 #box{width: 200px;height: 200px;background: red;border-radius: 20px/40px;}

网页显示

五、pc端的布局

1.通栏

自适应浏览器的宽度

2.版心

固定一个宽度,并且让容器居中

练习

1.定位实现下拉菜单

<!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>Document</title>
    <style>
    *{margin: 0;padding: 0;}
    ul{list-style: none;}
    #menu{width: 100px;height: 30px;margin: 20px auto;border: 1px black solid;position: relative;}
    #menu ul{width: 100px;border: 1px black solid;position: absolute;left: -1px;top: 30px;background: white;
    display: none;}
    p{text-align: center ;}
    #menu:hover ul{display: block;}
    #menu ul li:hover{background: gray;}

    </style>
</head>
<body>
    <div id="menu">
        卖家中心
        <ul>
            <li>免费开店</li>
            <li>已卖出的宝贝</li>
            <li>出售中的宝贝</li>
            <li>卖家服务市场</li>
            <li>卖家培训中心</li>
        </ul>
    </div>
    <p>测试段落测试段落测试段落</p>
</body>
</html>

2网页显示

2.定位实现元素居中

<!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>Document</title>
    <style>
    #box1{width: 300px;height: 300px;border: 1px black solid;position: relative;}
    #box2{width: 100px;height: 100px;background: red;position: absolute; left: 50%;top: 50%;margin: -50px 0 0 -50px;}    
    </style>
</head>
<body>
    <div id="box1">
    <div id="box2"></div>    
    </div>
</body>
</html>

网页显示

3.半圆练习

#box{width: 200px;height: 100px;background: red;border-radius: 150px 150px 0 0;}

网页显示

4.企业网页制作练习

<!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>Document</title>
    <link rel="stylesheet" href="./common.css">
    <style>
    #banner{position: relative;}
    #banner .banner_list{width: 100%;height: 469px;position: relative;}
    #banner .banner_list li{width: 100%;height: 100%;background: center 0 no-repeat;position: absolute;left: 0;top: 0;opacity: 0;z-index: 1;}
    #banner .banner_list li.active{opacity: 1;z-index: 10;}
    #banner .banner_list a{display: block;width: 100%;height: 100px;}
    #banner .banner_btn{width: 100%;position: absolute;bottom: 19px; z-index: 20;font-size: 0;text-align: center;}
    #banner .banner_btn li{display: inline-block;width: 12px;height: 12px;border: 2px  solid white;border-radius: 50%; box-sizing: border-box;margin: 0 6px;cursor: pointer; } 
    #banner .banner_btn li.active{background:white ;}

    #service{overflow: hidden;min-height: 407px;}
    #service .service_list{text-align: center;margin-top: 34px;}
    #service .service_list li{float: left;width: 250px;margin: 0 10px;}
    #service .service_list div{width: 102px;height: 102px;margin: 0 auto;}
    #service .service_list li:nth-of-type(1) div{background-image: url(./img/web1.png);}
    #service .service_list li:nth-of-type(2) div{background-image: url(./img/graphic1.png);}
    #service .service_list li:nth-of-type(3) div{background-image: url(./img/e-bussiness1.png);}
    #service .service_list li:nth-of-type(4) div{background-image: url(./img/mail1.png);}
    #service .service_list h3{font-size: 18px;color: #434343;line-height: 36px;margin-top: 25px;}
    #service .service_list p{font-size: 14px;color: #6D6D6D;line-height: 22px;}

    #case{background: #f8f8f8;}
   /*  #case .container{min-height: 460px;overflow: hidden;} */
    #case .area_title{margin-top: 55px;}
    #case .area_title  h2{color: #66C5B4;}
    #case .case_list{margin-top: 28px;}
    #case .case_list li{float: left;width: 340px;margin:0 10px;}
    #case .case_btn{width: 176px;height: 37px;background:#66C5B4 ;margin: 0 auto;border-radius :25px; line-height:37px ;text-align: center;font-size: 14px;margin-top: 36px ;}
    #case .case_btn a{display: block;width: 100%;height: 100%;color: white;} 

    #news{ min-height: 450px;overflow: hidden;}
    #news .area_title{margin-top: 65px;}
    #news dl{margin-top: 48px;}
    #news dt{width: 234px;}
    #news dd{width: 846px;}
    #news .news_list{width:100%;}
    #news .news_list li{width:50%;float: left;}
    #news .news_date{width: 71px;height: 70px; border-right: 1px solid #DCDCDC;text-align: center;}
    #news .news_date i{color: #66C5B4;font-size: 39px;display: block;font-weight: bold;}
    #news .news_date span{color: #999999;font-size: 20px;line-height: 36px;}
    #news .news_text{width: 310px;margin-left: 20px;}
    #news .news_text h3{font-size: 14px;}
    #news .news_text h3 a{color: #3F3F3F;}
    #news .news_text p{color: #A4A4A4;font-size: 12px; line-height: 21px;margin-top: 17px ;margin-bottom: 30px;}

    
    </style>
</head>
<body>
    <div id="head" class="container">
        <div class="head_logo l">
            <a href="#">
                <img src="./img/logo.png" alt="博文尚美" title="博文尚美">
            </a>
        </div>
        <ul class="head_menu r">
       <li>
        <a href="#">HOME</a>
       </li>
       <li>
        <a href="#">ABOUT</a>
       </li>
       <li>
        <a href="#"> PROTFOLIO </a>
       </li>
       <li>
        <a href="#">SERVICE </a>
       </li>
       <li>
        <a href="#"> NEWS </a>
       </li>
       <li>
        <a href="#"> CONTACT</a>
       </li>
        </ul>
    </div>
    <div id="banner" class="container_fiuid">
        <ul class="banner_list">
            <li class="active" style="background-image:url(./img/banner.png);">
                <a href="#"></a>
            </li>
            <li style="background-image:url(./img/banner.png);">
                <a href="#"></a>
            </li>
            <li style="background-image:url(./img/banner.png);">
                <a href="#"></a>
            </li>
            <li style="background-image:url(./img/banner.png);">
                <a href="#"></a>
            </li>

        </ul>
        <ol class="banner_btn">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li> 
        </ol>
    </div>
    <div id="service" class="container">
        <div class="area_title">
            <h2>服务范围</h2>
            <p>OUR SERVICES</p>
        </div>
        <ul class="service_list">
            <li>
                <div></div>
                <h3>1.WEB DESIGN</h3>
                <p>
                    企业品牌网站设计/手机网站制作
                    <br>
                    动画网站创意设计
                </p>
            </li>
            <li>
                <div></div>
                <h3>2.GRAPHIC DESIGN</h3>
                <p>
                    标志LOGO设计/产品宣传册设计
                    <br>
                    企业广告/海报设计
                </p>
            </li>
            <li>
                <div></div>
                <h3>3.E-BUSINESS PLAN</h3>
                <p>
                    淘宝/天猫装修设计及运营推广
                    <br>
                    企业微博、微信营销</p>
            </li>
            <li>
                <div></div>
                <h3>4.MAILBOXAGENTS</h3>
                <p>
                    腾讯/网易企业邮箱品牌代理
                    <br>
                    个性化邮箱定制开发</p>
            </li>
        </ul>
    </div>
    <div id="case" class="container-fluid">
    <div class="container">
        <div class="area_title">
            <h2>{ 客户案例 }</h2>
            <p>With the best professional technology, to design the best innovative web site </p>
        </div>
        <ul class="case_list clear">
            <li>
                <a href="#"><img src="./img/20141121095528549.png" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="./img/20141121095216750.png" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="./img/20141121105856226.png" alt=""></a>
            </li>
        </ul>
        <div class="case_btn">
            <a href="#">VIEW MORE</a>
        </div>
    </div>
    <div id="news" class="container">
        <div class="area_title">
            <h2>最新资讯</h2>
            <p>THE LATEST NEWS</p>
        </div>
        <dl>
            <dt class="l">
                <img src="./img/xs1.png" alt="">
            </dt>
            <dd class="l">
                <ul class="news_list">
                    <li>
                        <div class="news_date l">
                            <i>09</i>
                            <span>Jan</span>
                        </div>
                        <div class="news_text l">
                            <h3><a href="#">网站排名进入前三的技巧说明</a></h3>
                            <p>很多客户都会纳闷为什么自己的网站老是优化不到搜索引擎
                                首页,更不用说进首页前三了。那么网络优化...</p>
                        </div>
                   </li>
                   <li>
                        <div class="news_date l">
                            <i>08</i>
                            <span>Jan</span>
                        </div>
                        <div class="news_text l">
                            <h3><a href="#">
                                flash网站制作的优缺点</a></h3>
                            <p>
                            虽然HTMLS程序语言出现,大有逐渐代替flash网站趋势,但是过于
                            生硬的HTMLS动画效果,始终...</p>
                        </div>
                   </li>
                   <li>
                        <div class="news_date l">
                            <i>07</i>
                            <span>Jan</span>
                        </div>
                        <div class="news_text l">
                            <h3><a href="#">
                                做个网站多少钱</a></h3>
                            <p>
                            "做个网站多少钱?"很多客户打电话过来直接第一句就抛出问题。
                            这好比买辆车多少钱,你是要...</p>
                        </div>
                   </li>
                   <li>
                        <div class="news_date l">
                            <i>06</i>
                            <span>Jan</span>
                        </div>
                        <div class="news_text l">
                            <h3><a href="#">
                                哪些网站优化手法属于网络过度优化</a></h3>
                            <p>
                            大部分人都想让自己的网站,一夜之间出现在搜索独占鳌头。但是
                            事实告诉我们罗马不是...</p>
                        </div>
                   </li>
                </ul>
            </dd>
        </dl>
    </div>
    <div id="foot" class="container-fluid">
        <div class="container">
            <p class="l">Copyright 2006-2014 Bowenshangmei Culture All Rights Reserved</p>
            <div class="r">
                <a href="#">Home</a> | <a href="#">About</a> | <a href="#">Portfolio</a> | <a href="#">Contact</a>
            </div>
        </div>
    </div>
</body>
</html>
*{margin: 0;padding: 0;}
ul,ol{list-style: none;}
img{display: block;}
a{text-decoration: none;color:#646464;}
h1,h2,h3{font-size: 16px;}
body{font-family: Arial;}

.l{float: left;}
.r{float: right;}
.clear::after{content: "";display: block;clear: both;}
.container{width: 1080px;margin: 0 auto;position: relative;}
.container-fluid{width: 100%;}

#head{height: 81px;}
#head .head_logo{width: 162px;height: 44px;margin-top: 19px;}
#head .head_menu{font-size: 14px; line-height: 81px;}
#head .head_menu li{float: left;margin-left: 58px;}

#foot{background:#66c5b4;}
#foot .container{height: 54px;line-height: 54px;font-size: 12px;color: white;}
#foot div a{color: white;margin: 0 10px;}

.area_title{margin-top: 60px;}
.area_title h2{height: 20px;line-height: 20px;font-size: 20px;color: #363636;background:url(./img/title_bg.png) no-repeat center 0 ;font-weight: normal;text-align: center;}
.area_title p{color:#9F9F9F ;font-size: 14px;line-height: 34px;text-align: center;}

网页显示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
HTMLCSS和JavaScript是前端开发中最基础的三种技术,它们分别负责网页的结构、样式和交互。下面是对它们的简单介绍: 1. HTML(超文本标记语言):HTML是一种用于创建网页结构的标记语言。通过使用不同的HTML标签,可以定义网页的标题、段落、链接、图像等内容。HTML是网页的骨架,用于描述页面的结构和语义。 2. CSS(层叠样式表):CSS用于控制网页的样式和布局。通过CSS,可以设置网页的字体、颜色、背景、边框等外观效果,还可以实现响应式布局和动画效果。CSSHTML结合使用,可以使网页更加美观和易于阅读。 3. JavaScript(JS):JavaScript是一种脚本语言,用于实现网页的交互功能。通过JavaScript,可以对用户的操作做出响应,实现表单验证、动态内容加载、页面元素的交互效果等。JavaScript可以与HTMLCSS结合使用,使网页具有更强的交互性和动态性。 学习HTMLCSS和JavaScript可以按照以下步骤进行: 1. 学习HTML基础:了解HTML标签的基本语法和常用标签,学会创建网页的结构和内容。 2. 掌握CSS样式:学习CSS的基本语法和常用属性,掌握如何设置网页的样式和布局。 3. 学习JavaScript编程:了解JavaScript的基本语法和常用功能,学会使用JavaScript实现网页的交互效果。 4. 综合实践:通过实际项目或练习,将HTMLCSS和JavaScript结合起来,实现一个完整的网页或Web应用程序。 在学习过程中,可以参考一些优秀的教程和资源***www.w3schools.com/)等。此外,还可以通过阅读相关书籍、参加在线课程或加入开发社区来提升自己的技能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值