一,什么是CSS?

Cascading Style Sheets层叠样式表

 
 
 
 
 
层叠:就是层层覆盖叠加,如果有多种样式对同一html标签进行修饰,样式有冲突的部分应用优先级高,不冲突的部分共同作用
样式表:就是css属性样式的集合
 
  • CSS的作用

     
     
     
     
     
    1. 对html页面进行美化和修饰
    2. 将html的内容和样式进行了分离,让文档看起来更清晰
    3. 提高代码复用性
     

    1. CSS的选择器(三种)

    一,基本选择器(三种)

    1.ID选择器

     
     
     
     
     
    (1)id选择器    id唯一性
                语法:#id的值{css属性}
                  #ID{
                        属性名称:属性的值
                     }
                示例:
                    <div id="div1">hello css1!!!</div>
                    <div id="div2">hello css2!!!</div>
                    <style type="text/css">
                        #div1{background-color: red;}
                        #div2{background-color: pink;}
                    </style>
     

    2.类选择器

     
     
     
     
     
    (2)class选择器
                语法:.class的值{css属性}
                  格式:
                      .类名{
                          属性名称:属性的值
                      }
                示例:
                    <div class="style1">div1</div>
                    <div class="style1">div2</div>
                    <div class="style2">div3</div>
                    <style type="text/css">
                        .style1{background-color: red}
                        .style2{background-color: pink}
                    </style>
     

    3.元素选择器

     
     
     
     
     
    (3)元素选择器
                语法:html标签名{css属性}
                  格式:
                    元素(标签名称){
                         属性名称:属性的值
                    }
                示例:
                    <span>hello css!!!</span>
                    <style type="text/css">
                        span{color:red;font-size:100px; }
                    </style>
     
二,属性选择器
 
 
 
 
 
