文本在缩放时转出flex容器

时间:2019-04-16 10:05:41

标签: html css flexbox

嗨,我正在尝试创建一个用户卡类型div,该卡左侧有一些图像,右侧有用户名。我可以完成布局,但是在缩放时,文本溢出并且逃脱了flex容器。这是我的代码。 And this is the ouptut(Try zooming in by ctrl +)

<div style="
       border: 1px solid #775CD0; 
       display:flex;
       width:20%;
       border-radius:4px;
       ">
  <img src="https://picsum.photos/200/300
    " height="30" width="30" style="  
          align-self:start;
          margin-left:10px;
          padding-top:2px;
          padding-bottom:2px;
          ">
  <img src="https://picsum.photos/200/300/?random
    " class="image2" height="18px" width="18px" style="
          align-self:start;
          margin-top:18px;
          margin-left:-15px;
          ">
  <span class="account-name" style="
          margin-top:6px;
          padding-left:22px;
          ">
       GonFreecks
       </span>
</div>

1 个答案:

答案 0 :(得分:1)

减小宽度并使用display:inline-flex;

<div style="
   border: 1px solid #775CD0; 
   display:inline-flex;
   
   border-radius:4px;
   ">
   <img src="https://picsum.photos/200/300
" height="30" width="30" 
      style="  
      align-self:start;
      margin-left:10px;
      padding-top:2px;
      padding-bottom:2px;
      "
      >
   <img src="https://picsum.photos/200/300/?random
" class="image2" height="18px" width="18px" 
      style="
      align-self:start;
      margin-top:18px;
      margin-left:-15px;
      ">
   <span class="account-name"
      style="
      margin-top:6px;
      padding-left:22px;
      ">
   GonFreecks
   </span>
</div>