css居中與布局

- 水平居中

1.行內(nèi)元素:text-align:center
  <p class="cen">居中</p>     //html代碼
  .cen{                      //css代碼
  text-align:center;
  border:1px solid red;
  }
2.塊級(jí)元素

讓塊級(jí)元素居中的方法就是設(shè)置 margin-leftmargin-rightauto
margin:0 auto

  <div class="first"></div>          //html
  .first{                            //css
        width:20px;
        height:20px;
        margin:0 auto;
        border:1px solid red;
  }

- 垂直居中

1.設(shè)置padding-top與padding-bottom相等

  <div class="first">first</div>      //html
  .first{                             //css
        width:200px;
        padding-top:20px;
        padding-bottom:20px;
        border:1px solid red;
  }

2.設(shè)置height與line-height相等

 <div class="first">first</div>      //html
  .first{                            //css
  width:100px;
  height: 50px;
  line-height: 50px;
  border:1px solid red;
  }

- 左右布局

通過(guò)float浮動(dòng)實(shí)現(xiàn),float:left與float:right

<div class="first">leftcontent</div>
<div class="second">rightcontent</div>
.first{                       
  width:100px;
  height: 100px;
  float:left;
  border:1px solid red;
}
.second{                       
  width:100px;
  height: 100px;
  float:right;
  border:1px solid green;
}

- 左中右布局

思路:使用div將左中左浮,右側(cè)右浮

<div class="out">
    <div class="clearfix inner" style="float:left"> 
        <div class="first">left</div>
        <div class="first">middle</div>  
     </div>   
     <div class="third">right</div>
</div> 

.out{
    width:354px;
    height:100px;
    border:1px solid red;
}
.clearfix::after{
    content:'';
    display:block;
    clear:both;
}
.first{                       
  width:100px;
  height: 100px;
  float:left;
  border:1px solid red;
}
.second{                       
  width:100px;
  height: 100px;
  float:left;
  border:1px solid green;
  margin-left:25px;
}
.third{                       
  width:100px;
  height: 100px;
  float:right;
  border:1px solid green;
}


其他技巧

google關(guān)鍵字:
  • css shadow generator 生成陰影
  • css gradient generator 漸變背景
  • webpage free psd 免費(fèi)psd文件
  • dribbble 網(wǎng)站
  • css tricks shape css形狀代碼
  • iconfont.cn 圖標(biāo)庫(kù)
  • wallhaven 高清壁紙
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 陽(yáng)光明媚的星期天,天空是那么晴朗,空氣是那么新鮮,陽(yáng)光把所有的光芒帶到了大地,大地就變得暖洋洋的,就連云彩...
    梔藍(lán)_鈊閱讀 454評(píng)論 0 0
  • 如果有人問(wèn)你“你的夢(mèng)想是什么”你會(huì)如何回答? 朋友小A是一個(gè)外表純良,內(nèi)心堅(jiān)毅的妹子。記得才上大學(xué)時(shí),她說(shuō)“這里只...
    清婉Roise閱讀 222評(píng)論 0 0
  • 第二局 第二個(gè)夜晚 三維投影上出現(xiàn)了師也橫死的畫面,他就跟小雞一樣攤在地上,而他的頭頂,一根皮帶還在微微搖晃。 ...
    刀疤兒閱讀 872評(píng)論 2 7
  • 熬夜寫東西搞定了一個(gè)研究設(shè)計(jì)已經(jīng)快5點(diǎn)了
    dq920813閱讀 80評(píng)論 0 0

友情鏈接更多精彩內(nèi)容