css居中與布局

- 水平居中

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

讓塊級元素居中的方法就是設置 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.設置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.設置height與line-height相等

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

- 左右布局

通過float浮動實現(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將左中左浮,右側右浮

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

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

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

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