DIV 垂直 垂直水平 置中,div垂直水平置中
DIV 垂直 置中
讓div置中對齊 使用margin-left:auto;margin-right:auto; 可以讓你的div置中對齊。 .style{margin-left:auto;margin-right:auto;} 縮寫形式為: .style{margin:0 auto;} 數字0 表示上下邊距是0。可以按照需要設定成不同的值。 <style type="text/css"> .align-center{ margin:0 auto; /* 置中 這個是必須的,,其它的屬性非必須 */ width:500px; /* 給個寬度 頂到瀏覽器的兩邊就看不出置中效果了 */ background:red; /* 背景色 */ /* 文字等內容置中 text-align:center;*/}</style> @Html.Partial("_PartialMenuImg", "../../Images/Sys/test.jpg") <div class="align-center"></div>
DIV 垂直水平 置中1,關於置中使用css為:position:fixed;left:50%;top:50%;margin-left:width/2;margin-top:height/2; 對於ie6,只能把position:改成absolute; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>水平垂直置中div示範效果</title><style type="text/css">.align-center{position:fixed;left:50%;top:50%;margin-left:width/2;margin-top:height/2;}</style></head><body><div class="align-center">水平垂直置中div示範效果</div></body></html>
怎使文字在div中水平與垂直置中的css代碼,<div>水平垂直置中</div>
一個比較簡單的方法就是這樣:
你們假設你的DIV是高度100PX,寬度是1000PX,那你這樣寫,你的文字就會水平垂直置中:
<div style="width:1000px; height:100px; text-align:center; line-height:100px; border:blue solid 1px;">
水平垂直置中
</div>
CSS是這樣的,text-align:center意思就是說,讓這個DIV裡的文字水平置中,而line-height:100px;的意思是說,讓DIV裡面的每一行文字,占的高度為100PX(和那個DIV的高度一樣),這樣,文字就垂直置中了。也就是說,如果你的DIV是200PX高,那你就讓line-height:200px;文字就會垂直置中了。
不知道說明白沒有。不行,你再HI我好了。
怎使文字在div中水平與垂直置中的css代碼,<div>水平垂直置中</div>
一個比較簡單的方法就是這樣:
你們假設你的DIV是高度100PX,寬度是1000PX,那你這樣寫,你的文字就會水平垂直置中:
<div style="width:1000px; height:100px; text-align:center; line-height:100px; border:blue solid 1px;">
水平垂直置中
</div>
CSS是這樣的,text-align:center意思就是說,讓這個DIV裡的文字水平置中,而line-height:100px;的意思是說,讓DIV裡面的每一行文字,占的高度為100PX(和那個DIV的高度一樣),這樣,文字就垂直置中了。也就是說,如果你的DIV是200PX高,那你就讓line-height:200px;文字就會垂直置中了。
不知道說明白沒有。不行,你再HI我好了。