CSS两个div彼此相邻

编程入门 行业动态 更新时间:2024-10-17 09:42:37
本文介绍了CSS两个div彼此相邻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想把两个< div> 放在一起。正确的< div> 约为200像素;左侧< div> 必须填满屏幕宽度的其余部分吗?

解决方案

您可以使用 flexbox 以展示您的项目:

#parent {display:flex;}#narrow {width:200px;背景:lightblue; / *只是这样可见* /}#wide {flex:1; / *生长到容器的休息* / background:lightgreen; / *只是这样可见* /}

< div id =parent> < div id =wide> Wide(其余宽度)< / div> < div id =narrow> Narrow(200px)< / div>< / div>

这基本上只是削减flexbox的表面。

对于旧版浏览器支持,您可以使用CSS float 和 width 属性来解决它。

#narrow {float:right; width:200px; background:lightblue;}#wide {float:left; width:calc(100% - 200px); background:lightgreen;}

< div id =parent > < div id =wide> Wide(其余宽度)< / div> < div id =narrow> Narrow(200px)< / div>< / div>

I want to put two <div>s next to each other. The right <div> is about 200px; and the left <div> must fill up the rest of the screen width? How can I do this?

解决方案

You can use flexbox to lay out your items:

#parent { display: flex; } #narrow { width: 200px; background: lightblue; /* Just so it's visible */ } #wide { flex: 1; /* Grow to rest of container */ background: lightgreen; /* Just so it's visible */ }

<div id="parent"> <div id="wide">Wide (rest of width)</div> <div id="narrow">Narrow (200px)</div> </div>

This is basically just scraping the surface of flexbox. Flexbox can do pretty amazing things.

For older browser support, you can use CSS float and a width properties to solve it.

#narrow { float: right; width: 200px; background: lightblue; } #wide { float: left; width: calc(100% - 200px); background: lightgreen; }

<div id="parent"> <div id="wide">Wide (rest of width)</div> <div id="narrow">Narrow (200px)</div> </div>

更多推荐

CSS两个div彼此相邻

本文发布于:2023-11-29 21:29:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647673.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   CSS   div

发布评论

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

>www.elefans.com

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