【前端】CSS宽度适应内容;width: fit-content;

DOCTYPE html>
<html lang="zh-CN">

<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>宽度适应内容title>
    <style>
        /* .news-container {
            display: flex;
            flex-direction: column;
            align-items: start;
        } */

        .news-type {
            background: #334e70;
            padding: 5px 8px;
            color: rgb(255, 255, 255, 0.8);
            font-size: 1em;
            border-radius: 5px;
            font-weight: 400;
            display: flex;
            align-items: center;
            /* 宽度适应内容 */
            width: fit-content;
        }
    style>
head>

<body>
    <div class="news-container">
        <div class="news-type">
            <span>更多话题span>
            <a href="">更多a>
        div>
        <div class="news-list">div>
    div>
body>

html>

效果:
在这里插入图片描述

你可能感兴趣的:(CSS,css,前端,html)