LoginSignup
0
0

【CSSTips】横並び配置で2つ目の要素は1つ目の残り全ての横幅

Posted at

はじめに

左側のスペースに合わせて右側は残り全部という事はよくあるのですが、CSSを実際にかけない事があったので、メモ程度に残しておきます。

スクリーンショット 2023-11-28 20.34.26.png

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>Flex Wrap Sample</title>
</head>
<body>
    <div class="flex-wrap">
        <div class="left-column">左側</div>
        <div class="right-column">右で残り</div>
    </div>
    <div class="flex-wrap">
        <div class="left-column" style="width: 100px;">左側</div>
        <div class="right-column">右で残り</div>
    </div>
    <div class="flex-wrap">
        <div class="left-column" style="width: 200px;">左側</div>
        <div class="right-column">右で残り</div>
    </div>
    <div class="flex-wrap">
        <div class="left-column" style="width: 50px;">左側</div>
        <div class="right-column">右で残り</div>
    </div>
</body>
</html>
styles.css
.flex-wrap{
    display: flex;
    outline: auto;
}
.left-column{
    white-space: nowrap;
    background-color: #ccc;
    outline: auto;
    padding: 10px;
}
.right-column{
    width: 100%;
    background-color: #eee;
    padding: 10px;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0