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

效果演示css

 

 

實現原理html

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

 

代碼說明web

csside

<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顯示和隱藏效果的樣式。

 

htmlspa

<div>
	<input id="showHideRightPanel" class="showHideRightPanelChk" type="checkbox">
	<div class="topPanel">
		<div>Top panel</div>
	</div>
	<div class="contentPanel">
		<div>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 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>

 運行後,就能夠看見效果了。3d

相關文章
相關標籤/搜索