在浮动(或行内块)父级内均匀分配div(Evenly distribute divs horizontally within floated(or inline

编程入门 行业动态 更新时间:2024-10-10 11:27:49
在浮动(或行内块)父级内均匀分配div(Evenly distribute divs horizontally within floated(or inline-block) parent)

我试图平均分配他们的父母中的子项目。 我知道text-align:justify和flex方法 - 我目前使用flex方法。

问题是,我的布局(左边的float:left标识[红色] float:left或display:inline-block ,右边的按钮[black]和float:right )需要flex父div为float:left或display:inline-block (以便它位于徽标和按钮之间),但浮动或显示内嵌块会打破我为孩子们应用的柔性分布。

这里是我到目前为止的CodePen: http ://codepen.io/dmoz/pen/QKaQrL

这是我需要的图像:

有任何想法吗?

I'm trying to horizontally distribute child items evenly within their parent. I'm aware of the text-align:justify and flex methods—I'm currently using the flex method.

The problem is that my layout(a logo[red] to the left that's float:left or display:inline-block and a button[black] that's to the right and float:right) requires that the flex parent div be float:left or display:inline-block(so that it sits between the logo and the button), but floating or displaying inline-block breaks the flex distribution I have applied for the kids.

Here's a CodePen of where I'm at so far: http://codepen.io/dmoz/pen/QKaQrL

This is an image of what I need:

Any ideas?

最满意答案

我更新了你的CSS。 检查小提琴: https : //jsfiddle.net/Lq89dwxL/

.header { display: flex; width: 100%; height: 100px; background: #f5f5f5; margin: 0; padding: 0 10px; overflow: auto; } .logo { width: 100px; height: 30px; margin: 8px 50px 10px 0; background: red; } button { width: 30px; height: 30px; margin: 8px 0 0 50px; border: none; background: black; } .item_container { width:100%; display: flex; justify-content: space-between; padding: 0 55px 0 15px; } .item { width:25px; height: 30px; background: blue; margin: 8px 5px; }

I updated your CSS. Check the Fiddle: https://jsfiddle.net/Lq89dwxL/

.header { display: flex; width: 100%; height: 100px; background: #f5f5f5; margin: 0; padding: 0 10px; overflow: auto; } .logo { width: 100px; height: 30px; margin: 8px 50px 10px 0; background: red; } button { width: 30px; height: 30px; margin: 8px 0 0 50px; border: none; background: black; } .item_container { width:100%; display: flex; justify-content: space-between; padding: 0 55px 0 15px; } .item { width:25px; height: 30px; background: blue; margin: 8px 5px; }

更多推荐

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

发布评论

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

>www.elefans.com

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