黑马程序员技术交流社区

标题: CSS总结 ∩_∩ [打印本页]

作者: 陈彬磊    时间: 2019-6-1 15:06
标题: CSS总结 ∩_∩
一.CSS引入方式
1.CSS简介:
(1)CSS(Cascading style Sheets):层叠样式表。用来给html网页设置样式;
(2)当多个选择器对同一个元素进行样式设计时,则该元素的样式为多个选择器叠加的效果(当有冲突时,按照优先级设置);
2.引入方式:
(1)方式一:行内样式(在html元素的style属性上设置样式)

(2)方式二:页面内嵌样式(在head标签内部嵌入样式)

(3)方式三:引入外部样式文件
[Java] 纯文本查看 复制代码
例1(演示CSS三种引入方式):
Html代码:[mw_shl_code=java,true]CSS代码:

#haha{
    width: 300px;
    height: 300px;
    background-color: blue;
}
[Java] 纯文本查看 复制代码
(选择器的使用):
下拉  代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #daohang{
                width: 100%;
                height: 73px;
                border: 0px solid #EAEAEA;
            }
            #logo1{
                width: 332px;
                height: 72px;
                border: 0px solid #EAEAEA;
                float: left;
            }
            #logotu{
                width: 180px;
                height: 37px;
                margin-left: 78px;
                margin-top: 16px;
                background-image: url(一键杀毒_盗号保护_垃圾清理_软件管理-腾讯电脑管家官网_files/logo_2.png);
                background-repeat: no-repeat;
                background-size: 100% 100%;
            }
            #shouye{
                height: 72px;
                border: 0.25px solid #EAEAEA;
                float: left;
                width:70px ;
                font-family: "微软雅黑";
                font-size: 20px;
                text-align: center;
                line-height: 72px;
                color: #9D9D9D;
                border-top-style:none ;
                border-right-style:none ;
            }
            .dropdown {
                width: 121px;
                height: 72px;
                border: 0.25px solid #EAEAEA;
                float: left;
                position: relative;
                display: inline-block;
                text-align: center;
                line-height: 72px;
                border-top-style:none ;
                border-right-style:none ;
            }
            .dropdown-content{
                display: none;
                position: absolute;
                background-color: #FFFFFF;
                width: 120px;
                line-height: 27px;
                z-index: 1;
            }
            .dropdown:hover .dropdown-content {
                display: block;
            }
            .banben{
                width: 70px;
                height: 72px;
                float: left;
            }
            #login{
                width: 80px;
                height: 60px;
                float: left;
                margin-left: 60px;
                margin-top: 7px;
            }
            a{
                text-decoration: none;
                font-size: 17px;
                color: #333333;
                font-family: "微软雅黑";
                font-size: 20px;
            }
            a:hover{
                color: #2871D5;
            }
            #xialaxiang{
                font-size: 14px;
            }
            #tu{
                width: 50px;
                height: 50px;
                margin-left: 10px;
                margin-top: 10px;
                background: url(一键杀毒_盗号保护_垃圾清理_软件管理-腾讯电脑管家官网_files/09ec6123b95bae5a3d11c507bc84910e.png);%
                background-repeat: no-repeat;
                background-size: 100% 100%;
            }
            #maintu{
                width: 100%;
                height: 442px;
                background: url(一键杀毒_盗号保护_垃圾清理_软件管理-腾讯电脑管家官网_files/9fc5cc01281fdf183798ea0239533980.jpg);   
                background-repeat: no-repeat;
                background-size: 100% 100%;         
            }
        </style>
    </head>
    <body>
        <div id="daohang">
            <div id="logo1">
                <div id="logotu"></div>
            </div>
            <div id="shouye" ><a href="index.html" style="text-decoration: none;">首页</a></div>
            <div class="dropdown">
                <span class="dropbtn"style="line-height: 70px;"><a href="#" target="_blank">产品介绍</a></span>
                <div class="dropdown-content">
                    <a href="#" id="xialaxiang">安全防护</a><br />
                    <a href="#" id="xialaxiang">管理效率</a><br />
                    <a href="#" id="xialaxiang">电脑加速</a><br />
                    <a href="#" id="xialaxiang">游戏加速</a><br />
                    <a href="#" id="xialaxiang">等级加速</a><br />
                    <a href="#" id="xialaxiang">电脑加速</a><br />
                    <a href="#" id="xialaxiang">账号保护</a><br />
                    <a href="#" id="xialaxiang">手游助手</a><br />
                    <a href="#" id="xialaxiang">桌面管理</a><br />
                    <a href="#" id="xialaxiang">最近文档</a><br />
                </div>
            </div>
            <div class="dropdown">
                <span class="dropbtn"style="line-height: 70px;"><a href="#" target="_blank">安全咨询</a></span>
                <div class="dropdown-content">
                    <a href="#" id="xialaxiang">安全专题</a><br />
                    <a href="#" id="xialaxiang">管家大事记</a><br />
                    <a href="#" id="xialaxiang">联合实验室</a><br />
                </div>
            </div>
            <div class="dropdown">
                <span class="dropbtn"style="line-height: 70px;"><a href="#" target="_blank">在线安全</a></span>
                <div class="dropdown-content">
                    <a href="#" id="xialaxiang">电脑诊所</a><br />
                    <a href="#" id="xialaxiang">申诉举报</a><br />
                    <a href="#" id="xialaxiang">诈骗信息查询</a><br />
                    <a href="#" id="xialaxiang">网站安全检测</a><br />
                    <a href="#" id="xialaxiang">密码安全检测</a><br />
                    <a href="#" id="xialaxiang">账号安全查询</a><br />
                </div>
            </div>
            <div class="dropdown" style="border-right:0.25px solid #EAEAEA">
                <span class="dropbtn"style="line-height: 70px;"><a href="#" target="_blank">活动中心</a></span>
                <div class="dropdown-content">
                    <a href="#" id="xialaxiang">兑换礼包</a><br />
                    <a href="#" id="xialaxiang">赚安全金币</a><br />
                    <a href="#" id="xialaxiang">专题活动</a><br />
                </div>
            </div>
            <div class="banben" style="margin-left: 50px;"><div id="tu"></div></div>
            <div class="banben"><div id="tu"></div></div>
            <div class="banben"><div id="tu"></div></div>
            <div id="login" style="line-height: 60px; text-align: center;"><a href="ligin.html" target="_blank" style="font-size: 15px;color: #2771FA;">登录</a></div>
            <div style="clear: both;">
                <!--清除上面的浮动-->
            </div>
            <div id="maintu">

            </div>
        </div>
    </body>
</html>


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>CSS引入</title>
        <!--方式二:页面内嵌样式-->
        <style type="text/css">
            #hehe{
                width: 200px;
                height: 200px;
                background-color: yellow;
            }
        </style>
        <!--方式三:引入外部样式文件-->
        <link rel="stylesheet" type="text/css" href="css/index.css"/>
    </head>
    <body>
        <!--方式一:行内样式:-->
        <div style="background-color: green; width: 400px;height: 400px;">
            <div id="haha">
                <div id="hehe">
                    <div style="background-color: red; width: 120px;height: 120px;"></div>
                </div>
            </div>
        </div>
    </body>
</html>[/mw_shl_code]




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2