Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

[CSS面试题] 如何使得左右两边没有确定宽度的元素保持其中文本的自适应

image.png

需要实际的代码, 而不是解题思路 :

<div class="bg">
    <div>
        <span>文案文案文案文案文案文案文案文案文案文案文案文案文案文案</span>
    </div>
    
    <div>
        <button>按钮按钮</button>
    </div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

我也来试试 :

<style type="text/css">
    .bg {
        display: flex;
        justify-content: space-between;
        width: 440px;
        background-color: beige;
        align-items: center;
    }


    img {
        width: 44px;
        height: 44px;
    }

    .left {
        flex: 1;
    }

    .right {
        flex: none;
    }
</style>

其中, html为 :

<div class="bg">
    <img src="https://sponsor-static.ostack.cn/a0178ced5d32d23e1e29fe810c91de02.jpg" alt="">
    <div class="left">
        <span>文案文案文案文案文案文案文案文案</span>
    </div>

    <div class="right">
        <button>按钮按钮</button>
    </div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...