以京东移动端首页为例:
设置一个版心让其居中给一个最大宽和最小宽其余部分采用流式布局
body {
background: #f5f5f5
}
.jd_container {
min-width: 320px;
max-width: 640px;
width: 100%;
margin: 0 auto
}
.jd_search {
width: 100%;
height: 40px;
position: fixed;
left: 0;
top: 0;
z-index: 1000
}
.jd_search .jd_search_box {
height: 40px;
background: rgba(201, 21, 35, 0.85);
min-width: 320px;
max-width: 640px;
width: 100%;
margin: 0 auto;
position: relative
}
.jd_search .jd_search_box .icon_logo {
position: absolute;
left: 10px;
top: 4px;
width: 60px;
height: 36px;
background-position: 0 -103px
}
.jd_search .jd_search_box .login {
position: absolute;
right: 0;
top: 0;
width: 50px;
height: 40px;
line-height: 40px;
text-align: center;
color: #fff
}
.jd_search .jd_search_box form {
width: 100%;
padding-left: 70px;
padding-right: 50px;
position: relative
}
.jd_search .jd_search_box form .icon_search {
width: 20px;
height: 20px;
position: absolute;
left: 80px;
top: 10px;
background-position: -60px -109px
}
.jd_search .jd_search_box form input {
width: 100%;
height: 30px;
margin-top: 5px;
background: #fff;
border-radius: 15px;
padding-left: 40px
}
.jd_banner {
width: 100%;
overflow: hidden;
position: relative
}
.jd_banner ul:first-child {
width: 1000%;
transform: translateX(-10%);
-webkit-transform: translateX(-10%)
}
.jd_banner ul:first-child li {
width: 10%;
float: left
}
.jd_banner ul:first-child li a {
display: block;
width: 100%
}
.jd_banner ul:first-child li a img {
display: block;
width: 100%
}
.jd_banner ul:last-child {
position: absolute;
width: 118px;
height: 6px;
left: 50%;
margin-left: -59px;
bottom: 6px
}
.jd_banner ul:last-child li {
width: 6px;
height: 6px;
border-radius: 3px;
border: 1px solid #fff;
margin-left: 10px;
float: left
}
.jd_banner ul:last-child li:first-child {
margin-left: 0
}
.jd_banner ul:last-child li.now {
background: #fff
}
.jd_nav {
width: 100%;
background: #fff;
border-bottom: 1px solid #ccc
}
.jd_nav ul {
width: 100%;
padding-top: 10px;
padding-bottom: 10px
}
.jd_nav ul li {
width: 25%;
float: left
}
.jd_nav ul li a {
display: block;
width: 100%
}
.jd_nav ul li a img {
display: block;
width: 40px;
height: 40px;
margin: 0 auto
}
.jd_nav ul li a p {
text-align: center;
font-size: 12px;
color: #666;
padding: 5px 0
}
.jd_product {
padding: 0 5px
}
.jd_product_box {
margin-top: 10px;
box-shadow: 0 0 2px #ccc;
background: #fff
}
.jd_product_box .tit {
height: 34px;
line-height: 34px;
border-bottom: 1px solid #ddd
}
.jd_product_box .tit.nb {
border-bottom: none
}
.jd_product_box .tit h3 {
font-weight: normal;
position: relative;
padding-left: 23px
}
.jd_product_box .tit h3::before {
content: "";
width: 3px;
height: 12px;
background: #d8505c;
position: absolute;
left: 10px;
top: 11px
}
.sk .icon {
width: 16px;
height: 20px;
float: left;
margin-left: 10px;
margin-top: 7px;
background: url("../images/seckill-icon.png") no-repeat center/16px 20px
}
.sk .name {
float: left;
margin-left: 10px;
font-size: 16px;
color: #d8505c
}
.sk .time {
float: left;
margin-left: 10px
}
.sk .time span {
float: left;
width: 16px;
height: 16px;
line-height: 16px;
text-align: center;
color: #fff;
background: #333;
margin-left: 3px;
margin-top: 9px
}
.sk .time span:nth-child(3n) {
background: #fff;
width: 3px;
color: #333
}
.sk .pro {
width: 100%;
padding: 10px 0
}
.sk .pro li {
width: 33.3333%;
float: left
}
.sk .pro li a {
display: block;
border-right: 1px solid #ddd
}
.sk .pro li:last-child a {
border-right: none
}
.sk .pro li a img {
display: block;
margin: 0 auto;
width: 64%
}
.sk .pro li p {
text-align: center;
font-size: 12px;
padding: 5px 0
}
.sk .pro li .nowPrice {
color: #d8505c
}
.sk .pro li .oldPrice {
color: #666;
text-decoration: line-through
}
.w_50p {
width: 50%
}
.w_50p img {
display: block;
width: 100%
}
.bl {
border-left: 1px solid #ddd
}
.br {
border-right: 1px solid #ddd
}
.bb {
border-bottom: 1px solid #ddd
}
左侧固定右侧自适应:
方法:
1、左侧浮动并且固定宽度
2.右侧流式布局并设置overflow:hide
/*大容器*/
html,body{
height: 100%;
}
.jd_layout{
width: 100%;
height: 100%;
}
/*顶部通栏*/
.jd_topBar{
width: 100%;
height: 45px;
border-bottom: 1px solid #ccc;
background: url(../images/header-bg.png) 0 0 / 1px 44px;
position: absolute;
top: 0;
left: 0;
}
.jd_topBar a{
width: 40px;
height: 44px;
padding: 12px 10px;
position: absolute;
top: 0;
background-origin: content-box;
background-clip: content-box;
}
.jd_topBar .icon_back{
left: 0;
background-position: -20px 0;
}
.jd_topBar .icon_menu{
right: 0;
background-position: -60px 0;
}
.jd_topBar form{
width: 100%;
padding: 0 40px;
}
.jd_topBar form input{
width: 100%;
height: 30px;
border: 1px solid #ddd;
border-radius: 4px;
margin-top: 7px;
padding: 0 10px;
}
/*占满剩余的高度*/
.jd_main{
width: 100%;
height: 100%;
padding-top: 45px;
}
.jd_main .jd_cateLeft{
width: 90px;
height: 100%;
float: left;
overflow: hidden;
}
.jd_main .jd_cateLeft ul{
width: 90px;
}
.jd_main .jd_cateLeft ul li{
width: 90px;
height: 50px;
line-height: 50px;
background: #f3f4f5;
text-align: center;
font-size: 12px;
border-bottom: 1px solid #ccc;
border-right: 1px solid #ccc;
}
.jd_cateLeft ul li.now{
border-right: none;
background: #fff;
}
.jd_cateLeft ul li.now a{
color: #d8505c;
}
.jd_main .jd_cateLeft ul li a{
display: block;
width: 100%;
}
.jd_main .jd_cateRight{
overflow: hidden;
height: 100%;
}
.jd_main .jd_cateRight_box{
padding: 0 10px;
}
.jd_main .jd_cateRight_box .banner{
width: 100%;
display: block;
margin-top: 10px;
}
.jd_main .jd_cateRight_box .banner img{
width: 100%;
display: block;
}
.jd_cateRight_box .hot{}
.jd_cateRight_box .hot h3{
font-size: 12px;
}
.jd_cateRight_box .hot ul{
width: 100%;
}
.jd_cateRight_box .hot ul li{
width: 33.333%;
float: left;
}
.jd_cateRight_box .hot ul li a{
display: block;
width: 100%;
}
.jd_cateRight_box .hot ul li a img{
width: 62px;
height: 62px;
display: block;
margin: 0 auto;
}
.jd_cateRight_box .hot ul li a p{
font-size: 12px;
text-align: center;
padding: 5px 0;
}
网友评论