语法:基本选择器[属性=‘属性值’]{css属性}
        示例:
            <form action="">
                name:<input type="text" /><br/>
                pass:<input type="password" /><br/>
            </form>
            <style type="text/css">
                input[type='text']{ overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; border-radius: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; border-right-style: none; width: inherit; padding: 0px 4px; background: transparent;">                input[type='password']{ overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; border-radius: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; border-right-style: none; width: inherit; padding: 0px 4px; background: transparent;">            </style>
 
三,伪元素选择器
 
 
 
 
 
a标签的伪元素选择器
            语法:
                静止状态    a:link{css属性}
                悬浮状态    a:hover{css属性}
                触发状态    a:active{css属性}
                完成状态    a:visited{css属性}
            示例:
                <a href="#">点击我吧</a>
                <style type="text/css">
                    a:link{color:blue}
                    a:hover{color:red}
                    a:active{color:yellow}
                    a:visited{color:green}
                </style>
 
四,层级选择器
 
 
 
 
 
语法:父级选择器 子级选择器 .....
        示例:
            <div id="d1">
                <div class="dd1">
                    <span>span1-1</span>
                </div>
                <div class="dd2">
                    <span>span1-2</span>
                </div>
            </div>
            <div id="d2">
                <div class="dd1">
                    <span>span1-1</span>
                </div>
                <div class="dd2">
                    <span>span1-2</span>
                </div>
            </div>

            <style type="text/css">
                #d1 .dd2 span{color:red}
            </style>
 

2. CSS的引入方式(三种)

1.行内样式

 
 
 
 
 
内嵌样式是把css的代码嵌入到html标签中
            <div style="color:red;font-size: 100px;">你好啊 小朋友</div>
            语法:
                (1)使用style属性将样式嵌入到html标签中
                (2)属性的写法:属性:属性值
                (3)多个属性之间使用分号;隔开
            不建议使用
 

2.内部样式

 
 
 
 
 
 在head标签中使用style标签进行css的引入
            <style type="text/css">
                div{color:red;font-size: 100px;}
            </style>
            语法:
                (1)使用style标签进行css的引入
                    <style type="text/css">
                        属性:type:告知浏览器使用css解析器去解析
                (2)属性的写法:属性:属性值
                (3)多个属性之间使用分号;隔开
 

3.外部样式

 
 
 
 
 
将css样式抽取成一个单独css文件 谁去使用谁就引用
            <link rel="stylesheet" type="text/css" href="demo1.css"/>
            语法:
                (1)创建css文件 将css属性写在css文件中
                (2)在head中使用link标签进行引入
                    <link rel="stylesheet" type="text/css" href="css文件地址"/>
                    rel:代表要引入的文件与html的关系
                    type:告知浏览器使用css解析器去解析
                    href:css文件地址
                (3)属性的写法:属性:属性值
                (4)多个属性之间使用分号;隔开
 

优先级:ID选择器>类选择器>元素选择器

三,css属性

  • 文字属性

     
     
     
     
     
    font-size:大小
    font-family:字体类型
     
  • 文本属性

     
     
     
     
     
    color:颜色
            text-decoration:下划线
                属性值:none(去除下划线) underline
            text-align:对齐方式
                属性值:left  center  right
                <div>hello css!!!</div>
                <a href="#">click me!!!</a>
                <style type="text/css">
                    div{color:red;text-decoration: underline;text-align: right }
                    a{text-decoration: none;}
                </style>
     
  • 背景属性

     
     
     
     
     
    background-image:背景图片
                属性值:url("图片地址");
            background-repeat:平铺方式
                属性值:默认横向纵向平铺
                        repeat:横向纵向平铺
                        no-repeat:不平铺
                        repeat-y:纵向
                        repeat-x:横向
    
    
            body{
    
    
                background-image: url("images/dog.gif");
                background-repeat: repeat-y;
            }
     
  • 列表属性

     
     
     
     
     
    list-style-type:列表项前的小标志
                属性值:太多了
            list-style-image:列表项前的小图片
                属性值:url("图片地址");
    
    
                <ul>
                    <li>辣椒酱</li>
                    <li>胡萝卜</li>
                    <li>大白菜</li>
                    <li>番茄</li>
                </ul>
                <style type="text/css">
                    /* ul{list-style-type: decimal-leading-zero;} */
                    ul{list-style-image: url("images/forward.gif");}
                </style>
     

  • 尺寸属性

     
     
     
     
     
    width:宽度
            height:高度
                <div id="d1">div1</div>
                <div id="d2">div2</div>
                <style type="text/css">
                    #d1{background-color: red;width: 200px;height: 200px;}
                    #d2{background-color: pink;width: 200px;height: 200px;}
                </style>
     

  • 显示属性

     
     
     
     
     
    display:
                属性值:none:隐藏
                        block:块级显示
                        inline:行级显示
    
    
                <form action="">
                    name:<input id="name" type="text" /><span id="span">对不起 输入不符合要求</span>
                    <br>
                    pass:<input id="pass" type="password" />
                    <br>
                    <input id="btn" type="button" value="button" />
                </form>
                <style type="text/css">
                    span{color:red;display: none}
                </style>
                <script type="text/javascript">
                    document.getElementById("btn").onclick = function(){
                        document.getElementById("span").style.display = "inline";
                    };
                </script>
     

  • 浮动属性(float)

     
     
     
     
     
        <div style="width:400px;height: 400px;border: 1px solid red;">
                <div style="width: 100px;float: left; height: 100px;border: 1px solid blue;"></div>
                <div style="clear: both;"></div>
                <div style="width: 110px;height: 100px;border: 1px solid yellow;"></div>
                <div style="width: 120px;height: 100px;border: 1px solid green;"></div>
            </div>
    float:
                属性值:left  right
                        clear:清除浮动 left right both
                缺点: (1)影响相邻元素不能正常显示
                        (2)影响父元素不能正常显示
      text-decoration-none去掉下划线
     

四,盒子模型

 
 
 
 
 
border:
        border-width:边框的宽度
        border-color:边框的颜色
        border-style:边框的线型

        border-top:上边框
        border-bottom:下边框
        border-left:左边框
        border-right:右边框

    padding:
        代表边框内壁与内部元素之间的距离
        padding:10px;代表上下左右都是10px
        padding:1px 2px 3px 4px;上右下左
        padding:1px 2px;上下/左右
        padding:1px 2px 3px;
        padding-top:单独设置
    margin:
        代表边框外壁与其他元素之间的距离
        margin:10px;代表上下左右都是10px
        margin:1px 2px 3px 4px;上右下左
        margin:1px 2px;上下/左右
        margin:1px 2px 3px;
        margin-top:单独设置

带你玩转JavaWeb开发之三 - CSS从基础到实战的更多相关文章

  1. 带你玩转JavaWeb开发之三 -JS插件实战开发

    前提:需要掌握的知识点           填写HTML代码 Element元素中有一个innerHTML属性,这个属性可以填写一段html代码 innerHTML = "<font ...

  2. 带你玩转JavaWeb开发之五-如何完成响应式开发页面

    响应式页面开发 使用BootStrap开发一个响应式的页面出来 响应式开发就是同一个页面在PC端与手机端Pad端显示不同的效果,以给用户更好的体验 需求分析 开发一套页面,让用户能够在PC端, Pad ...

  3. 带你玩转JavaWeb开发之四 -如何用JS做登录注册页面校验

    今日内容 使用JQuery完成页面定时弹出广告 使用JQuery完成表格的隔行换色 使用JQuery完成复选框的全选效果 使用JQuery完成省市联动效果 使用JQuery完成下列列表左右选择 使用J ...

  4. 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(4)

    按照分类的名称统计每个分类商品所花的总钱数[排序查询] SQL中对查询的列进行排序,使用关键字order by.默认情况下是升序的排序(从小到大的排序顺序关键字 asc).使用降序排序需要使用关键字d ...

  5. 带你玩转JavaWeb开发之一 - HTML快速入门

    一,html简介 1,html是什么 Html是用来描述网页的一种语言. (1)HTML 指的是超文本标记语言 (Hyper Text Markup Language) (2)HTML 不是一种编程语 ...

  6. 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(3)

    [语法] update 表名 set 列名=列值,列名=列值 -[条件]; [注意事项] * 修改的列的值需要与列的类型一致. * 修改的列的值的长度不能超过列的类型的最大长度. * 字符串类型和日期 ...

  7. 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(2)

    1.1.1    对数据库中表的记录进行操作(*****) 1.1.1.1   对数据库中表记录插入操作 [语法] 向数据库表中插入某些列:insert into 表名 (列名1,列名2,列名3-) ...

  8. 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(1)

    1.1.1    对数据库的表进行操作 1.1.1.1   对数据库中表进行创建 [语法:] create table 表名( 列名 列类型 [列约束], 列名 列类型 [列约束], 列名 列类型 [ ...

  9. JavaWEB开发02——CSS&JS

    今日目标 使用CSS完成网站首页的优化 使用CSS完成网站注册页面的优化 使用JS完成简单的数据校验 使用JS完成图片轮播效果 教学目标: 了解CSS的概念 了解CSS的引入方式 了解CSS的基本用法 ...

随机推荐

  1. Python学习笔记04

    语句之后有冒号,表示有一个语句块,且以四个空格的缩进来表示隶属关系. 与C# 相比,没有了{},没有了(),被冒号和缩进取代了 if,while,for,range,continue,break if ...

  2. git的合并与推送

    集中式合作模式 1.git fetch 获取远程更新 2.git merge origin/master 进行合并,如果报错,则相应解决.注:你得用git bash命令行执行才能看见报错详情,用ecl ...

  3. django 后台管理

    修改 admin.py from myapp.models import * from django.contrib import admin # Register your models here. ...

  4. ccc array

    setInterval可以用来设置函数的执行频率 nodeList: { default:[], type:[cc.Node] } active 可以用来设置是否启用 cc.Class({ exten ...

  5. ACM 无线网络覆盖

    无线网络覆盖 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们的乐乐同学对于网络可算得上是情有独钟,他有一个计划,那就是用无线网覆盖郑州大学. 现在学校给了他一个 ...

  6. ios编译ASIHTTPRequest时出现 'libxml/HTMLparser.h' file not found in ASIHTTPRequest

    解决方法是添加libxml2.dylib 然后在Build Settings 中的 Header Search Paths 添加: ${SDK_DIR}/usr/include/libxml2

  7. Codeforces Round #215 (Div. 2) C. Sereja and Algorithm

    #include <iostream> #include <vector> #include <algorithm> #include <string> ...

  8. [Leetcode|SQL] Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  9. Code[VS]1690 开关灯 题解

    Code[VS]1690 开关灯 题解     时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description:     YYX家门前 ...

  10. 通过data:image/png;base64把图片直接写在src里

    从网上下了个源文件查看时候发现了引用图片的地址不是在本地上的,而是后面跟了一大串字符data:image/png;base64...查了一下资料分析如下: 关于用base64存储图片 网页上有些图片的 ...