双飞翼布局(float和flex实现)

编程入门 行业动态 更新时间:2024-10-11 01:20:29

双飞翼<a href=https://www.elefans.com/category/jswz/34/1770549.html style=布局(float和flex实现)"/>

双飞翼布局(float和flex实现)

双飞翼布局

要求

  1. 中间宽度自适应,两边宽度固定
  2. 中间栏在浏览器中优先展现渲染
    float布局实现
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<style>.parent {/*以下非必须 */overflow: hidden;color: #fff;margin-bottom: 10px;}.div-content {width: calc(100% - 400px); float: left;margin: 0 200px;/*以下非必须 */background-color: #999;}.div-left {width: 200px;margin-left: -100%;float: left;/*以下非必须 */background-color: orange;}.div-right {width: 200px;margin-left: -200px;float: left;/*以下非必须 */background-color: #999;}
</style><body><div class="parent"><div class="div-content"><ul><li>中间宽度自适应,两边宽度固定</li><li>中间栏在浏览器中优先展现渲染</li><li>这里的每一列都可以是最高列</li></ul></div><div class="div-left">我是左边</div><div class="div-right">我是右边</div></div>
</body></html>

flex布局实现(flex-shrink和order)

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<style>.flex {display: flex;justify-content: center;align-items: flex-start;}.flex-content {background-color: #999;width: 100%;order: 1;}.flex-left {background-color: orange;width: 200px;order: 0;flex-shrink: 0;}.flex-right {background-color: skyblue;width: 200px;flex-shrink: 0;order: 2;}
</style><body><div class="parent flex"><div class="flex-content"><ul><li>中间宽度自适应,两边宽度固定</li><li>中间栏在浏览器中优先展现渲染</li><li>每一列都可以是最高列</li></ul></div><div class="flex-left">我是左边</div><div class="flex-right">我是右边</div></div>
</body></html>

结果:

PS:欢迎指正

更多推荐

双飞翼布局(float和flex实现)

本文发布于:2024-03-08 13:19:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1720991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   双飞翼   flex   float

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!