zoukankan      html  css  js  c++  java
  • div在div垂直居中(响应式)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>浮动元素居中</title>
    <style type="text/css"> 
    <!--
    #hezi {
        position:absolute;
        left:50%;
        top: 50%;
    }
    .s_cell {
        float:left;
        position:relative;
        right:50%;
        bottom: 50%;
        background: red;
    }
    -->
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=uft-8"></head>
    <body>
    <div id="hezi">
    <div class="s_cell">
    <span class="font_style">浮动元素内容1浮动元素内容1浮动元素内容1浮动元素内容1</span>
    </div>
    </div>
    </body>
    </html>


     
    <!doctype html>
    <html>
    
        <head>
            <meta charset="utf-8">
            <title>子盒子绝对居中</title>
        </head>
        <style>
        html,body{height: 100%;}
        *{margin: 0px;padding: 0px;}
            #big {
                margin: 0 auto;
                position: relative;
                width: 100%;
                height: 100%;
                background: #5B5757;
            }
            .small {
                width: 500px;
                height: 200px;
                position: absolute;
                top: 50%;
                left: 50%;
                margin-left: -250px;
                /*设置负值,为要定为子盒子的一半宽度*/
                
                margin-top: -100px;
                /*设置负值,为要定位子盒子的一半高度*/
                
                background: green;
            }
        </style>
    
    
        <div id="big">
            <div class="small"></div>
        </div>
    
    </html>
  • 相关阅读:
    HTML 基础 元素 标签
    HTML5 元素介绍
    网站程序 模板下载 下载 ftp
    域名解析和空间绑定
    如何选择云虚拟主机操作系统?
    网站备案查询
    响应式网站01
    项目中使用百度统计和友盟统计
    项目中使用http referer,为了盗取图片资源
    vue-awesome-swiper中的数据异步加载
  • 原文地址:https://www.cnblogs.com/yutaoyao/p/4079470.html
Copyright © 2011-2022 走看看