定位层级及表格表单

定位

position属性可以控制Web浏览器如何以 及在何处显示特定的元素。
可以使用position属性把一个元素放置到网 页中的任何位置。可选值:
static
relative
absolute
fixed

相对定位

  1. 每个元素在页面的文档流中都有一个自然位置。相 对于这个位置对元素进行移动就称为相对定位。周 围的 元素完全不受此影响。
  2. 当将position属性设置为relative时,则开启了元素 的相对定位。
  3. 当开启了相对定位以后,可以使用top、right、 bottom、left四个属性对元素进行定位

特点

  • 如果不设置元素的偏移量,元素位置不会发生改变。
  • 相对定位不会使元素脱离文本流。元素在文本流中 的位置不会改变。
  • 相对定位不会改变元素原来的特性。
  • 相对定位会使元素的层级提升,使元素可以覆盖文 本流中的元素。

绝对定位

  • 绝对定位指使元素相对于html元素或离他最近 的祖先定位元素进行定位。
  • 当将position属性设置为absolute时,则开启 了元素的绝对定位。
  • 当开启了绝对定位以后,可以使用top、right、 bottom、left四个属性对元素进行定位。

特点

  • 绝对定位会使元素完全脱离文本流。
  • 绝对定位的块元素的宽度会被其内容撑开。
  • 绝对定位会使行内元素变成块元素。
  • 一般使用绝对定位时会同时为其父元素指定一 个相对定位,以确保元素可以相对于父元素进 行定位。

固定定位

  • 固定定位的元素会被锁定在屏幕的某个位置上,当 访问者滚动网页时,固定元素会在屏幕上保持不动。
  • 当将position属性设置为fixed时,则开启了元素的 固定定位。
  • 当开启了固定定位以后,可以使用top、right、bottom、left四个属性对元素进行定位。
  • 固定定位的其他特性和绝对定位类似。

z-index层级设置

  • 当元素开启定位以后就可以设置z-index这 个属性。
  • 这个属性可以提升定位元素所在的层级。
  • z-index可以指定一个整数作为参数,值越 大元素显示的优先级越高,也就是z-index 值较大的元素会显示在网页的最上层。
  • 无论z-index值多都不能够将自己的子元素覆盖

表格table

  • tr表示一行
  • th表示表头
  • td表示一个单元格
  • 对于表格可以设置thead tbody tfoot并且无论位置如何表格顺序均不变
  • colspan横向合并colspan=“2”横向合并2行在td里写<td colspan=“2”></td>
  • rowspan横向合并rowspan=“2”纵向合并2列在td里写<td rowspan=“2”></td>

其他样式

  • text-align:设置文本的水平对齐。
  • vertical-align:设置文本的垂直对齐。
    可选值:top、baseline、middle、bottom
  • border-spacing:边框间距
  • border-collapse:合并边框
    collapse:合并边框
    separate:不合并边框

子类与父类分开解决高度塌陷的又一个方法display table

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .box1{
            width: 200px;
            height: 200px;
            background-color: #d86aff;
        }
         .box2{
            width: 100px;
            height: 100px;
            background-color: yellow;
            margin-top: 100px;
        }
        .box1:before{
            content: "";
            display: table;
        }
        .box3{
            border: 1px solid red;
        }
        .box4{
            width: 100px;
            height: 100px;
            background-color: cornflowerblue;
        }
        .clearfix:before,.clearfix:after{
            content: "";
            display: table;
            clear: both;
        }
        .clearfix{
            zoom: 1;
        }

    </style>
</head>
<body>
<div class="box3 clearfix">
    <div class="box4"></div>
</div>
<div class="box1 clearfix">
    <!--<table></table>-->
    <div class="box2"></div>
</div>
</body>
</html>

表单

基本用法如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        /*.form{*/
        /*background-color: #bbffaa;*/
        /*text-align: center;*/
        /*}*/
    </style>
