gpt4 book ai didi

css - 没有父元素的 100% 宽度

转载 作者:太空宇宙 更新时间:2023-11-04 07:55:52 25 4
gpt4 key购买 nike

我有点困惑。我正在构建一个待办事项列表应用程序,我正在尝试将标题设置为屏幕宽度的 100%。我相信我有正确的元标记,但将标题设置为 100% 宽度会将元素拉伸(stretch)到屏幕右侧。我做错了什么吗?

<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo List App</title>

<link rel="stylesheet" text="text/css" href="style.css">


</head>
<body>
<header>

<input type="text" placeholder="Enter an activity...">

<button></button>

</header>
</body>
</html>

@charset "UTF-8";

header {
width: 100%;
height: 80px;
position: fixed;
padding: 15px;
top: 0px;
left: 0px;
z-index: 5;
background: #25b99a;
box-shadow:0px 2px 4px rgba(44, 62, 80, 0.15);
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}

header input {
width: 100%;
height: 50px;
float: left;
background: rgba(255,255,255,0.2);
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-radius: 5px;
border: 0px;
box-shadow: none;
outline: none;
}

最佳答案

您需要包含 box-sizing 属性。

Info from MDN

html {
box-sizing: border-box;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
}

header {
width: 100%;
height: 80px;
position: fixed;
padding: 15px;
top: 0px;
left: 0px;
z-index: 5;
background: #25b99a;
box-shadow: 0px 2px 4px rgba(44, 62, 80, 0.15);
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}

header input {
width: 100%;
height: 50px;
float: left;
background: rgba(255, 255, 255, 0.2);
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-radius: 5px;
border: 0px;
box-shadow: none;
outline: none;
}
<header>
<input type="text" placeholder="Enter an activity...">
<button></button>
</header>

关于css - 没有父元素的 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47331907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com