zoukankan      html  css  js  c++  java
  • CSS

    • 用于页面美化和布局控制

    概述

    1. 概念:Cascading Style Sheets 层叠样式表
      • 层叠:多个样式可以作用在同一个html元素上,同时生效
    2. 好处:
      1. 功能强大
      2. 将内容展示和样式控制分离
        • 降低耦合度。解耦
        • 让分工协作更容易
        • 提高开发效率

    CSS的使用

    • CSS与HTML的结合方式
    1. 内联样式

      • 在标签内使用 style属性指定css代码
      • 如:不推荐使用
      <!-- body标签内 -->
      <div style="color: red;">hello css</div>
      
    2. 内部样式

      • 在head标签内,定义style标签,style标签的标签体内容就是css代码
      • 如:
      <!-- head标签内 -->
      <style>
      div{
              color: blue;
          }
      </style>
      <!-- body标签内 -->
      <div>hello css</div>
      
    3. 外部样式

      1. 定义css资源文件
      2. 在head标签内,定义link标签,引入外部的资源文件
      <!-- 外部css资源文件 -->
      div{
      color:green;
      }
      <!-- 分隔 -->
      <link rel="stylesheet" href="css/a.css">
      <div>hello css</div>
      <div>hello css</div>
      

    注意事项:

    • 第1、2、3种方式,css作用的范围越来越大
    • 第1种方式不常用,后期常用2、3种方式
    • 第3种方式还可以写为:

    CSS语法

    • 格式:
      选择器{
          属性名1:属性值1;
          属性名2:属性值2;
          ...
      }
      
    • 选择器:筛选具有相似特征的元素。
    • 注意:每一对属性需要使用;隔开,最后一对属性可以不加;

    选择器

    基础选择器

    1. id选择器:选择具有相同 id属性值 的元素,建议在一个html页面中id值唯一
      • 语法:#id属性值
    2. 元素选择器:选择具有相同标签名称的元素
      • 语法:标签名称{}
    3. 类选择器:选择具有相同 class属性值 的元素
      • 语法:.class属性值{}
        注意:
        优先级:id选择器 > 类选择器 > 元素选择器
    • 示例:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>基础选择器</title>
    	<style>
    		#div1{
    			color: red;
    		}
    		div{
    			color: blue;
    		}
    		.cls1{
    			color: green;
    		}
    	</style>
    </head>
    <body>
    	<div id="div1">我爱学习 java</div>
    	<div>你好,世界!</div>
    	<div class="cls1">Hello World!</div>
    </body>
    </html>
    

    扩展选择器

    1. 选择所有元素
      • 语法:*{}
    2. 并集选择器
      • 语法:选择器1,选择器2 {}
    3. 子选择器:筛选选择器1元素下的选择器2的元素
      • 语法:选择器1 选择器2 {}
    4. 父选择器:筛选选择器2的父元素的选择器1
      • 语法:选择器1 > 选择器2 {}
    5. 属性选择器:选择元素名称,属性名=属性值的元素
      • 语法:元素名称[属性名="属性值"]
    6. 伪类选择器:选择一些元素具有的状态
      • 语法:元素:状态 {}
      • 如:<a>
        • 状态:
          • link:初始化状态
          • hover:鼠标悬浮状态
          • active:正在访问状态
          • visited:被访问过的状态
    • 示例:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>扩展选择器</title>
        <style>
            <!-- 子选择器 -->
            div p {
                color: red;
            }
            <!-- 父选择器 -->
            div > p {
                border: 1px solid;
            }
            <!-- 属性选择器 -->
            input[type="text"] {
                border: 5px solid;
            }
    		<!-- 伪类选择器 -->
            a:link {
                color: pink;
            }
            a:hover {
                color: green;
            }
            a:active {
                color: yellow;
            }
            a:visited {
                color: red;
            }
        </style>
    </head>
    <body>
        <div>
            <p>我是一个段落</p>
        </div>
        <p>这是另一个段落</p>
        <input type="text">
        <input type="password">
        <br>
        <a href="#">储备库</a>
    </body>
    </html>
    

    属性

    1. 字体、文本
      • font-size:字体大小
      • color:文本颜色
      • text-align:对齐方式
      • line-height:行高
    2. 背景
      • background:设置背景色,复合属性
    3. 边框
      • border:设置边框,复合属性
    4. 尺寸
      • width:宽度
      • height:高度
    • 示例:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>CSS属性</title>
    	<style>
    		p {
    			color: #FF0000;
    			font-size: 30px;
    			text-align: center;
    			line-height: 100px;
    			/*
    				border边框
    			 */
    			border: 1px solid red;
    		}
    		div {
    			border: 1px solid red;
    			/*
    				尺寸
    			 */
    			 200px;
    			height: 200px;
    			/*
    				背景
    			 */
    			background: url("img/touxiang1.jpeg");
    	}
    	</style>
    </head>
    <body>
    
    <p>好好学习 天天向上</p>
    
    <div></div>
    </body>
    </html>
    
    1. 盒子模型:控制布局
    • margin:外边距

    • padding:内边距

      • 默认情况下内边距会影响整个盒子的大小
      • box-sizing: border-box; 设置盒子的属性,让width和height就是最终盒子的大小。
    • float:浮动

      • left
      • right
    • 示例:

      <!DOCTYPE html>
      <html lang="en">
      <head>
          <meta charset="UTF-8">
          <title>CSS属性盒子模型</title>
          <style>
              div {
                  border: 1px solid red;
                   100px;
              }
              .div1 {
                   100px;
                  height: 100px;
                  /*外边距*/
                  /*margin: 50px;*/
              }
              .div2 {
                   200px;
                  height: 200px;
                  /*内边距*/
                  padding: 50px;
                  /*
                      设置盒子的属性,让 width 和 height 就是最终盒子的大小
                   */
                  box-sizing: border-box;
              }
              .div3 {
                  float: left;
              }
      
              .div4 {
                  float: left;
              }
      
              .div5 {
                  float: right;
              }
          </style>
      </head>
      <body>
      
          <div class="div2">
              <div class="div1"></div>
          </div>
          <div class="div3">aaaaaa</div>
          <div class="div4">bbbbbb</div>
          <div class="div5">cccccc</div>
      
      </body>
      </html>
      

    案例:注册页面(css)

    • 效果图:

    注册页面(css)

    • 代码实现:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>注册页面</title>
        <style>
            * {
                margin: 0px;
                padding: 0px;
                box-sizing: border-box;
            }
    
            body {
                background: url("img/register_bg.jpg") no-repeat center;
            }
    
            .rg_layout {
                 900px;
                height: 500px;
                border: 8px solid #EEEEEE;
                background-color: white;
                /*让div水平居中*/
                margin: auto;
                margin-top: 15px;
            }
    
            .rg_left {
                /*border: 1px solid red;*/
                float: left;
                margin: 15px;
            }
    
            .rg_left > p:first-child {
                color: #FFD026;
                font-size: 20px;
            }
    
            .rg_left > p:last-child {
                color: #A6A6A6;
                font-size: 20px;
            }
    
            .rg_center {
                /*border: 1px solid red;*/
                float: left;
    
                 450px;
            }
    
            .rg_right {
                /*border: 1px solid red;*/
                float: right;
                margin: 15px;
            }
    
            .rg_right > p:first-child {
                font-size: 15px;
            }
    
            .rg_right p a {
                color: pink;
            }
    
            .td_left {
                 100px;
                text-align: right;
                height: 45px;
            }
    
            .td_right {
                padding-left: 40px;
            }
    
            #username, #password, #checkcode, #birthday, #tel, #name, #email {
                 251px;
                height: 32px;
                border: 1px solid #A6A6A6;
                /*设置边框圆角*/
                border-radius: 5px;
                padding-left: 10px;
            }
    
            #checkcode {
                 110px;
            }
    
            #img_check {
                height: 32px;
                /*垂直居中*/
                vertical-align: middle;
            }
    
            #btn_sub {
                 150px;
                height: 40px;
                background-color: #FFD026;
                border: 1px solid #FFD026;
            }
    
        </style>
    </head>
    <body>
    <div class="rg_layout">
        <div class="rg_left">
            <p>新用户注册</p>
            <p>USER REGISTER</p>
        </div>
        <div class="rg_center">
            <div class="rg_form">
                <!--定义表单-->
                <form action="#" method="post">
                    <table>
                        <tr>
                            <td class="td_left"><label for="username">用户名</label></td>
                            <td class="td_right"><input type="text" name="username" id="username" placeholder="请输入用户名"></td>
                        </tr>
    
                        <tr>
                            <td class="td_left"><label for="password">密码</label></td>
                            <td class="td_right"><input type="password" name="password" id="password" placeholder="请输入密码">
                            </td>
                        </tr>
    
                        <tr>
                            <td class="td_left"><label for="email">Email</label></td>
                            <td class="td_right"><input type="email" name="email" id="email" placeholder="请输入Email"></td>
                        </tr>
    
                        <tr>
                            <td class="td_left"><label for="name">姓名</label></td>
                            <td class="td_right"><input type="text" name="name" id="name" placeholder="请输入真实姓名"></td>
                        </tr>
    
                        <tr>
                            <td class="td_left"><label for="tel">手机号</label></td>
                            <td class="td_right"><input type="text" name="tel" id="tel" placeholder="请输入您的手机号"></td>
                        </tr>
    
                        <tr>
                            <td class="td_left">性别</td>
                            <td class="td_right"><input type="radio" name="gender" value="male" checked>男
                                <input type="radio" name="gender" value="female">女
                            </td>
                        </tr>
    
                        <tr>
                            <td class="td_left"><label for="birthday">出生日期</label></td>
                            <td class="td_right"><input type="date" name="birthday" id="birthday"></td>
                        </tr>
    
                        <tr>
                            <td class="td_left"><label for="checkcode">验证码</label></td>
                            <td class="td_right"><input type="text" id="checkcode" placeholder="请输入验证码">
                                <img id="img_check" src="./img/verify_code.jpg" width="100">
                            </td>
                        </tr>
    
                        <tr>
                            <td colspan="2" align="center"><input id="btn_sub" type="submit" value="注册"></td>
                        </tr>
    
                    </table>
    
                </form>
    
            </div>
        </div>
        <div class="rg_right">
            <p>已用账号?<a href="#">立即登录</a></p>
        </div>
    
    </div>
    
    </body>
    </html>
    
  • 相关阅读:
    10.cocos2dx C++为Sprite添加触摸事件监听器
    9.多彩的幕布layer
    8.ZOrder
    7.cocos精灵创建和绘制
    6.cocos2d设置定时器
    5.cocos2d锚点
    4.cocos场景和层的调用
    文件导入导出
    两个整数相乘是否超限
    倒置字符串函数reverse
  • 原文地址:https://www.cnblogs.com/rainszj/p/12188898.html
Copyright © 2011-2022 走看看