我有一個相當大的注冊表單。
我想讓表單輸入在中間分開并在它大于螢屏高度時彼此相鄰使用 flex(如果這甚至是正確的方法)。
感謝您的任何幫助和輸入。
我需要添加更多文字來發布所以忽略這個
例子:
------------
| FORM |
| -------- |
| | | | when it is too large to fit completely
| | | | v
| | | | ---------------------
| | | | | FORM |
| -------- | | -------- -------- |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| -------- | | -------- -------- |
| submit | | submit |
------------ ---------------------
為我令人困惑的 CSS 感到抱歉
@font-face {
font-family: 'eau';
src: url('../fonts/eau.woff2') format('woff2'), url('../fonts/eau.woff') format('woff'), url('../fonts/eau.ttf') format('truetype');
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
--unfocused-color: rgb(238, 115, 38);
--focused-color: #ee7326;
--error-background: #ec6666;
--error-color: white;
}
html,
body {
width: 100%;
height: 100%;
}
body {
background: #eaeaea;
font-family: 'eau', sans-serif;
position: relative;
}
.container {
width: 25%;
min-width: 350px;
max-width: 50%;
height: intrinsic;
height: -webkit-fit-content;
height: -moz-max-content;
padding: 3em;
border-radius: 24px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
text-align: center;
}
form h1 {
text-transform: uppercase;
font-weight: 500;
}
a {
text-decoration: none;
color: rgb(66, 0, 219);
font-size: 80%;
}
.flex-parent {
display: flex;
flex-direction: column;
}
input[type='email'],
input[type='password'],
input[type='text'] {
background: none;
display: block;
margin: 25px auto 0 auto;
padding: 14px 10px;
width: 70%;
min-width: 100px;
text-align: center;
border: 2px solid var(--unfocused-color);
border-radius: 24px;
outline: none;
color: black;
transition: 0.25s;
}
input[type='email']:focus,
input[type='password']:focus,
input[type='text']:focus {
width: 90%;
border: 2px solid var(--focused-color);
}
input[type='submit'] {
background: none;
display: block;
margin: 25px auto 0 auto;
padding: 14px 10px;
width: 50%;
min-width: 100px;
text-align: center;
border: 2px solid var(--unfocused-color);
border-radius: 24px;
outline: none;
color: black;
transition: 0.25s;
}
input[class="password-reset-button"] { /* it breaks if i dont use [] */
width: 60%;
min-width: 120px;
padding: 0;
margin-top: 10px;
border: none;
color: rgb(66, 0, 219);
font-size: 80%;
}
p {
margin: 24px auto;
}
form .submitenabled:hover {
background-color: var(--unfocused-color);
color: white;
}
form .submitdisabled {
color: white;
border: 2px solid #6d6d6d;
background-color: #6d6d6d;
}
.error {
text-align: center;
font-size: 80%;
display: block;
margin: 30px auto 0px auto;
padding: 8px 4px;
width: 100%;
height: 20%;
background-color: var(--error-background);
color: var(--error-color);
border-radius: 24px;
}
.displayNone {
display: none;
}
<!DOCTYPE html>
<html lang="en">
<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">
<link rel="stylesheet" href="../../styles/login-signup-style.css">
<title>registreren</title>
</head>
<body>
<div class="container">
<form action="../../php/signup_handler.php" method="post" id="form">
<h1>Account registreren</h1>
<a href="../login">Inloggen</a>
<div class="flex-parent">
<div class="flex-item">
<input type="email" name="email" placeholder="Email" id="email" required>
<input type="text" name="first_name" placeholder="Voornaam" id="first_name" required>
<input type="text" name="tussenvoegsel" placeholder="Tussenvoegsels" id="tussenvoegsel" required>
<input type="text" name="last_name" placeholder="Achternaam" id="last_name" required>
</div>
<div class="flex-item">
<input type="text" name="student_nr" placeholder="Student nummer" id="student_nr" required>
<input type="text" name="class" placeholder="Klas" id="class" required>
<input type="password" name="password" placeholder="Wachtwoord" id="pwd" required>
<input type="password" name="confirmPassword" placeholder="Herhaal Wachtwoord" id="pwd2" required>
</div>
</div>
<input type="submit" value="Maak account" class="submitenabled" id="submit">
</form>
</div>
<script src="../../javascript/signup.js"></script>
</body>
</html>
uj5u.com熱心網友回復:
只需使用媒體查詢,doc。
這樣它就會切換到正常的顯示 flex,您也可以通過column在特定螢屏寬度下方添加來實作相反的方式。
@media screen and (min-width:800px){
.flex-parent{
flex-direction:row;
}
}
演示
@font-face {
font-family: 'eau';
src: url('../fonts/eau.woff2') format('woff2'), url('../fonts/eau.woff') format('woff'), url('../fonts/eau.ttf') format('truetype');
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
--unfocused-color: rgb(238, 115, 38);
--focused-color: #ee7326;
--error-background: #ec6666;
--error-color: white;
}
html,
body {
width: 100%;
height: 100%;
}
body {
background: #eaeaea;
font-family: 'eau', sans-serif;
position: relative;
}
.container {
width: 25%;
min-width: 350px;
max-width: 50%;
height: intrinsic;
height: -webkit-fit-content;
height: -moz-max-content;
padding: 3em;
border-radius: 24px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
text-align: center;
}
form h1 {
text-transform: uppercase;
font-weight: 500;
}
a {
text-decoration: none;
color: rgb(66, 0, 219);
font-size: 80%;
}
.flex-parent {
display: flex;
flex-direction: column;
}
input[type='email'],
input[type='password'],
input[type='text'] {
background: none;
display: block;
margin: 25px auto 0 auto;
padding: 14px 10px;
width: 70%;
min-width: 100px;
text-align: center;
border: 2px solid var(--unfocused-color);
border-radius: 24px;
outline: none;
color: black;
transition: 0.25s;
}
input[type='email']:focus,
input[type='password']:focus,
input[type='text']:focus {
width: 90%;
border: 2px solid var(--focused-color);
}
input[type='submit'] {
background: none;
display: block;
margin: 25px auto 0 auto;
padding: 14px 10px;
width: 50%;
min-width: 100px;
text-align: center;
border: 2px solid var(--unfocused-color);
border-radius: 24px;
outline: none;
color: black;
transition: 0.25s;
}
input[class="password-reset-button"] { /* it breaks if i dont use [] */
width: 60%;
min-width: 120px;
padding: 0;
margin-top: 10px;
border: none;
color: rgb(66, 0, 219);
font-size: 80%;
}
p {
margin: 24px auto;
}
form .submitenabled:hover {
background-color: var(--unfocused-color);
color: white;
}
form .submitdisabled {
color: white;
border: 2px solid #6d6d6d;
background-color: #6d6d6d;
}
.error {
text-align: center;
font-size: 80%;
display: block;
margin: 30px auto 0px auto;
padding: 8px 4px;
width: 100%;
height: 20%;
background-color: var(--error-background);
color: var(--error-color);
border-radius: 24px;
}
.displayNone {
display: none;
}
@media screen and (min-width:800px){
.flex-parent{
flex-direction:row;
}
}
<!DOCTYPE html>
<html lang="en">
<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">
<link rel="stylesheet" href="../../styles/login-signup-style.css">
<title>registreren</title>
</head>
<body>
<div class="container">
<form action="../../php/signup_handler.php" method="post" id="form">
<h1>Account registreren</h1>
<a href="../login">Inloggen</a>
<div class="flex-parent">
<div class="flex-item">
<input type="email" name="email" placeholder="Email" id="email" required>
<input type="text" name="first_name" placeholder="Voornaam" id="first_name" required>
<input type="text" name="tussenvoegsel" placeholder="Tussenvoegsels" id="tussenvoegsel" required>
<input type="text" name="last_name" placeholder="Achternaam" id="last_name" required>
</div>
<div class="flex-item">
<input type="text" name="student_nr" placeholder="Student nummer" id="student_nr" required>
<input type="text" name="class" placeholder="Klas" id="class" required>
<input type="password" name="password" placeholder="Wachtwoord" id="pwd" required>
<input type="password" name="confirmPassword" placeholder="Herhaal Wachtwoord" id="pwd2" required>
</div>
</div>
<input type="submit" value="Maak account" class="submitenabled" id="submit">
</form>
</div>
<script src="../../javascript/signup.js"></script>
</body>
</html>
uj5u.com熱心網友回復:
我對你的 css(在 .container 和 body 中)做了一些調整。還添加了一個媒體查詢來實作您所描述的外觀。中斷為 600 像素,但可以調整。
@font-face {
font-family: 'eau';
src: url('../fonts/eau.woff2') format('woff2'), url('../fonts/eau.woff') format('woff'), url('../fonts/eau.ttf') format('truetype');
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
--unfocused-color: rgb(238, 115, 38);
--focused-color: #ee7326;
--error-background: #ec6666;
--error-color: white;
}
html,
body {
width: 100%;
height: 100%;
}
body {
background: #eaeaea;
font-family: 'eau', sans-serif;
position: relative;
height: 100vh;
}
.container {
width: 25%;
width: 500px;
padding: 3em;
border-radius: 24px;
position: absolute;
top: 10px;
left: calc(50% - 250px);
background: white;
text-align: center;
}
form h1 {
text-transform: uppercase;
font-weight: 500;
}
a {
text-decoration: none;
color: rgb(66, 0, 219);
font-size: 80%;
}
.flex-parent {
display: flex;
flex-direction: row;
}
input[type='email'],
input[type='password'],
input[type='text'] {
background: none;
display: block;
margin: 25px auto 0 auto;
padding: 14px 10px;
width: 70%;
min-width: 100px;
text-align: center;
border: 2px solid var(--unfocused-color);
border-radius: 24px;
outline: none;
color: black;
transition: 0.25s;
}
input[type='email']:focus,
input[type='password']:focus,
input[type='text']:focus {
width: 90%;
border: 2px solid var(--focused-color);
}
input[type='submit'] {
background: none;
display: block;
margin: 25px auto 0 auto;
padding: 14px 10px;
width: 50%;
min-width: 100px;
text-align: center;
border: 2px solid var(--unfocused-color);
border-radius: 24px;
outline: none;
color: black;
transition: 0.25s;
}
input[class="password-reset-button"] {
/* it breaks if i dont use [] */
width: 60%;
min-width: 120px;
padding: 0;
margin-top: 10px;
border: none;
color: rgb(66, 0, 219);
font-size: 80%;
}
p {
margin: 24px auto;
}
form .submitenabled:hover {
background-color: var(--unfocused-color);
color: white;
}
form .submitdisabled {
color: white;
border: 2px solid #6d6d6d;
background-color: #6d6d6d;
}
.error {
text-align: center;
font-size: 80%;
display: block;
margin: 30px auto 0px auto;
padding: 8px 4px;
width: 100%;
height: 20%;
background-color: var(--error-background);
color: var(--error-color);
border-radius: 24px;
}
.displayNone {
display: none;
}
@media only screen and (max-width: 600px) {
.flex-parent {
flex-direction: column;
}
.container {
width: 350px;
top: 10px;
left: calc(50% - 175px);
}
}
<body>
<div class="container">
<form action="../../php/signup_handler.php" method="post" id="form">
<h1>Account registreren</h1>
<a href="../login">Inloggen</a>
<div class="flex-parent">
<div class="flex-item">
<input type="email" name="email" placeholder="Email" id="email" required>
<input type="text" name="first_name" placeholder="Voornaam" id="first_name" required>
<input type="text" name="tussenvoegsel" placeholder="Tussenvoegsels" id="tussenvoegsel" required>
<input type="text" name="last_name" placeholder="Achternaam" id="last_name" required>
</div>
<div class="flex-item">
<input type="text" name="student_nr" placeholder="Student nummer" id="student_nr" required>
<input type="text" name="class" placeholder="Klas" id="class" required>
<input type="password" name="password" placeholder="Wachtwoord" id="pwd" required>
<input type="password" name="confirmPassword" placeholder="Herhaal Wachtwoord" id="pwd2" required>
</div>
</div>
<input type="submit" value="Maak account" class="submitenabled" id="submit">
</form>
</div>
<script src="../../javascript/signup.js"></script>
</body>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358483.html
上一篇:帶有谷歌地圖的Z-index
下一篇:使立方體變小
