国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

css中常用的幾種居中方法(推薦)

2024-07-11 08:36:24
字體:
供稿:網(wǎng)友

在前端面試中,大都會問你div居中的方法:

文筆不好,就隨便寥寥幾句話概括了,

不過以后文筆肯定會變得更好一些的。

今天我們就細數(shù)一下幾種方法:

1,使用position:absolute,設(shè)置left、top、margin-left、margin-top的屬性

CSS Code復(fù)制內(nèi)容到剪貼板

.one{   
           position:absolute;   
           width:200px;   
           height:200px;   
           top:50%;   
           left:50%;   
           margin-top:-100px;   
           margin-left:-100px;   
           background:red;    
}  

這種方法基本瀏覽器都能夠兼容,不足之處就是需要固定寬高。

2,使用position:fixed,同樣設(shè)置left、top、margin-left、margin-top的屬性

CSS Code復(fù)制內(nèi)容到剪貼板

.two{   
            position:fixed;   
            width:180px;   
            height:180px;   
            top:50%;   
            left:50%;   
            margin-top:-90px;   
            margin-left:-90px;   
            background:orange;   
}  

大家都知道的position:fixed,IE是不支持這個屬性的

3,利用position:fixed屬性,margin:auto這個必須不要忘記了。

CSS Code復(fù)制內(nèi)容到剪貼板

.three{   
            position:fixed;   
            width:160px;   
            height:160px;   
            top:0;   
            rightright:0;   
            bottombottom:0;   

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 勃利县| 中宁县| 涞水县| 方城县| 高要市| 朔州市| 且末县| 南充市| 麦盖提县| 山丹县| 邳州市| 开封市| 丹巴县| 望城县| 宁国市| 惠州市| 凌源市| 杭锦后旗| 望奎县| 襄樊市| 卓尼县| 全南县| 汶川县| 阿克苏市| 白沙| 永嘉县| 会泽县| 河津市| 兴城市| 库尔勒市| 永清县| 民勤县| 渝北区| 县级市| 黑河市| 云梦县| 长治县| 溆浦县| 平阴县| 库尔勒市| 礼泉县|