zoukankan
html css js c++ java
纯CSS基于窗口垂直居中
都是IE8+的
<!DOCTYPE html> <html> <head> <title>基于窗口垂直居中 by 司徒正美</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style> body{ background-image:url(about:blank); /* for IE6 */ } .fixed{ position: fixed; left: 50%; top:50%; height: 0;/* 不占据位置 */ background-color: red; } .relative{ position: relative; left: -50%;/*处理水平方向 */ /*处理垂直方向*/ -webkit-transform: translateY(-50%) translateZ(0); -moz-transform: translateY(-50%); -ms-transform: translateY(-50%); -o-transform: translateY(-50%); transform: translateY(-50%) translateZ(0); background-color: pink; } .content{ padding:80px; background-color: lightblue; } </style> </head> <body > <h1<基于窗口垂直居中 by 司徒正美</h1> <button onclick="document.getElementById('dialog').style.display = 'block'">open</button> <div class="fixed" id="dialog"> <div class="relative"> <div class="content"> <button style='position: absolute;right:0;top:0' type='button' onclick="document.getElementById('dialog').style.display = 'none'">close</button> XXXXXXXXXXXXXXXXX </div> </div> </div> </body> </html>
运行代码
<!DOCTYPE html> <html> <head> <title>基于窗口垂直居中 by 司徒正美</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style> body{ background-image:url(about:blank); /* for IE6 */ } .fixed{ position: fixed; left: -100%; right:100%; top:0; bottom: 0; background-color: #CCC; text-align: center; font-size: 0; } .fixed:after { content:""; display: inline-block; vertical-align: middle; height: 100%; 0; } .content{ display: inline-block; *display: inline; *zoom:1; vertical-align: middle; text-align: left; position: relative; right: -100%; font-size: 16px; background-color: lightgreen; width:150px; height: 150px; } </style> </head> <body > <button onclick="document.getElementById('dialog').style.display = 'block'">open</button> <h1>基于窗口垂直居中 2 by 司徒正美</h1> <div class="fixed" id="dialog"> <div class="content"> <button style='position: absolute;right:0;top:0' type='button' onclick="document.getElementById('dialog').style.display = 'none'">close</button> XXXXXXXXXXXXXXXXX </div> </div> </body> </html>
运行代码
相关链接:
CSS未知高度垂直居中
查看全文
相关阅读:
小程序导出excel
小程序搜索框加icon
微信小程序全局传参 app传参
长亭安服面经
uni关于生成支付宝小程序问题
Echarts图表使用
js获取url路径斜杠分开
git---更新gitignore文件,使之生效
常见Cpu 100%的原因
OFFICE 2019 INSTRUCTIONS
原文地址:https://www.cnblogs.com/rubylouvre/p/3157572.html
最新文章
Msfvenom学习总结
【转载】Word2Vec-知其然知其所以然
MASKCRAFTER: 1.1
HOGWARTS: BELLATRIX
HA: VEDAS
HA: NARAK
KB-VULN: 3
议论文阅读笔记
将博客搬至CSDN
[luogu p5049] 旅行(数据加强版)
热门文章
[集训队作业2018] 串串
带花树学习笔记
wqs二分&闵可夫斯基和学习笔记
Lyndon Word&Runs 学习笔记
[集训队作业2018] 串串划分
去除数组中的空值
小程序微信在线支付
js根据月份或者开始和结束时间
两个数组取相同项filter
小程序日期时间控件 日期时间选择器
Copyright © 2011-2022 走看看