日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

垂直居中效果汇总

發(fā)布時間:2025/4/16 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 垂直居中效果汇总 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

垂直居中是網站中一種常見的需求,常見的垂直居中效果和實現(xiàn)如下

1、具有固定寬高的div垂直居中

?

2、單行文本垂直居中

?

3、多行文本處置居中

?

4、圖片垂直居中

?

案例與實現(xiàn)方法前點擊鏈接:

http://www1.pconline.com.cn/magazine/20170220/test3.html

代碼如下

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>test</title><style>*{/*outline: 1px solid red;*/}body{text-align: center;}.div1{width: 200px;height: 200px;margin:auto;position: relative;border:1px solid green;}.div11{width: 100px;height: 100px;position: absolute;top:50%;left:50%;margin-left:-50px;margin-top:-50px;outline: 1px solid red;}.div2{width: 200px;height: 200px;border:1px solid blue;margin:auto;margin-top: 20px;text-align: center;}.span22{text-align: center;line-height: 200px;}.div3{width: 800px;height: 400px;margin:auto;border: 1px solid blue;margin-top: 20px;text-align: center;vertical-align: middle;}.div3 img{vertical-align: middle;}.span33{display: inline-block;width: 0px;height: 100%;vertical-align: middle;}.div4{width: 200px;height: 200px;margin:auto;border: 1px solid red;margin-top:20px;position: relative;}</style> </head> <body><h3>1、具有固定寬高的div垂直居中</h3><div class="div1"><div class="div11">div11</div></div><h3>2、單行文本垂直居中</h3><div class="div2"><span class="span22">hello world</span></div><h3>3、多行文本處置居中</h3><div class="div4"><div class="div44">hello helo heloo heloo woe o egaghrbqrb naobjo bnorebjoqr bneojb beorb oqer nojoqfjobq</div></div><script>var div44 = document.querySelector(".div44");div44W = div44.offsetWidth;div44H = div44.offsetHeight;div44.style.marginLeft=(div44.parentNode.offsetWidth-div44W)/2+"px"; div44.style.marginTop =(div44.parentNode.offsetHeight-div44H)/2+"px";</script><h3>4、圖片垂直居中</h3><div class="div3"><span class="span33"></span><img src="a.jpg" alt=""></div> </body> </html>

?

?

轉載于:https://www.cnblogs.com/gg1234/p/6419902.html

總結

以上是生活随笔為你收集整理的垂直居中效果汇总的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。