</head>
<body>
<form method="get" action="1.html" class="form">
    <table align="center" border="0">
        <tr>
            <td>
                用户名:
            </td>
            <td><input type="text" name="username" id="username" placeholder="请输入用户名" size="30"></td>
        </tr>
        <tr>
            <td>
                密&nbsp; &nbsp;码:
            </td>
            <td><input type="password" name="password" id="password" placeholder="请输入密码" size="30"></td>
        </tr>
        <tr>
            <td>
                性别:
            </td>
            <td><input type="radio" name="radio">男
                <input type="radio" name="radio">女
            </td>
        <tr>
        <tr>
            <td>
                爱好:
            </td>
            <td><input type="checkbox" name="checkbox">游泳
                <input type="checkbox" name="checkbox">下棋
                <input type="checkbox" name="checkbox">网球
                <input type="checkbox" name="checkbox">篮球
            </td>
        </tr>
        <tr>
            <td colspan="2">
                来自:
                <select>
                    <option>请选择</option>
                    <optgroup label="中国">
                        <option>广州</option>
                        <option>上海</option>
                        <option>北京</option>
                    </optgroup>
                    <optgroup label="美国">
                        <option>华盛顿</option>
                        <option>纽约</option>
                        <option>休斯敦</option>
                    </optgroup>
                </select></td>
        </tr>
        <tr>
            <td>
                <input type="submit" name="submit" id="submit"></td>
            <td><input type="reset" name="reset" id="reset"></td>
        </tr>
    </table>
</form>
</body>
</html>
结果如下:
表单.png

表单其他属性

textarea
  • textarea用来创建一个文本域,实际效果和 文本框类似,只是可以输入多行数据。
    可用属性:
    cols:文本域的列数
    rows:文本域的行数
fieldset
  • fieldset用来为表单项进行分组。
label
  • label标签用来为表单项定义描述文字

附录

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .one{
            width: 960px;
            height: 42px;

            margin: 50px auto;
            list-style-type: none;
            border: 1px solid gainsboro;

        }
        .one li{
            float: left;
            margin: 8px 5px;
            position: relative;
            left: 239px;

        }

        .one a:not(.span){
            display: block;
            text-decoration: none;
            padding: 5px 10px;
            background-color: gold;
            color: black;
            text-align: center;
            font: 12px 微软雅黑;

        }
        .span{
            text-decoration: none;
        }
        .one a:hover{
            background-color: #d86aff;
        }
        .two{
            width: 960px;
            height: 42px;

            margin: 50px auto;
            list-style-type: none;
            border: 1px solid black;
            text-align: center;
        }
        .two a{
            text-decoration: none;
            font: 14px 微软雅黑;
            color: #333;
            font-weight: bold;
        }
        .two li{
            display: block;
            float: left;
            margin: 9px 0px;
            position: relative;
            left: 170px;
        }
        .two span{

            margin: 0px 20px;
        }
        .two a:hover{
            background-color: #bbffaa;
        }
    </style>
</head>
<body>
<div class="box1">
    <ul class="one">
        <li><a href="#">上一页</a></li>
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li>
        <li><a href="#">4</a></li>
        <li><a href="#" class="span"><span >...</span></a></li>
        <li><a href="#">17</a></li>
        <li><a href="#">18</a></li>
        <li><a href="#">19</a></li>
        <li><a href="#">20</a></li>
        <li><a href="#">下一页</a></li>
    </ul>
</div>
<div class="box2">
    <ul class="two">
        <li><a href="#">首页</a></li>
        <li><span>|</span></li>
        <li><a href="#">网站建设</a></li>
         <li><span>|</span></li>
        <li><a href="#">程序开发</a></li>
         <li><span>|</span></li>
        <li><a href="#">网络营销</a></li>
         <li><span>|</span></li>
        <li><a href="#">企业VI</a></li>
         <li><span>|</span></li>
        <li><a href="#">案例展示</a></li>
         <li><span>|</span></li>
        <li><a href="#">联系我们</a></li>
    </ul>
</div>
</body>
</html>
结果如下:
标题栏.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,037评论 1 92
  • 学会使用CSS选择器熟记CSS样式和外观属性熟练掌握CSS各种选择器熟练掌握CSS各种选择器熟练掌握CSS三种显示...
    七彩小鹿阅读 6,429评论 2 66
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 28,677评论 1 45
  • 定位: 定位指的就是将指定的元素摆放到页面的任意位置通过定位可以任意的摆放元素 通过position属性来设置元素...
    咻咻咻滴赵大妞阅读 297评论 0 0
  • HTML 5 HTML5概述 因特网上的信息是以网页的形式展示给用户的,因此网页是网络信息传递的载体。网页文件是用...
    阿啊阿吖丁阅读 4,871评论 0 0

友情链接更多精彩内容