效果图:
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://code.jquery.com/jquery-3.3.1.js"></script>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.left {
position: absolute;
left: 0;
top: 0;
width: 300px;
height: 100%;
background: #123456;
transition: all 0.2s ease 0s;
}
.right {
position: absolute;
/*绝对定位脱离文档流,基于relative或者浏览器*/
left: 300px;
right: 0;
/*left: 0;right: 0;//实现左右居中*/
/*left: 300;right: 0;//width的大小是从left300到右边浏览器结束,而不是根据子元素的width而改变*/
height: 100%;
background: #F5F5DC;
transition: all 0.2s ease 0s;
}