css和css3弹性盒模型实现元素宽度(高度)自适应
发布时间:2019-05-15 15:28:48 作者:花花最美腻
我要评论
这篇文章主要介绍了css和css3弹性盒模型实现元素宽度(高度)自适应的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
一、css实现左侧宽度固定右侧宽度自适应
1、定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自适应</title>
<style>
*{
padding: 0;
margin: 0;
}
.left{
background: red;
width: 200px;
height: 200px;
position: absolute;/*定位*/
left: 0;
top:0;
}
.right{
background: blue;
height: 200px;
margin-left: 210px;
}
</style>
</head>
<body>
<div class="left">
定宽
</div>
<div class="right">
自适应
</div>
</body>
</html>
2、浮动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自适应</title>
<style>
*{
padding: 0;
margin: 0;
}
.left{
background: red;
width: 200px;
height: 200px;
float: left;/*浮动*/
}
.right{
background: blue;
height: 200px;
margin-left: 210px;
}
</style>
</head>
<body>
<div class="left">
定宽
</div>
<div class="right">
自适应
</div>
</body>
</html>
3、margin
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自适应</title>
<style>
*{
padding: 0;
margin: 0;
}
.left{
background: red;
width: 200px;
height: 200px;
}
.right{
background: blue;
height: 200px;
margin-top: -200px;/*margin*/
margin-left: 210px;
}
</style>
</head>
<body>
<div class="left">
定宽
</div>
<div class="right">
自适应
</div>
</body>
</html>
二、css3弹性盒模型实现自适应
1、上下高度固定中间高度自适应
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
body,html{
height: 100%;
}
#contain{
display: flex;
flex-direction: column;/*列 垂直方向*/
height: 100%;/*全屏效果 该元素及其父元素及html、body height:100%*/
}
#top{
height: 200px;
background: red;
}
#center {
flex: 1;
background: blue;
}
#bottom{
height: 100px;
background: green;
}
</style>
</head>
<body>
<div id="contain">
<div id="top">你好</div>
<div id="center">你好</div>
<div id="bottom">你也好</div>
</div>
</body>
</html>
2、左侧宽度固定右侧宽度自适应
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
#contain {
display: flex; /*父元素设置该属性*/
}
#left {
width: 100px;
height: 200px;
background: #fff8a8;
margin-right: 10px;
}
#right {
flex: 1; /*所占比例/份数*/
height: 200px;
background: #ff9bad;
}
</style>
</head>
<body>
<div id="contain">
<div id="left"></div>
<div id="right"></div>
</div>
</body>
</html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
这篇文章主要介绍了纯Css实现Div高度根据自适应宽度(百分比)调整,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着2020-07-16- 对象height:100%并不能直接产生效果,是因为跟其父对象有关,下面有个示例为大家详细介绍下,感兴趣的朋友可以参考下2013-09-04
CSS min-height IE6、IE7、FF下DIV自适应高度
IE6、IE7、FF下DIV自适应高度2010-05-13- 翻译自Matthew James Taylor的Equal Height Columns with Cross-Browser CSS and No Hacks,有些部分根据我的理解改了,让一些初心者更好理解。2009-11-12
- 用css控制textarea文本域的高度随内容的变化而变化,不出现滚动条.2009-07-11
- 今天有人问起,晚上试着写出来,供参考; 以下代码兼容主流浏览器IE6、IE7、Firefox、Opera。 从最简单的开始………… 一、如何让一个DIV水平居2009-04-04
这篇文章主要介绍了CSS 实现高度自适应铺满整屏的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学2020-11-23


最新评论