我正在用HTML和CSS制作一些"卡片",我有一个容器,又名.父母div:

 .resources {
        display: flex;
        background-color: #000000;
        margin-top: 1vh;
        padding: 8px 8px 0px 8px;
        flex-direction: column;
        border-radius: 5px;
    }



    .resources .resource {
        width: 100%;
        height: auto;
        display: flex;
        margin: auto;
        margin-bottom: 8px;
        cursor: pointer;
        background-color: #010101;
        padding: 5px 5px 5px 5px;
        border-radius: 5px;
    }



    .resources .resource .icon {
        width: 4vh;
        height: 4vh;
        border-radius: 5px;
        margin: auto;
    }
    
    .resources .resource .text {
        text-align: left;
        margin-left: 5px;
        float: left;
        
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        width: 90%;
    }
    
    .resources .resource .text h6 {
        font-size: 13px;
        color: #ffffff;
    }
    
    .resources .resource .text p {
        font-size: 12px;
        color: #ffffff;
    }
<div class="resources">
      <div class="resource">
          <img class="icon" src="...">
             <div class="text">
              <h6>title</h6>
              <p>lorem ipsum</p>
            </div>
      </div>
</div>

基本上一切正常.这就是我所知道的:

enter image description here

但是,子卡(资源)的末尾与父div(资源)重叠,我不希望它溢出,我希望它具有相同的填充,并留在父div中.类似于:

enter image description here

希望这对任何提前提供帮助的人都有意义.

推荐答案

你只需要删除margin:autowidth:100%表单.resources .resource,就像这样(红色边框只是为了有一些视觉效果)

.resources {
    display: flex;
    background-color: #000000;
    margin-top: 1vh;
    padding: 8px 8px 0px 8px;
    flex-direction: column;
    border-radius: 5px;
}
.resources .resource {
    height: auto;
    display: flex;
    margin-bottom: 8px;
    cursor: pointer;
    background-color: #010101;
    padding: 5px 5px 5px 5px;
    border-radius: 5px;
  border:1px solid red;
}
.resources .resource .icon {
    width: 4vh;
    height: 4vh;
    border-radius: 5px;
    margin: auto;
}

.resources .resource .text {
    text-align: left;
    margin-left: 5px;
    float: left;
    
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    width: 90%;
}

.resources .resource .text h6 {
    font-size: 13px;
    color: #ffffff;
}

.resources .resource .text p {
    font-size: 12px;
    color: #ffffff;
}
<div class="resources">
      <div class="resource">
          <img class="icon" src="https://images.unsplash.com/photo-1633332755192-727a05c4013d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80">
             <div class="text">
              <h6>title</h6>
              <p>lorem ipsum</p>
            </div>
      </div>
</div>

Html相关问答推荐

如何阻止Chromecast图标出现在HTML5视频

为什么前端框架可以创建自定义属性,而我却被期望在挖掘之前添加数据

更改Angular 为17的material Select 字段的高度?

在弹性框布局中的第n个元素后强制换行

从html文件中提取元素的Python BeautifulSoup

如何使活动选项卡背景作为父背景图像

嵌入最近的 YOUTUBE 视频(不是短片,视频)

jQuery 索引返回不正确的结果

为 HTML5 文本字段设置最后六位正则表达式模式

为什么 Flexbox 中相邻元素上的 flex:1 会影响另一个元素的固定宽度?

子元素放在文本样式之后,样式会 destruct

为什么每当我调整图片大小时它都会使我的其他元素移动

如何通过像图像一样的 元素来调整 SVG 图标的大小

HTML、CSS设计图像出格

从垫分页器中删除输入边框

在shiny 的应用程序中使用图标功能时出错

如何通过可见文本使用 Selenium 定位元素

将 div 放在图片旁边而不是下方

使用 TailwindCSS 将徽标放在左上角,将菜单放在右上角

我正在try 向我预先存在的导航栏添加响应式汉堡包导航,但由于某种原因它没有显示