• pc端常见布局---垂直居中布局 单元素定高


    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>常见元素布局</title>
            <style type="text/css">
                /* 一、垂直居中布局 */
                /* 1.单个元素垂直居中 高度固定 缺点:用到定位,脱离文档流*/
                .content {
                    position: relative;
                    height: 100px;
                    background: #008000;/* background和height测试更好的观看效果 */
                }
    
                .box {
                    height: 50px;
                    position: absolute;
                    top: 0;
                    bottom: 0;
                    margin: auto 0;
                    background: #ff9933;
                    color: #fff; /* background和color测试更好的观看效果 */
                    line-height: 50px; /* 文字垂直居中 */
                }
            </style>
        </head>
        <body>
            <div class="content">
                <div class="box">
                    高度固定
                </div>
            </div>
        </body>
    </html>
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>常见元素布局</title>
            <style type="text/css">
                /* 一、垂直居中布局 */
                /* 2.单个元素垂直居中 高度固定 记得父容器设置了行高,子类要记得重置行高*/
                .content {
                    height: 100px;
                    line-height: 100px;
                    background: #008000;/* background测试更好的观看效果 可忽略*/
                }
    
                .box {
                    display: inline-block;
                    height: 50px;
                    vertical-align: middle;
                    background: #ff9933;
                    color: #fff;/* background和color测试更好的观看效果 */
                    line-height: 50px;/* 文字垂直居中 */
                }
            </style>
        </head>
        <body>
            <div class="content">
                <div class="box">
                    高度固定
                </div>
            </div>
        </body>
    </html>

    效果:

  • 相关阅读:
    疯狂Java学习笔记(008)
    CSS-链接
    css学习:css样式的引入
    两个文本根据索引key关联合并,将无关联信息单独输出
    三 数据挖掘算法
    二、数据挖掘
    vsftp虚拟账户设置
    python3在linux下的编码错误
    python 一个根据正则判断输入的函数
    python excel读写与dict转换
  • 原文地址:https://www.cnblogs.com/lhl66/p/10374600.html
Copyright © 2020-2023  润新知