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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > CSS >内容正文

CSS

垂直居中及容器内图片垂直居中的CSS解决方法

發布時間:2023/12/6 CSS 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 垂直居中及容器内图片垂直居中的CSS解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

方法一:

<style type="text/css">
<!--
* {margin:0;padding:0}
div {
? width:500px;
? height:500px;
? border:1px solid #666;
? overflow:hidden;
? position:relative;
? display:table-cell;
? text-align:center;
? vertical-align:middle
}
div p {
? position:static;
? +position:absolute;
? top:50%
? }
img {
? position:static;
? +position:relative;
? top:-50%;left:-50%;
? }
-->
</style>
<div><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div>

方法二:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div里面圖片垂直居中的幾個例子</title>
<style type="text/css">
<!--
body {
? margin:0;padding:0
}
div {
? width:500px;
? height:500px;
? line-height:500px;
? border:1px solid #666;
? overflow:hidden;
? position:relative;
? text-align:center;
}
div p {
? position:static;
? +position:absolute;
? top:50%
}
img {
? position:static;
? +position:relative;
? top:-50%;left:-50%;
? vertical-align:middle
}
p:after {
? content:".";font-size:1px;
? visibility:hidden
}
-->
</style>
</head>
<body>
<div><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div>
</body>
</html>

方法三:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div里面圖片垂直居中的幾個例子</title>
<style type="text/css">
<!--
* {margin:0;padding:0}
div {
? width:500px;
? height:500px;
? line-height:500px;
? border:1px solid #666;
? overflow:hidden;
? position:relative;
? text-align:center;
}
div p {
? position:static;
? +position:absolute;
? top:50%;
? vertical-align:middle
}
img {
? position:static;
? +position:relative;
? top:-50%;left:-50%;
? vertical-align:middle
}
-->
</style>
</head>
<body>
<div><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div>
</body>
</html>

方法四(針對背景圖片居中):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div里面圖片垂直居中的幾個例子</title>
<style type="text/css">
<!--
* {margin:0;padding:0;}
div {
? width:500px;border:1px solid #666;
? height:500px;
? background:url("http://www.google.com/intl/en/images/logo.gif") center no-repeat
}
-->
</style>
</head>
<body>
<div></div>
</body>
</html>


?

總結

以上是生活随笔為你收集整理的垂直居中及容器内图片垂直居中的CSS解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

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