三栏布局(二)——上下宽高固定,中间自适应

上下宽高固定,中间自适应的几种布局方式,

有4种布局方式:   position;   flex;    table;   grid。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>上下固定,中间自适应</title>
</head>
<style type="text/css">
html * {
padding: 0;
margin: 0;
}

html,
body {
height: 100%;
}

.layout {
width: 200px;
margin-right: 20px;
display: inline-block;
overflow: hidden;
height: 100%;
}

.layout .container div {
width: 200px;

}
</style>
<body>
<!-- 定位 -->
<section class="layout position">
<style type="text/css">
.layout.position .container>div {
position: absolute;
}

.layout.position .top {
top: 0;
height: 100px;
background-color: pink;
}

.layout.position .middle {
top: 100px;
bottom: 100px;
background-color: skyblue;
}

.layout.position .bottom {
height: 100px;
bottom: 0px;
background-color: deeppink;
}
</style>
<article class="container">
<div class="top">pistion上</div>
<div class="middle">pistion中</div>
<div class="bottom">pistion下</div>
</article>
</section>
<!-- flex 注意 html和body的高度都要设置成100%-->
<section class="layout flexbox">
<style type="text/css">
.layout.flexbox {
height: 100%;
}

.layout.flexbox .container {
width: 200px;
display: flex;
height: 100%;
flex-direction: column;
}

.layout.flexbox .top {
height: 100px;
background-color: pink;
}

.layout.flexbox .middle {
flex: 1;
background-color: #87CEEB;
overflow: auto;
}

.layout.flexbox .bottom {
height: 100px;
background-color: hotpink;
}
</style>
<article class="container">
<div class="top">flexbox上</div>
<div class="middle">flexbox中</div>
<div class="bottom">flexbox下</div>
</article>
</section>

<!-- 表格布局 -->
<section class="layout table">
<style type="text/css">
.layout.table{
height: 100%;

}
.layout.table .container{
height: 100%;
display: table;
width: 200px;
}
.layout.table .container>div{
display: table-row;
}
.layout.table .top {
height: 100px;
background-color: pink;
}

.layout.table .middle {
background-color: #87CEEB;
}

.layout.table .bottom {
height: 100px;
background-color: hotpink;
}
</style>
<article class="container">
<div class="top">table上</div>
<div class="middle">table中</div>
<div class="bottom">table下</div>
</article>
</section>

<!-- 网格布局 -->
<section class="layout grid">
<style type="text/css">
.layout.grid{
height: 100%;
}
.layout.grid .container{
height: 100%;
display: grid;
width: 200px;
grid-template-columns:100px;
grid-template-rows:100px auto 100px;

}

.layout.grid .top {
background-color: pink;
}

.layout.grid .middle {
background-color: #87CEEB;
}

.layout.grid .bottom {
background-color: hotpink;
}
</style>
<article class="container">
<div class="top">grid上</div>
<div class="middle">grid中</div>
<div class="bottom">grid下</div>
</article>
</section>
</body>
</html>

原文地址:https://www.cnblogs.com/SallyShan/p/11617509.html

时间: 2024-08-29 19:52:02

三栏布局(二)——上下宽高固定,中间自适应的相关文章

CSS布局-三栏布局,左右宽度300px,中间自适应

tips: css中“>”是: css3特有的选择器,A>B 表示选择A元素的所有子B元素. 与A B的区别在于,A B选择所有后代元素,而A>B只选择一代.  .a,.b{逗号指相同的css样式}:.a .b{空格指后代元素}:.a>.b{大于号指子代元素}: 一.浮动解决方案 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q

中间固定 两边平分的 自适应三栏布局

NEC 和网上有很多关于两栏三栏布局的案例,而关于三栏布局大体为: 两边固定大小 中间自适应: 无意中一个朋友问我: 中间固定 两边平分的 自适应三栏布局 怎么实?! 当时第一时间想到的是用 display: flex; 然而这个属性不是全兼容的,目前市场上一些国产机的浏览器 实现不了想要的结果: 回去细想后觉得用position是个方法——不管怎样这是在布局中被我用坏了的属性,总能帮我解决很多问题! 以下是贴出的代码: <style> *{ padding: 0; margin: 0; }

css实现三栏布局的几种方法及优缺点

三栏布局,顾名思义就是两边固定,中间自适应. 三栏布局在实际的开发十分常见,比如淘宝网的首页,就是个典型的三栏布局:即左边商品导航和右边导航固定宽度,中间的主要内容随浏览器宽度自适应. 我们不妨假定这样一个布局:高度已知,其中左栏.右栏宽度各为300px,中间自适应,可以通过几种方法来实现?以及各自的优缺点是什么? 一.浮动布局 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l

详解 CSS 七种三栏布局技巧

作者:林东洲 链接:https://zhuanlan.zhihu.com/p/25070186 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 三栏布局,顾名思义就是两边固定,中间自适应.三栏布局在开发十分常见,那么什么是三栏布局?比如我打开某东的首页: 映入眼帘的就是一个常见的三栏布局:即左边商品导航和右边导航固定宽度,中间的主要内容随浏览器宽度自适应. 下面围绕的这样的目的,即左右模块固定宽度,中间模块随浏览器变化自适应,想要完成的最终效果如下图所示: 红色

三栏布局(二)-------上下宽高固定,中间自适应

上一篇写的是左右宽高固定,中间自适应,根据上一篇的内容,总结了下上下宽高固定,中间自适应的几种布局方式,话不多说,直接上代码. <!DOCTYPE html> <html> <head> <title>上中下三栏布局</title> <style type="text/css"> html * { padding: 0; margin: 0; } html, body{ height:100%; } .layout

记一道css面试题 : 三栏布局两边宽度固定,中间宽度自适应,并且布局随屏幕大小改变。

前几天面试时有道css题没做出来,回来好好学习一番后把其记录下来. 题目是这样的:左中右三栏布局,左右两栏宽度固定,左右两栏的宽度为200像素,中间栏宽度自适应.当屏幕小于600px时,3栏会分别占用一行.像这样 当屏幕大于600px时,是这样 我做出来用了css3的@media,如果不用这个,好吧,水平有限想不出来... 下面是代码: <!DOCTYPE> <html> <head> <style> body{ margin: 0 ; padding: 0

css高度已知,左右定宽,中间自适应三栏布局

css高度已知,左右定宽,中间自适应三栏布局: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X

CSS实现经典三栏布局(两侧定宽,中间自适应)

近期开始独立攻克百度前端技术学院的各项任务,之前做了两个比较复杂的页面,深深感觉基础不好,好多css的语句都是为了实现效果而去写的,出现了好多问题,而自己的解决方案也不够优,于是决定从基础开始学起,循序渐进. 第一个任务是实现一个三栏布局,外部的两栏固定宽度,中间自适应,以下是效果图: 我使用了两种方法实现以上效果:float和position 以下是float方法的CSS代码: 1 .team-inf{ 2 float: left; 3 width: 200px; 4 } 5 .logo-gr

转载:CSS实现三栏布局的四种方法示例

转载网址:http://www.jb51.net/css/529846.html 前言 其实不管是三栏布局还是两栏布局都是我们在平时项目里经常使用的,也许你不知道什么事三栏布局什么是两栏布局但实际已经在用,或许你知道三栏布局的一种或两种方法,但实际操作中也只会依赖那某一种方法,本文具体的介绍了三栏布局的四种方法,并介绍了它的使用场景. 所谓三栏布局就是指页面分为左中右三部分然后对中间一部分做自适应的一种布局方式. 1.绝对定位法 HTML代码如下: <div class="left&quo