css列表示例&flex布局子元素超出父容器宽度问题

css列表示例

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        @import url('//at.alicdn.com/t/c/font_3916097_p205l52oy7.css');
        ul,li,body {
            margin: 0;
            padding: 0;
        }
        
        ul li {
            display: flex;
            justify-content: space-between;
            padding: 0 10px;
            line-height: 32px;
            width: 260px;
            background-color: rgb(236, 255, 231);
            /* height: 32px; */
            box-sizing: border-box;
            margin-bottom: 10px;
        }
        .title {
            /* max-width: 250px; */
            text-overflow: ellipsis;
            white-space: nowrap; /* white-space属性为nowrap时,不会因为超出容器宽度而发生换行 */
            overflow: hidden;
            cursor: pointer;
        }
        .num {
            flex-shrink: 0;
            /* flex-grow: 1; */
            margin-left: 15px;
            user-select: none;
        }
    </style>
</head>
<body>
    
    <ul>
        <li>
            <div class="title">
                <i class="iconfont icon-dongtai"></i>
                <span>我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车我的风车</span>
            </div>
            <span class="num">
                1000000篇
            </span>
        </li>
    </ul>
</body>
</html>

flex布局子元素超出父容器宽度问题处理

使用flex布局,右边文字过长,子元素直接就超过了父元素的宽度
在这里插入图片描述

flex布局中 子元素宽度超出父元素导致样式问题

我们希望达到的是下面的效果
在这里插入图片描述

<style>
/* 还是用scss的代码看吧, 用原生css不方便看 */
.blog-info {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-radius: 5px;
    margin-bottom: 10px;
    background-color: #fff;
    box-shadow: 0 3px 10px 0px rgba(0, 0, 0, .1);

    .cover {
        width: 110px;
        height: 110px;
        margin-right: 12px;

        border: 1px solid red;

        object-fit: cover;

        &>a {
            width: 100%;
            height: 100%;
            overflow: hidden;
            display: inline-flex;
        }

        img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: all .36s;
            &:hover {
                transform: scale(1.2);
            }
        }
    }

    .article {

        border: 1px solid red;

        flex: 1;
        /* 以下任意设置一个都可以 */
        overflow: hidden;
        /* width: 0; */

        .title {
            margin-bottom: 6px;

            border: 1px solid red;


            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;

            a {
                color: #2498ff;
                font-size: 18px;
            }
        }

        .summary {
            height: 60px;
            margin-bottom: 10px;

            border: 1px solid red;


            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
        }

        .article-extra-info {
            font-size: 13px;
            color: #82868e;

            border: 1px solid red;


            span {
                margin-right: 12px;
            }

            a {
                color: #1890ff;
            }
        }
    }
}
</style>

<div style="width:810px;margin: 0 auto;border:1px solid red">

   <div class="blog-info">
   
    	<!-- 左边图片封面 -->
       <div class="cover">
           <a href="#">
               <img src="http://127.0.0.1:3003/api/file/getImage/202303/wqfqXLDfIbhlhrtKoWMBDuqwQHoOzO.png" alt="">
           </a>
       </div>
       
        <!-- 右边文章盒子 -->
       <div class="article">
       
            <div class="title">
                <a href="#">好的文章好的文章好的文章好的文章好的文章好的文章好的文章好的文章好的文章好的文章</a>
            </div>
            
            <div class="summary">
                111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
            </div>
            
            <div class="article-extra-info">
                <span class="time">202-03-03 12:22:33</span>
                <span>作者: <a href="#">zzhua</a></span>
                <span>分类专栏: <a href="#">spring</a></span>
            </div>
            
        </div>
        
   </div>
</div>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值