CSS3+HTML5特效8 - 頂部和右側固定,左側隨視窗變化的布局

來源:互聯網
上載者:User

標籤:c   style   class   blog   code   a   

原文:CSS3+HTML5特效8 - 頂部和右側固定,左側隨視窗變化的布局

效果示範

 

 

實現原理

  1. 使用3個div(一個是頂部欄,一個是左側欄,一個是右側欄);
  2. 使用checkbox作為判斷是否顯示和隱藏右側欄,點擊顯示和隱藏label實現最終效果。

 

代碼說明

css

+ View Code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 <style> body {   font-family:"Microsoft YaHei",arial,sans-serif;   margin: 0px;   padding: 0px;   color: #666; }   ul {   margin:0;   padding:0;   list-style-type:none; }   .topPanel{     position: fixed;     top: 0px;     left: 0px;     height: 30px;     width: 100%;     border-top: 1px solid #e0e0e0;     border-bottom: 1px solid #e0e0e0;     background: #F0FFFF; }   .topPanel div{     display: inline-block;     padding: 3px 20px 0px 3px;     height: 27px; }   .splitPanel{     position: fixed;     top: 49%;     width: 15px;     height: 50px;     right: 301px;     background: #1E90FF;     cursor: pointer;     border-top-left-radius: 10px;     border-bottom-left-radius: 10px;     z-index: 9999; }   .showHideRightPanelChk {     display: none; }   .showHideRightPanelChk:checked ~ .rightPanel {     display: none; }   .showHideRightPanelChk:checked ~ .splitPanel {     right: 0px;     background: #FFC125; }   .showHideRightPanelChk:checked ~ .splitPanel label{     right: 0px; }   .showHideRightPanelChk:checked ~ .splitPanel label:nth-child(1){     margin: 20px 0px 0px 6px;     transform: rotate(315deg);     -webkit-transition:1s all ease;     transition:1s all ease; }   .showHideRightPanelChk:checked ~ .contentPanel {     right: 0px; }   .splitMark{     margin: 20px 0px 0px 3px;     width: 5px;     height: 5px;     border-top: 2px #fff solid;     border-left: 2px #fff solid;     transform: rotate(135deg);     display: inline-block;     -webkit-transition:1s all ease;     transition:1s all ease; }   .splitBorder{     position: fixed;     top: 49%;     width: 15px;     height: 50px;     right: 301px; }   .rightPanel{     position: fixed;     top: 31px;     right: 0px;     width: 299px;     bottom: 1px;     border-left: 1px solid #e0e0e0;     padding: 1px 1px 1px 1px; }   .rightPanel div{     display: inline-block;     margin: 0px 0px 14px 0px; }   .contentPanel{     position: fixed;     top: 32px;     left: 0px;     right: 301px;     bottom: 1px;     width: auto;     background: #FFFFF0; } </style>

  

  1. 設定了頂部div,height為30px,width為100%,底部有邊框的效果;
  2. 設定了左側div,top為32px,距離右側301px,距離底部1px,width為auto的效果;
  3. 設定了右側div,top為31px,width為300px,距離底部1px,左側有邊框的效果;
  4. 設定了用於點擊轉場效果的地區,top為49%,width為15px,height為50px,距離右側301px,同時設定左上及左下為圓角效果;
  5. 設定用於標識右側div顯示和隱藏效果的樣式。

 

html

<div><input id="showHideRightPanel" class="showHideRightPanelChk" type="checkbox"><div class="topPanel"><div>Top panel</div></div><div class="contentPanel"><div>ContentContent Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content Content </div></div><div class="splitPanel"><label for="showHideRightPanel" class="splitMark"></label><label for="showHideRightPanel" class="splitBorder"></label></div><div class="rightPanel"><div><ul><li>Right panel</li></ul></div></div></div>

 運行後,就可以看見效果了。

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.