zoukankan      html  css  js  c++  java
  • 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>

    效果:

  • 相关阅读:
    Mac系统杂项 (持续更新)
    黑苹果-IOS学习的开始
    WPF命令参数CommandParameter
    WPF使用RoutedCommand自定义命令
    解决iOS设备屏幕切换时页面造成的问题
    width100%,设置padding或border溢出解决方法
    linux下别名alias的设置
    cordova navigator app 对象
    jquery easyui combox实用方法记录
    seajs构建方法
  • 原文地址:https://www.cnblogs.com/lhl66/p/10374600.html
Copyright © 2011-2022 走看看