課程
/前端開發(fā)
/HTML/CSS
/CSS深入理解之line-height
關于垂直居中的,不僅僅是line-height
2016-09-20
源自:CSS深入理解之line-height 1-1
正在回答
簡單的情況text-align:center; ?vertical-align:?middle等,下面是復雜一點的:
// 方法一:已知元素的高寬
?????<div></div>
?CSS:
??.content{
????????background-color:#6699FF;
????????width:200px;
????????height:200px;
????????position: absolute; ???????
????????top: 50%;
????????left: 50%;
????????/* 二分之一的負height,width ?*/
????????margin-top:-100px ;
????????margin-left: -100px;
????}
?//方法二:未知元素的高寬 ???
????????/* transform: translate(-50%,-50%) ?或 margin:auto與四邊距相等 */???
????????margin:auto; ?????/*無這個就只有top、left起作用*/
????????top: 0;
????????left: 0;??
????????bottom:0; ?
????????right: 0;
//3,兩個按鈕在div中居中,并相距一定距離
<style type="text/css">
div{width: 600px;height: 500px;background-color: rgba(240,240,240,0.9);text-align:
????????center;}
.button{ width:100px;height: 90px;background-color: #f00;position: relative;top: 50%;
???????????transform: translate(0,-50%) ?}
.button1{margin-left: 0;margin-right: 100px;}
.button2{margin-right: 0;}
</style>
</head>
<body>
?<div>
? <input type="button" class="button button1"></input>
? <input type="button" ?class="button button2"></input>
?</div>
慕少7532173
舉報
帶領大家深入理解line-height的定義,還有實際應用經(jīng)驗分享
2 回答圖片水平垂直居中不行
1 回答多行文本水平垂直居中模型實現(xiàn)
2 回答單行文本是否真的垂直居中?我測得跟老師的不一樣,我的測是真的居中了,求解
2 回答我怎么實現(xiàn)不了圖片垂直居中呢,按照老師的代碼做的呢
1 回答為什么我在父級塊元素設置行高跟盒子高度一致時,里面的img會垂直居中,搞不懂啊
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2016-09-20
簡單的情況text-align:center; ?vertical-align:?middle等,下面是復雜一點的:
// 方法一:已知元素的高寬
?????<div></div>
?CSS:
??.content{
????????background-color:#6699FF;
????????width:200px;
????????height:200px;
????????position: absolute; ???????
????????top: 50%;
????????left: 50%;
????????/* 二分之一的負height,width ?*/
????????margin-top:-100px ;
????????margin-left: -100px;
????}
?//方法二:未知元素的高寬 ???
?????<div></div>
?CSS:
??.content{
????????background-color:#6699FF;
????????width:200px;
????????height:200px;
????????position: absolute; ???????
????????/* transform: translate(-50%,-50%) ?或 margin:auto與四邊距相等 */???
????????margin:auto; ?????/*無這個就只有top、left起作用*/
????????top: 0;
????????left: 0;??
????????bottom:0; ?
????????right: 0;
????}
//3,兩個按鈕在div中居中,并相距一定距離
<style type="text/css">
div{width: 600px;height: 500px;background-color: rgba(240,240,240,0.9);text-align:
????????center;}
.button{ width:100px;height: 90px;background-color: #f00;position: relative;top: 50%;
???????????transform: translate(0,-50%) ?}
.button1{margin-left: 0;margin-right: 100px;}
.button2{margin-right: 0;}
</style>
</head>
<body>
?<div>
? <input type="button" class="button button1"></input>
? <input type="button" ?class="button button2"></input>
?</div>