gpt4 book ai didi

html - 如何开始使用 flex?

转载 作者:行者123 更新时间:2023-11-28 01:43:07 25 4
gpt4 key购买 nike

我希望我的“p”与中心对齐,“#fname label”获得 1/3 的空间,“#fname input”获得 2/3和下一行#mail 相同。

现在所有东西都被打乱了,并且在同一行,

我的 codepen和我的代码:

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


/* styles to make borders not take on extra space */

* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

html {
overflow-y: scroll;
/* fix for the scrollbar push issue */
width: 100%;
height: 100%;
}

body {
width: 100%;
height: 100%;
}


/* Browser style reset so they all play nice */

html,
body,
div,
span,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
abbr,
address,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
samp,
small,
strong,
sub,
sup,
var,
b,
i,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
time,
mark,
audio,
video {
font-size: 100%;
margin: 0;
padding: 0;
outline: 0 none;
vertical-align: baseline;
}


/* Now we Starting to code */

body {
background-color: #F7FBCC;
}

#title {
text-align: center;
font-size: 40pt;
color: #1A1A1A;
font-family: 'Chivo', sans-serif;
margin-top: 40px;
margin-bottom: 40px;
}

.container {
background-color: #fff;
display: flex;
flex-flow: row wrap;
flex border-radius: 8px;
box-shadow: 0px 2px 8px rgba(29, 31, 32, 0.2);
}

#description {
color: #1a1a1a;
flex: 1;
justify-content: center;
padding-top: 16px;
margin-bottom: 40px;
}

#fname {
display: flex;
flex-flow: row wrap;
margin-top: 40px;
margin-left: 40px;
}

#fname label {
flex: 1;
}

#fname input {
flex: 2;
}

#mail {
display: flex;
flex-flow: row wrap;
margin-top: 40px;
margin-left: 40px;
}

#mail label {
flex: 1;
}

#email input {
flex: 2;
}
<head>

<link href="https://fonts.googleapis.com/css?family=Chivo|Roboto" rel="stylesheet">

<meta charset="UTF-8">

</head>

<header>
<div id="title">
<h1> Music - Survey Form </h1>
</div>
</header>

<body>


<form>

<div class="container">

<div id="description">
<p> Let us know what kind of music you like</p>
</div>

<div id="fname">
<label for="name"> Full Name: </label>
<input type="text" id="name" placeholder="What's your name" required>

</div>

<div id="mail">
<label for="email"> Email address: </label>
<input type="text" id="email" placeholder="What's your email" required>

</div>


-->


</div>
<!-- Closing div-container -->
</div>
</body>

附上

如果你能告诉我是否有我可以去掉的线条,请告诉我

谢谢大家先进:)

最佳答案

首先,您的容器似乎可以是基于列的 flex 布局,因为您希望所有内容都堆叠起来。唯一并排的元素是标签和输入对,因此您可以调整它们。标记保持原样,这些是您可以对 CSS 进行的调整:

.container {
background-color: #fff;
display: flex;
flex-direction: column;
box-shadow: 0px 2px 8px rgba(29, 31, 32, 0.2);
}

#title {
text-align: center;
font-size: 40pt;
color: #1A1A1A;
font-family: 'Chivo', sans-serif;
margin-top: 40px;
margin-bottom: 40px;
}

#description {
text-align: center;
color: #1a1a1a;
padding-top: 16px;
margin-bottom: 40px;
}

#fname,
#mail {
display: flex;
margin-top: 40px;
margin-left: 40px;
}

#fname label,
#mail label {
width: 33%;
}

#fname input,
#mail input {
width: 100%;
}

编辑:添加替代基于百分比的宽度。我选择使用基于百分比的宽度,因为您要求列为 1/3,并且通常是因为我相信它更具可读性。 flex 和 flex-grow 的组合虽然效果很好,但总的来说我觉得百分比更具可读性和可预测性。

#fname label,
#mail label {
flex: 1;
}

#fname input,
#mail input {
flex-grow: 2;
}

CodePen 分支:https://codepen.io/88mpg/pen/PeBpmm

关于html - 如何开始使用 flex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50334961/

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