垂直和水平对齐(中间和中心)的CSS [英] vertical and horizontal align (middle and center) with css

查看:242
本文介绍了垂直和水平对齐(中间和中心)的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在练CSS和我很困惑我怎么能强迫我的 DIV 元素为中心(垂直和水平方向),在我的网页(指哪种方式或途径跨浏览器兼容)?

I am practicing CSS and i am so confused how can i force my div element to be center (vertically and horizontally) at my page (mean which way or ways for cross browser compatibility)?

祝商祺!

推荐答案

有许多方法:

  1. 中心的水平,并与固定措施的元件的垂直对齐

CSS

 <div style="width:200px;height:100px;position:absolute;left:50%;top:50%;
margin-left:-100px;margin-top:-50px;">
<!–content–>
</div> 


2。中心水平和文字的垂直一行


2 . Center horizontally and vertically a single line of text

CSS

<div style="width:400px;height:200px;text-align:center;line-height:200px;">
<!–content–>
</div>  


3。居中的元件的水平和垂直对准,没有特别的措施


3 . Center horizontal and vertical align of an element with no specific measure

CSS

<div style="display:table;height:300px;text-align:center;">
<div style="display:table-cell;vertical-align:middle;">
<!–content–>
</div>
</div>  


这里更多: <一个href="http://www.noobcube.com/tutorials/html-css/horizontal-and-vertical-centering-using-css-a-beginners-guide-/">Horizontal和垂直对齐在CSS

这篇关于垂直和水平对齐(中间和中心)的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