垂直居中

hmtl div水平、垂直居中

匿名 (未验证) 提交于 2019-12-02 23:03:14
最近写网页经常需要将div在屏幕中居中显示,遂记录下几个常用的方法,都比较简单。 水平居中直接加上<center>标签即可,或者设置margin:auto;当然也可以用下面的方法 下面说两种在屏幕正中(水平居中+垂直居中)的方法 放上示范的html代码: <body> <div class="main"> <h1>MAIN</h1> </div> </body> 方法一: div使用绝对布局,设置margin:auto;并设置top、left、right、bottom的值相等即可,不一定要都是0。 .main{ text-align: center; /*让div内部文字居中*/ background-color: #fff; border-radius: 20px; width: 300px; height: 350px; margin: auto; position: absolute; top: 0; left: 0; right: 0; bottom: 0; } --------------------- 作者:qq_32623363 来源:CSDN 原文:https://blog.csdn.net/qq_32623363/article/details/77101971 版权声明:本文为博主原创文章,转载请附上博文链接!

实现多种水平垂直居中的布局(定宽高和不定宽高)

偶尔善良 提交于 2019-12-02 21:54:17
1、定宽高 一、绝对定位和负magin值 <template> <div id="app"> <div class="box"> <div class="children-box"></div> </div> </div> </template> <style type="text/css"> .box { width: 200px; height: 200px; border: 1px solid red; position: relative; } .children-box { position: absolute; width: 100px; height: 100px; background: yellow; left: 50%; top: 50%; margin-left: -50px; margin-top: -50px; } </style> 二、绝对定位 + transform <template> <div id="app"> <div class="box"> <div class="children-box"></div> </div> </div> </template> <style type="text/css"> .box { width: 200px; height: 200px; border: 1px solid red; position:

Java_iText_PDF―生成PDF工具

匿名 (未验证) 提交于 2019-12-02 21:53:52
1. 详情见代码: /** * PDF工具 */ public class PdfUtils { /** * 生成 * @param iouData 借据数据 * @param planList 还款计划List * @param accountsList 收本金账户 * @param interstAccountsList 收息账户 * @param orderCode * @return */ public static String turnToPdf(LoanIouData iouData,List<LoanRepaymentPlan> planList, List<TransferAccount> accountsList, List<TransferAccount> interstAccountsList, String orderCode){ String basePath = PropertiesUtil.getValue("pdf.path","/application.properties"); File file = new File(basePath); if(!file.exists()){ file.mkdirs(); } String path = ""; try { //创建文件 Document document = new Document();

水平,垂直居中的15种方法

匿名 (未验证) 提交于 2019-12-02 20:32:16
一.水平居中 1.文字水平居中 <div class="one">   测试居中 </div> <style> .one{   width: 200px;   height: 100px;   border:1px solid red;    text-align: center; } </style> 2.盒子居中 <div class="one">是盒子居中</div> <style> .one{   width: 200px;   height: 100px;   border:1px solid red;    margin: 0 auto; } </style> 3.多块级元素水平居中 <div class="container"> <div class="child"> 简单不先于复杂 </div> <div class="child"> 而是在复杂之后 </div> <div class="child"> 简单不先于复杂,而是在复杂之后。 </div> <div class="child"> 简单不先 </div> </div> <style> .container {   height:100px;   padding: 8px;    text-align: center;   border: 2px dashed #f69c55; } .child {  

实现图片、多行文本垂直居中:display的table和table-cell搭配效果

两盒软妹~` 提交于 2019-12-02 16:54:51
display的table和table-cell搭配效果:文本\图片 display:table和table-cell是如何让多行文字在块内垂直居中? 多行文本的居中 网页中见过的案例效果 : HTML: <div class="parent"> <p class="son"> 冰爽饮品限时特惠 </p> </div> CSS: .parent { display: table; //容器变成块级表格元素 width: 30px; height: 30px; text-align: center; } .son { display: table-cell; //对应子元素变成表格单元格 height: 30px; vertical-align: middle; } 关键是将容器本身设置为display:table-cell 单元格。再附加两条属性即可。父级不设为dispaly:table 也能产生效果 display: table-cell; text-align: center; vertical-align: middle; ------------------------分割线---------------------------------------------------分割线-----------------------------------------------

图片完美垂直居中的实现方法:display:table\table-row\table-cell

喜你入骨 提交于 2019-12-02 16:54:31
2019独角兽企业重金招聘Python工程师标准>>> 效果如上图所示,完全用css去控制,但不兼容IE7 IE6这两个祖宗,用到的主要是display的table和table-cell两个属性值,恩,vertical-aligen想必以前大家常用在table的td中,这个table-cell正是让你的div可以模拟td的特性,注意: table-row table-cell 最好结合table去套用,div display为table时他仍是属性一个独立的块, 但table-row table-cell的一些特性需依附在table中实现。 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vertical-align</title> <style type="text/css"> .container{ width: 300px; height: 400px; margin: 50px auto; border: 1px solid #ccc; display: table; } .img{ text-align: center; vertical-align: middle; display: table-cell; } img{ width: 260px; height: 350px; } </style>

HTML中实现table垂直居中

荒凉一梦 提交于 2019-12-02 16:52:36
html中是没办法实现上下居中的,如果设置上下居中,需要通过 js 程序来设置。 方法一:在外面嵌套一层table,用table中的td来控制居中 <form id="form1" method="post"> <table border=0 cellpadding=0 cellspacing=0 style="width:100% ;height:100%"> <tr> <td style="width:100%;" align="center" valign="middle"> <table style="background-color:lightskyblue; margin:auto"> <tr> <td></td> <td align="center"> 用户登录 </td> <td></td> </tr> </table> </td> </tr> </table> </form> 方法二: table { width: 600px; height: 400px;//可随意 position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; /* 有了这个就自动居中了 */ } 方法三: table{ margin:0px auto; width:300px; height:200px;

display:flex垂直居中

ε祈祈猫儿з 提交于 2019-12-02 16:51:00
布局说明:1. 场次为一场比赛       2. 比赛双方是交战的两个队伍 3. 一场比赛可以有多种玩法,所以场的每个玩法的布局的高度都不确定。 主要说下我学到的垂直居中的flex。 1. 第一次尝试。 1 < div class ="parent" > 2 < h1 > 我是通过flex的水平垂直居中噢 </ h1 > 3 < h1 > 我是通过flex的水平垂直居中噢 </ h1 > 4 < h1 > 居中 </ h1 > 5 < h1 > 我是通过flex的水平垂直居中噢 </ h1 > 6 </ div > html,body { width : 100% ; height : 200px ; margin : 0 ; padding : 0 ; } .parent { display : flex ; align-items : center ; /* 垂直居中 */ justify-content : center ; /* 水平居中 */ width : 100% ; height : 100% ; background : #ddd } h1 { border : 1px solid #f00 ; margin : 0 ; padding : 0 ; width : 25% ; } 但是我想要的效果是第三栏的高度和其他栏的高度一样,并且居中。如此css改成了 2.

在FlowDocument中设置TableCell垂直居中遇到的问题

≯℡__Kan透↙ 提交于 2019-12-02 16:50:46
最近在程序中用到了WPF中的FlowDocument生成一个文档,其中有对System.Windows.Documents.Table的使用,在使用的过程中发现这家伙居然不支持设置垂直居中。一个程序,内部逻辑是里子,外部显示是面子,而boss显然是既要里子更要面子,于是折腾开始。 先对着MSDN撸,无果。接着满世界问问题,在stackoverflow上提问题,有人给了个 线索 ,这个针对一个TableRow只有一个TableCell的情况时是极好的,奈何前期别人已经将程序写成了一个TableRow中有多个TableCell,要我再去更改程序逻辑比较头疼。于是上MSDN论坛求助,热心的老外给了我一个计算TableCell高度的方法(虽然最后发现有点问题,还是非常感谢)。 最后的方法是通过遍历Table来获取其每行的高度,并通过设置该行TableCell的padding,使其呈现垂直居中的效果。获取行高度的方法如下: private double getRowHeight(TableRow row) { double maxHeight = 0 ; foreach (TableCell cell in row .Cells ) { Rect startRect = cell .ElementStart .GetCharacterRect (LogicalDirection

关于用display:table让元素居中的小结

我是研究僧i 提交于 2019-12-02 16:50:03
让元素垂直居中有一种简单的方法:给需要居中的元素用一个父级包起来,并给父元素添加样式’display:table’,同时给这个父级设置好高度,再给需要居中的元素一个display:table-cell,vertical-align:middle;这样被设置的元素就可以做到垂直居中 效果图如下 来源: CSDN 作者: tian361zyc 链接: https://blog.csdn.net/tian361zyc/article/details/72883945