简体   繁体   English

css标签的绝对位置,但仍考虑到父宽度

[英]css label absolute position, but still taken into account for parent width

I have a flexbox layout with a div containing a label as the last item. 我有一个flexbox布局,其中div包含一个标签作为最后一项。 It has to be position: absolute . 它必须处于position: absolute Is it possible to still make the parent div expand to contain the label? 是否仍然可以使父div扩展以包含标签?

<div class='container'>
  <div class="item">flex1</div>
  <div class="item">flex2</div>
  <div class="item no-flex">
    <div>
        <label>nfdfesrsawe</label>
    <div>
  </div>
</div>

.container{ 
   width: 100%;
   display: flex;
   background-color: red;
  justify-content: space-between
}

.item {
  border: solid black 1px;
  flex: 1;
}

.no-flex {
  flex: 0
}

label {
  position: absolute;
}

https://codepen.io/anon/pen/yozvwx https://codepen.io/anon/pen/yozvwx

EDIT: simplified example: 编辑:简化示例:

<div class='container'>
    <label>Make the container fit around me, please</label>
<div>

.container{ 
   background-color: red;
}

label {
  position: absolute;
}

I need to work with this because the absolute positioning is defined by another framework (vuetify) and I can only try to fix it via css and not html changes 我需要使用它,因为绝对定位是由另一个框架(vuetify)定义的,我只能尝试通过CSS而不是html更改来修复它

In short no. 简而言之,没有。

Anything other than a flex child will not respond to flex as when you make something position:absolute you force it to be block not flex . 除了flex child元素外,其他任何东西都不会对flex做出响应,就像您在某个position:absolute做出的那样position:absolute将其强制为非flex block

Check an answer I have gave before regarding Flex Box's 检查我之前就Flex Box给出的答案

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

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