简体   繁体   English

有没有办法拉伸包裹在 inline-flex 中的块以匹配父 div 宽度?

[英]Is there anyway to stretch a block wrapped in an inline-flex to match parent div width?

EDIT: This is the effect that I'm looking for.编辑:这是我正在寻找的效果。

在此处输入图像描述

I apologize if the question is worded a bit strangely, but essentially, I have two blocks (one div, one icon) inside a div, which is inside another parent div whose width is dynamically adjusted depending on the width of the text.如果问题的措辞有点奇怪,我深表歉意,但本质上,我在一个 div 内有两个块(一个 div,一个图标),它位于另一个父 div 内,其宽度根据文本的宽度动态调整。 Basically, I want the icon to remain both inline with the other div, and also be right aligned every time the parent div expands.基本上,我希望图标与另一个 div 保持内联,并且每次父 div 展开时都右对齐。 How can I achieve this?我怎样才能做到这一点?

HTML HTML

 .message, .other-message{ border-radius: 15px; padding: 10px; color: white; max-width: 50%; }.other-message { background-color: gray; margin: 10px auto 10px 10px; }.message { background-color: blue; margin: 5px 10px 10px auto; }.date, .username { color: rgb(200, 200, 200); padding: 5px; font-size: 80%; }.date-and-comment-removal{ display: inline-flex; }.date-and-comment-removal > i{ margin-right: 0; }.date-and-comment-removal > i:hover{ cursor: pointer; }.date-and-comment-removal >.date{ margin-right: auto; }
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css"> <div class="message">nothing much <div class="username">nisey</div> <div class="date">2021-03-04 3:52 AM</div> </div> <div class="other-message">hey, what's up? Pharetra magna ac placerat vestibulum lectus. Tortor id aliquet lectus proin. Felis donec et <div class="username">darienmiller88</div> <div class="date-and-comment-removal"> <div class="date">2021-03-04 3:52 AM</div> <i class="bi bi-three-dots-vertical"></i> </div> </div>

The three ellipses I want to expand to the right, and remain right aligned every time the message block expands due to a longer message.我想向右扩展的三个椭圆,并且每次消息块由于更长的消息而扩展时保持右对齐。 What should I add or change?我应该添加或更改什么?

You can add width: 100% to the .date-and-comment-removal and it does what you want.您可以将width: 100%添加到.date-and-comment-removal并执行您想要的操作。

 .message, .other-message { border-radius: 15px; padding: 10px; color: white; max-width: 50%; }.other-message { background-color: gray; margin: 10px auto 10px 10px; }.message { background-color: blue; margin: 5px 10px 10px auto; }.date, .username { color: rgb(200, 200, 200); padding: 5px; font-size: 80%; }.date-and-comment-removal { width: 100%; display: inline-flex; }.date-and-comment-removal>i { margin-right: 0; }.date-and-comment-removal>i:hover { cursor: pointer; }.date-and-comment-removal>.date { margin-right: auto; }
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css"> <div class="message">nothing much <div class="username">nisey</div> <div class="date">2021-03-04 3:52 AM</div> </div> <div class="other-message">hey, what's up? Pharetra magna ac placerat vestibulum lectus. Tortor id aliquet lectus proin. Felis donec et <div class="username">darienmiller88</div> <div class="date-and-comment-removal"> <div class="date">2021-03-04 3:52 AM</div> <i class="bi bi-three-dots-vertical"></i> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM