<small id='7RG2U'></small><noframes id='7RG2U'>

<tfoot id='7RG2U'></tfoot>

      <bdo id='7RG2U'></bdo><ul id='7RG2U'></ul>
    <i id='7RG2U'><tr id='7RG2U'><dt id='7RG2U'><q id='7RG2U'><span id='7RG2U'><b id='7RG2U'><form id='7RG2U'><ins id='7RG2U'></ins><ul id='7RG2U'></ul><sub id='7RG2U'></sub></form><legend id='7RG2U'></legend><bdo id='7RG2U'><pre id='7RG2U'><center id='7RG2U'></center></pre></bdo></b><th id='7RG2U'></th></span></q></dt></tr></i><div id='7RG2U'><tfoot id='7RG2U'></tfoot><dl id='7RG2U'><fieldset id='7RG2U'></fieldset></dl></div>
    <legend id='7RG2U'><style id='7RG2U'><dir id='7RG2U'><q id='7RG2U'></q></dir></style></legend>
    1. img 设置 flex-grow 填充 flex 容器剩余空间,导致 flex 内部溢出 flex 容器

      时间:2023-09-07
      <i id='spIUO'><tr id='spIUO'><dt id='spIUO'><q id='spIUO'><span id='spIUO'><b id='spIUO'><form id='spIUO'><ins id='spIUO'></ins><ul id='spIUO'></ul><sub id='spIUO'></sub></form><legend id='spIUO'></legend><bdo id='spIUO'><pre id='spIUO'><center id='spIUO'></center></pre></bdo></b><th id='spIUO'></th></span></q></dt></tr></i><div id='spIUO'><tfoot id='spIUO'></tfoot><dl id='spIUO'><fieldset id='spIUO'></fieldset></dl></div>
      • <bdo id='spIUO'></bdo><ul id='spIUO'></ul>
        1. <tfoot id='spIUO'></tfoot>

          <small id='spIUO'></small><noframes id='spIUO'>

          <legend id='spIUO'><style id='spIUO'><dir id='spIUO'><q id='spIUO'></q></dir></style></legend>

              <tbody id='spIUO'></tbody>

                本文介绍了img 设置 flex-grow 填充 flex 容器剩余空间,导致 flex 内部溢出 flex 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                以下是我的代码,text1";溢出 flex 容器,我希望 flex 容器中的 img + text 和 img 填充 flex 容器休息

                following is my code, "text1" overflow the flex container, I expect img + text in flex container and img fill flex container rest

                <!DOCTYPE html>
                <html lang="en">
                <head>
                    <meta charset="utf-8">
                    <!--mobile friendly-->
                    <meta name="viewport" content="width=device-width, user-scalable=yes">
                    <style>
                        .c {
                            display: flex;
                            flex-direction: column;
                            width: 100px;
                            height: 100px;
                            border: 5px solid lightblue;
                        }
                
                        .c img {
                            flex-grow: 1;
                            object-fit: contain;
                        }
                    </style>
                </head>
                <body>
                <div class="c">
                    <img src="./img.jpg"/>
                    <div>text1</div>
                </div>
                </body>
                </html>
                

                结果是:

                如果元素不是 img 并且是 div,flex-grow: 1 将填充 flex rest 空间,我很困惑为什么 img 会导致内部溢出

                if element is not img and is div, flex-grow: 1 will fill flex rest space, I'm confused why img cause inner overflow

                以下是我的img.jpg"

                following is my "img.jpg"

                推荐答案

                /* CSS */
                
                .c {
                  width: 100px;
                  height: 100px;
                  border: 5px solid lightblue;
                  position: relative;
                  text-align: center;
                }
                .c img {
                  width: 100%;
                }
                .c div {
                  position: absolute;
                  top: 50%;
                  left: 50%;
                  transform: translate(-50%, -50%);
                  color: red;
                }

                <!-- HTML -->
                
                <!DOCTYPE html>
                <html lang="en">
                  <head>
                    <meta charset="utf-8">
                    <meta name="viewport" content="width=device-width, user-scalable=yes">
                  </head>
                  <body>
                    <div class="c">
                      <img src="https://i.stack.imgur.com/P5N3A.jpg" />
                      <div>text1</div>
                    </div>
                  </body>
                </html>

                这篇关于img 设置 flex-grow 填充 flex 容器剩余空间,导致 flex 内部溢出 flex 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:真的有必要制作和使用新的自定义元素和 Web 组件(HTML 标签)吗? 下一篇:vscode“智能感知"和“转到定义"对于非 js/ts 文件

                相关文章

                <i id='oiyuV'><tr id='oiyuV'><dt id='oiyuV'><q id='oiyuV'><span id='oiyuV'><b id='oiyuV'><form id='oiyuV'><ins id='oiyuV'></ins><ul id='oiyuV'></ul><sub id='oiyuV'></sub></form><legend id='oiyuV'></legend><bdo id='oiyuV'><pre id='oiyuV'><center id='oiyuV'></center></pre></bdo></b><th id='oiyuV'></th></span></q></dt></tr></i><div id='oiyuV'><tfoot id='oiyuV'></tfoot><dl id='oiyuV'><fieldset id='oiyuV'></fieldset></dl></div>

                <small id='oiyuV'></small><noframes id='oiyuV'>

                  <bdo id='oiyuV'></bdo><ul id='oiyuV'></ul>
                1. <tfoot id='oiyuV'></tfoot>

                  1. <legend id='oiyuV'><style id='oiyuV'><dir id='oiyuV'><q id='oiyuV'></q></dir></style></legend>