固定位置更改容器宽度

Fre*_* J. 2 html css

我试图阻止标题元素滚动,所以我给它position: fixed但是根据下面的第二个图像改变它的大小.
我正在使用CSS来维护第一个图像的外观并防止标题滚动.谢谢

在此输入图像描述

html, body {
    height: 100%;
    padding: 0;
    margin: 0;
}

button {
    height: 1.5em;
    width: 1.5em;
    font-size: 1.5em;
    top: 0;
}

label {
    display: inline-block;
    width: calc(100% - 5em);
    text-align: center;
}

header {
    border-bottom: 1px solid black;
    background-color: yellow;
    position: fixed;
}
Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
    <meta name="viewport" content="width=device-width" />
</head>

<body >
<header>
    <button class="menuLeft" type="button" >&#9776;</button>
    <label>Title of Page</label>
    <button class="menuRight" type="button">&#8942;</button>
</header>


</body>
</html>
Run Code Online (Sandbox Code Playgroud)

ket*_*tan 6

只是给width:100%头部.

html, body {
    height: 100%;
    padding: 0;
    margin: 0;
}

button {
    height: 1.5em;
    width: 1.5em;
    font-size: 1.5em;
    top: 0;
}

label {
    display: inline-block;
    width: calc(100% - 5em);
    text-align: center;
}

header {
    border-bottom: 1px solid black;
    background-color: yellow;
    position: fixed;
  width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
    <meta name="viewport" content="width=device-width" />
</head>

<body >
<header>
    <button class="menuLeft" type="button" >&#9776;</button>
    <label>Title of Page</label>
    <button class="menuRight" type="button">&#8942;</button>
</header>


</body>
</html>
Run Code Online (Sandbox Code Playgroud)