zoukankan      html  css  js  c++  java
  • 不定高度实现居中显示

    <!DOCTYPE html>
    <html>
    <meta name="name" content="content" charset='utf-8'>
    <head>
    	<title>网页居中</title>
    </head>
    <style type="text/css" media="screen">
    	*{margin:0;padding: 0;}
    	.al{ 800px;height: 600px;margin: 30px auto;position: relative;border:1px solid red;}
    	.par{position: absolute;top:50%;left:50%;}
    	.chd{background: green;position: relative;top:-50%;left:-50%;}
    	.ul{ 600px;height:400px;margin: 10px auto;border:1px solid blue; }
    	.ul li{ 50px;height: 30px;border:1px solid red;text-align: center;line-height: 30px;list-style-type: none;float:left;margin: 20px 0 0 20px;}
    </style>
    <body>
    <div class="al">
    	<div class="par">
    		<div class="chd">
    			我要居中我要居中
    		</div>
    	</div>
    </div>
    </body>
    </html>
    

      第二种方法

    <!DOCTYPE html>
    <html>
    <meta name="name" content="content" charset='utf-8'>
    <head>
    	<title>网页居中</title>
    </head>
    <style type="text/css" media="screen">
    	*{margin:0;padding: 0;}
    	.al{ 800px;height: 600px;margin: 30px auto;}
    	.par{ 800px;height: 600px;border:1px solid red;display: table-cell;text-align: center;vertical-align: middle;}
    	.chd{background: green;display: inline-block;}
    
    </style>
    <body>
    <div class="al">
    	<div class="par">
    		<div class="chd">
    			我要居中我要居中
    		</div>
    	</div>
    </div>
    </body>
    </html>
    

      

  • 相关阅读:
    生活的乐趣
    android加载webview白屏问题
    强极则辱
    向studio项目中复制集成其他代码,项目R文件丢失
    每一步都是最好的选择
    JQuery小插件,Selected插件1
    JSON进阶三JSON的几种调用形式
    JSON进阶四前后台交互之美
    .NET双样式分页控件
    JSON进阶五JS和WCF的交互
  • 原文地址:https://www.cnblogs.com/mk2016/p/5408034.html
Copyright © 2011-2022 走看看