css 我的表单内容并不完全可见

tvokkenx  于 2023-04-13  发布在  其他
关注(0)|答案(3)|浏览(144)

我是一个CSS初学者,我试图使用Flexbox创建一个表单。然而,我面临着一个问题,我的内容无法完全显示。目前,当在平板电脑或桌面上查看网站时,标题表单不可见。在移动的视图上的情况更糟,因为一些输入字段不可见。尽管是可滚动的。你能帮我确定我的代码中缺少了什么吗?
HTML:

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Us</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <section id="registration-page">
        <form class="signup-form">  
            <div class="form-header">
                <h1>Create Account</h1>
            </div>
          <div class="form-body">
            <div class="row">
              <div class="input-group">
                <label>First name </label>
                <input type="text" placeholder="Enter your first name">
              </div>
              <div class="input-group">
                <label>Last name</label>
                <input type="text" placeholder="Enter your last name">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Email </label>
                <input type="email" placeholder="Enter your email address">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Password </label>
                <input type="password" placeholder="Enter your your password">
              </div>
              <div class="input-group">
                <label>Confirm Password</label>
                <input type="password" placeholder="Enter your password again">
              </div>
            </div>

              
            <div class="row">
              <div class="input-group">
                <label for="">Gender</label>
            
                <div class="radio-group">
            
                  <div>
                    <label for="male">
                      <input type="radio" name="gender" id="male">
                      Male
                    </label>
                  </div>
            
                  <div>
                    <label for="female">
                      <input type="radio" name="gender" id="female">
                      Female
                    </label>
                  </div>
            
                  <div>
                    <label for="other">
                      <input type="radio" name="gender" id="other"> Other
                    </label>
                  </div>
            
                </div> <!-- .radio-group -->
              </div> <!-- .input-group -->
            

              <div class="input-group">
                <label for="">Hobbies</label>
                <div class="checkbox-group">
                  <div>
                    <label for="music">
                      <input type="checkbox" name="hobbies" id="music">
                      Music
                    </label>
                  </div>
             
                  <div>
                    <label for="cooking">
                      <input type="checkbox" name="cooking" id="cooking">
                      Cook
                    </label>
                  </div>
             
                  <div>
                    <label for="travel">
                      <input type="checkbox" name="travel" id="travel">
                      Travel
                    </label>
                  </div>
             
                  <div>
                    <label for="movies">
                      <input type="checkbox" name="movies" id="movies">
                      Movie
                    </label>
                  </div>
                </div>

                </div> <!-- .checkbox-group -->
              </div><!-- .input-group -->
              
              
              <div class="row"> 
                <div class="input-group">
                  <label for="">Source of Income</label>
                  <select>
                    <option>Employed</option>
                    <option>Self-Employed</option>
                    <option>Unemployed</option>
                  </select>
                </div>
                <div class="input-group">
                  <label>Income</label>
                  <div class="range-group">
                    <input type="range" min="0" max="100" value="10" oninput="rangeValue.innerText = this.value">
                    <label id="rangeValue">10</label>
                  </div>
                </div>
              </div>
              
              <div class="row">
                <div class="input-group">
                  <label>Upload Profile Picture</label>
                  <input type="file">
                </div>
                <div class="input-group">
                  <label>Age</label>
                  <input type="number">
                </div>
              </div>

              <div class="row">
                <div class="input-group">
                  <label for="">Bio</label>
                  <textarea> </textarea>
                </div>
              </div>

              <div class="form-footer">
                <button class="btn">Create</button>
              </div>

          </div>

        </form> 
    
</section>

</body>

CSS:

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;

}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

html {
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
    font-family: 'Roboto', sans-serif;
    font-weight: bold;
    height: 100vh;
}

#registration-page {
    height: 100vh;
    background: #78a7ba; 
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: scroll;
}

.signup-form {
    flex: 1;
    max-width: 600px;
    background-color: #EFF0F1;
    border-radius: 10px;
    border: 1px solid #999;
}

.form-header {
    padding: 15px 0;
    border-bottom: 1px solid #cccccc;
}

.form-header h1 {
    font-size: 28px;
    text-align: center;
    color: #666;
}

.row {
    display: flex;
    flex-direction: row;
}

.input-group {
    flex:1;  
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 10px 5px;
}

label {
    color: #1BBA93;
    font-size: 17px;
    font-weight: 500;
    padding-bottom: 5px;
}

input[type="text"],
input[type="email"], 
input[type="password"],
input[type="file"],
input[type="number"],
textarea,
select {
    font-size: 18px;
    height: 34px;
    padding: 0px 10px;
    color: #666;
    border: 1px solid #d6d6d6;
    border-radius: 4px;
    background: white;
    outline: none;
    }

    .form-body {
        background: white;
        padding: 5px 10px;
    }

    .radio-group,
    .checkbox-group,
    .range-group {
        display: flex;
    }

    .radio-group div, 
    .checkbox-group div,
    .range-group input {
        flex: 1 ;
    }

    .radio-group label, 
    .checkbox-group label{
        color:#666;
        cursor:pointer;
        
    }
    .range-group label {
        margin-left: 10px;
        background-color: #1BBA93;
        color: white;
        border-radius: 5px;
        padding: 5px;
        font-size: 17px;
        text-align: center;
      }

    textarea {
        resize: none;
        height: 100px;
    }

    .form-footer {
        display:flex;
        justify-content: flex-end;
    }

    .btn {
        padding:10px 20px;
        background-color: #1BBA93;
        font-size:17px;
        border:none;
        border-radius:5px;
        color:#bcf5e7;
        cursor:pointer;
    }

    @media only screen and (max-width: 500px) {
        .row{
          flex-direction:column; 
        }
    }
/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;

}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

html {
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
    font-family: 'Roboto', sans-serif;
    font-weight: bold;
    height: 100vh;
}

#registration-page {
    height: 100vh;
    background: #78a7ba; 
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: scroll;
}

.signup-form {
    flex: 1;
    max-width: 600px;
    background-color: #EFF0F1;
    border-radius: 10px;
    border: 1px solid #999;
}

.form-header {
    padding: 15px 0;
    border-bottom: 1px solid #cccccc;
}

.form-header h1 {
    font-size: 28px;
    text-align: center;
    color: #666;
}

.row {
    display: flex;
    flex-direction: row;
}

.input-group {
    flex:1;  
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 10px 5px;
}

label {
    color: #1BBA93;
    font-size: 17px;
    font-weight: 500;
    padding-bottom: 5px;
}

input[type="text"],
input[type="email"], 
input[type="password"],
input[type="file"],
input[type="number"],
textarea,
select {
    font-size: 18px;
    height: 34px;
    padding: 0px 10px;
    color: #666;
    border: 1px solid #d6d6d6;
    border-radius: 4px;
    background: white;
    outline: none;
    }

    .form-body {
        background: white;
        padding: 5px 10px;
    }

    .radio-group,
    .checkbox-group,
    .range-group {
        display: flex;
    }

    .radio-group div, 
    .checkbox-group div,
    .range-group input {
        flex: 1 ;
    }

    .radio-group label, 
    .checkbox-group label{
        color:#666;
        cursor:pointer;
        
    }
    .range-group label {
        margin-left: 10px;
        background-color: #1BBA93;
        color: white;
        border-radius: 5px;
        padding: 5px;
        font-size: 17px;
        text-align: center;
      }

    textarea {
        resize: none;
        height: 100px;
    }

    .form-footer {
        display:flex;
        justify-content: flex-end;
    }

    .btn {
        padding:10px 20px;
        background-color: #1BBA93;
        font-size:17px;
        border:none;
        border-radius:5px;
        color:#bcf5e7;
        cursor:pointer;
    }

    @media only screen and (max-width: 500px) {
        .row{
          flex-direction:column; 
        }
    }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Us</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <section id="registration-page">
        <form class="signup-form">  
            <div class="form-header">
                <h1>Create Account</h1>
            </div>
          <div class="form-body">
            <div class="row">
              <div class="input-group">
                <label>First name </label>
                <input type="text" placeholder="Enter your first name">
              </div>
              <div class="input-group">
                <label>Last name</label>
                <input type="text" placeholder="Enter your last name">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Email </label>
                <input type="email" placeholder="Enter your email address">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Password </label>
                <input type="password" placeholder="Enter your your password">
              </div>
              <div class="input-group">
                <label>Confirm Password</label>
                <input type="password" placeholder="Enter your password again">
              </div>
            </div>

              
            <div class="row">
              <div class="input-group">
                <label for="">Gender</label>
            
                <div class="radio-group">
            
                  <div>
                    <label for="male">
                      <input type="radio" name="gender" id="male">
                      Male
                    </label>
                  </div>
            
                  <div>
                    <label for="female">
                      <input type="radio" name="gender" id="female">
                      Female
                    </label>
                  </div>
            
                  <div>
                    <label for="other">
                      <input type="radio" name="gender" id="other"> Other
                    </label>
                  </div>
            
                </div> <!-- .radio-group -->
              </div> <!-- .input-group -->
            

              <div class="input-group">
                <label for="">Hobbies</label>
                <div class="checkbox-group">
                  <div>
                    <label for="music">
                      <input type="checkbox" name="hobbies" id="music">
                      Music
                    </label>
                  </div>
             
                  <div>
                    <label for="cooking">
                      <input type="checkbox" name="cooking" id="cooking">
                      Cook
                    </label>
                  </div>
             
                  <div>
                    <label for="travel">
                      <input type="checkbox" name="travel" id="travel">
                      Travel
                    </label>
                  </div>
             
                  <div>
                    <label for="movies">
                      <input type="checkbox" name="movies" id="movies">
                      Movie
                    </label>
                  </div>
                </div>

                </div> <!-- .checkbox-group -->
              </div><!-- .input-group -->
              
              
              <div class="row"> 
                <div class="input-group">
                  <label for="">Source of Income</label>
                  <select>
                    <option>Employed</option>
                    <option>Self-Employed</option>
                    <option>Unemployed</option>
                  </select>
                </div>
                <div class="input-group">
                  <label>Income</label>
                  <div class="range-group">
                    <input type="range" min="0" max="100" value="10" oninput="rangeValue.innerText = this.value">
                    <label id="rangeValue">10</label>
                  </div>
                </div>
              </div>
              
              <div class="row">
                <div class="input-group">
                  <label>Upload Profile Picture</label>
                  <input type="file">
                </div>
                <div class="input-group">
                  <label>Age</label>
                  <input type="number">
                </div>
              </div>

              <div class="row">
                <div class="input-group">
                  <label for="">Bio</label>
                  <textarea> </textarea>
                </div>
              </div>

              <div class="form-footer">
                <button class="btn">Create</button>
              </div>

          </div>

        </form> 
    
</section>

</body>
</html>

我的目标是确保正确显示完整的表单,而不管使用的设备是台式机、平板电脑还是移动的。

q8l4jmvw

q8l4jmvw1#

我解决了多个问题,我将带你通过:

  • 首先,你将注册表单的宽度固定为600 px。这对移动的设备不起作用,所以你应该使用min表达式来满足移动设备的需求。对于你的问题,我使用了min(600 px,100%)由于在移动的设备中,100%的屏幕小于600 px,其他内容将溢出。(你也可以为小型和大型设备提供更好的条件,但如果你对大型设备中的最大600像素感到满意,那就可以了。
  • 对于header问题,您只需删除registration-page中的100 vh条件。
  • 你最好为你的注册表单添加一些空白,这样它的边缘就不会与较小设备的屏幕边缘分开。
  • 最后,我设置“溢出:隐藏”在注册表单中,这样底部圆形边框半径就像它被孩子们溢出一样。只要注册的高度是默认值(自动),这就很好,但是如果你固定了它的高度,你可以把填充放在底部,而不是把最后一个孩子放在注册表单的底部边距。

如果有什么不清楚的地方,请在评论中提问!

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;

}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

html {
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
    font-family: 'Roboto', sans-serif;
    font-weight: bold;
    min-height: 100vh;
}

#registration-page {
    background: #78a7ba; 
    display: flex;
    justify-content: center;
    align-items: center;
}

.signup-form {
    flex: 1;
    /* max-width: 600px; */
    background-color: #EFF0F1;
    border: 1px solid #999;
    border-radius: 10px;
    /* The overflow condition to make bottom 
    borders appear circular, as the borders of 
    last children of signup-form
    are overflowing the edges making it appear sharp*/
    overflow: hidden;
    max-width: min(100%, 600px);
    width: 50vw;
    margin: 8px;
}

.form-header {
    padding: 15px 0;
    border-bottom: 1px solid #cccccc;
}

.form-header h1 {
    font-size: 28px;
    text-align: center;
    color: #666;
}

.row {
    display: flex;
    flex-direction: row;
}

.input-group {
    flex:1;  
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 10px 5px;
}

label {
    color: #1BBA93;
    font-size: 17px;
    font-weight: 500;
    padding-bottom: 5px;
}

input[type="text"],
input[type="email"], 
input[type="password"],
input[type="file"],
input[type="number"],
textarea,
select {
    font-size: 18px;
    height: 34px;
    padding: 0px 10px;
    color: #666;
    border: 1px solid #d6d6d6;
    border-radius: 4px;
    background: white;
    outline: none;
    }

    .form-body {
        background: white;
        padding: 5px 10px;
    }

    .radio-group,
    .checkbox-group,
    .range-group {
        display: flex;
    }

    .radio-group div, 
    .checkbox-group div,
    .range-group input {
        flex: 1 ;
    }

    .radio-group label, 
    .checkbox-group label{
        color:#666;
        cursor:pointer;
        
    }
    .range-group label {
        margin-left: 10px;
        background-color: #1BBA93;
        color: white;
        border-radius: 5px;
        padding: 5px;
        font-size: 17px;
        text-align: center;
      }

    textarea {
        resize: none;
        height: 100px;
    }

    .form-footer {
        display:flex;
        justify-content: flex-end;
    }

    .btn {
        padding:10px 20px;
        background-color: #1BBA93;
        font-size:17px;
        border:none;
        border-radius:5px;
        color:#bcf5e7;
        cursor:pointer;
    }

    @media only screen and (max-width: 500px) {
        .row{
          flex-direction:column; 
        }
        

    }
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Us</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <section id="registration-page">
        <form class="signup-form">  
            <div class="form-header">
                <h1>Create Account</h1>
            </div>
          <div class="form-body">
            <div class="row">
              <div class="input-group">
                <label>First name </label>
                <input type="text" placeholder="Enter your first name">
              </div>
              <div class="input-group">
                <label>Last name</label>
                <input type="text" placeholder="Enter your last name">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Email </label>
                <input type="email" placeholder="Enter your email address">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Password </label>
                <input type="password" placeholder="Enter your your password">
              </div>
              <div class="input-group">
                <label>Confirm Password</label>
                <input type="password" placeholder="Enter your password again">
              </div>
            </div>

              
            <div class="row">
              <div class="input-group">
                <label for="">Gender</label>
            
                <div class="radio-group">
            
                  <div>
                    <label for="male">
                      <input type="radio" name="gender" id="male">
                      Male
                    </label>
                  </div>
            
                  <div>
                    <label for="female">
                      <input type="radio" name="gender" id="female">
                      Female
                    </label>
                  </div>
            
                  <div>
                    <label for="other">
                      <input type="radio" name="gender" id="other"> Other
                    </label>
                  </div>
            
                </div> <!-- .radio-group -->
              </div> <!-- .input-group -->
            

              <div class="input-group">
                <label for="">Hobbies</label>
                <div class="checkbox-group">
                  <div>
                    <label for="music">
                      <input type="checkbox" name="hobbies" id="music">
                      Music
                    </label>
                  </div>
             
                  <div>
                    <label for="cooking">
                      <input type="checkbox" name="cooking" id="cooking">
                      Cook
                    </label>
                  </div>
             
                  <div>
                    <label for="travel">
                      <input type="checkbox" name="travel" id="travel">
                      Travel
                    </label>
                  </div>
             
                  <div>
                    <label for="movies">
                      <input type="checkbox" name="movies" id="movies">
                      Movie
                    </label>
                  </div>
                </div>

                </div> <!-- .checkbox-group -->
              </div><!-- .input-group -->
              
              
              <div class="row"> 
                <div class="input-group">
                  <label for="">Source of Income</label>
                  <select>
                    <option>Employed</option>
                    <option>Self-Employed</option>
                    <option>Unemployed</option>
                  </select>
                </div>
                <div class="input-group">
                  <label>Income</label>
                  <div class="range-group">
                    <input type="range" min="0" max="100" value="10" oninput="rangeValue.innerText = this.value">
                    <label id="rangeValue">10</label>
                  </div>
                </div>
              </div>
              
              <div class="row">
                <div class="input-group">
                  <label>Upload Profile Picture</label>
                  <input type="file">
                </div>
                <div class="input-group">
                  <label>Age</label>
                  <input type="number">
                </div>
              </div>

              <div class="row">
                <div class="input-group">
                  <label for="">Bio</label>
                  <textarea> </textarea>
                </div>
              </div>

              <div class="form-footer">
                <button class="btn">Create</button>
              </div>

          </div>

        </form> 
    
</section>

</body>
nkhmeac6

nkhmeac62#

您已将页面限制为仅100vh:

#registration-page {
    height: 100vh;
}
html {
    height: 100vh;
}

删除这些属性,它应该可以正常工作(或者在500px媒体查询中将高度设置为auto):

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol,
ul {
  list-style: none;
}

blockquote,
q {
  quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
  content: '';
  content: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

html {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  font-family: 'Roboto', sans-serif;
  font-weight: bold;
  height: 100vh;
}

#registration-page {
  background: #78a7ba;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: scroll;
  height: 100vh;
}

.signup-form {
  flex: 1;
  max-width: 600px;
  background-color: #EFF0F1;
  border-radius: 10px;
  border: 1px solid #999;
}

.form-header {
  padding: 15px 0;
  border-bottom: 1px solid #cccccc;
}

.form-header h1 {
  font-size: 28px;
  text-align: center;
  color: #666;
}

.row {
  display: flex;
  flex-direction: row;
}

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 10px 5px;
}

label {
  color: #1BBA93;
  font-size: 17px;
  font-weight: 500;
  padding-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
input[type="number"],
textarea,
select {
  font-size: 18px;
  height: 34px;
  padding: 0px 10px;
  color: #666;
  border: 1px solid #d6d6d6;
  border-radius: 4px;
  background: white;
  outline: none;
}

.form-body {
  background: white;
  padding: 5px 10px;
}

.radio-group,
.checkbox-group,
.range-group {
  display: flex;
}

.radio-group div,
.checkbox-group div,
.range-group input {
  flex: 1;
}

.radio-group label,
.checkbox-group label {
  color: #666;
  cursor: pointer;
}

.range-group label {
  margin-left: 10px;
  background-color: #1BBA93;
  color: white;
  border-radius: 5px;
  padding: 5px;
  font-size: 17px;
  text-align: center;
}

textarea {
  resize: none;
  height: 100px;
}

.form-footer {
  display: flex;
  justify-content: flex-end;
}

.btn {
  padding: 10px 20px;
  background-color: #1BBA93;
  font-size: 17px;
  border: none;
  border-radius: 5px;
  color: #bcf5e7;
  cursor: pointer;
}

@media only screen and (max-width: 500px) {
  .row {
    flex-direction: column;
  }
  html,
  #registration-page {
    height: auto;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Contact Us</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <section id="registration-page">
    <form class="signup-form">
      <div class="form-header">
        <h1>Create Account</h1>
      </div>
      <div class="form-body">
        <div class="row">
          <div class="input-group">
            <label>First name </label>
            <input type="text" placeholder="Enter your first name">
          </div>
          <div class="input-group">
            <label>Last name</label>
            <input type="text" placeholder="Enter your last name">
          </div>
        </div>

        <div class="row">
          <div class="input-group">
            <label>Email </label>
            <input type="email" placeholder="Enter your email address">
          </div>
        </div>

        <div class="row">
          <div class="input-group">
            <label>Password </label>
            <input type="password" placeholder="Enter your your password">
          </div>
          <div class="input-group">
            <label>Confirm Password</label>
            <input type="password" placeholder="Enter your password again">
          </div>
        </div>

        <div class="row">
          <div class="input-group">
            <label for="">Gender</label>

            <div class="radio-group">

              <div>
                <label for="male">
                      <input type="radio" name="gender" id="male">
                      Male
                    </label>
              </div>

              <div>
                <label for="female">
                      <input type="radio" name="gender" id="female">
                      Female
                    </label>
              </div>

              <div>
                <label for="other">
                      <input type="radio" name="gender" id="other"> Other
                    </label>
              </div>

            </div>
            <!-- .radio-group -->
          </div>
          <!-- .input-group -->

          <div class="input-group">
            <label for="">Hobbies</label>
            <div class="checkbox-group">
              <div>
                <label for="music">
                      <input type="checkbox" name="hobbies" id="music">
                      Music
                    </label>
              </div>

              <div>
                <label for="cooking">
                      <input type="checkbox" name="cooking" id="cooking">
                      Cook
                    </label>
              </div>

              <div>
                <label for="travel">
                      <input type="checkbox" name="travel" id="travel">
                      Travel
                    </label>
              </div>

              <div>
                <label for="movies">
                      <input type="checkbox" name="movies" id="movies">
                      Movie
                    </label>
              </div>
            </div>

          </div>
          <!-- .checkbox-group -->
        </div>
        <!-- .input-group -->

        <div class="row">
          <div class="input-group">
            <label for="">Source of Income</label>
            <select>
              <option>Employed</option>
              <option>Self-Employed</option>
              <option>Unemployed</option>
            </select>
          </div>
          <div class="input-group">
            <label>Income</label>
            <div class="range-group">
              <input type="range" min="0" max="100" value="10" oninput="rangeValue.innerText = this.value">
              <label id="rangeValue">10</label>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="input-group">
            <label>Upload Profile Picture</label>
            <input type="file">
          </div>
          <div class="input-group">
            <label>Age</label>
            <input type="number">
          </div>
        </div>

        <div class="row">
          <div class="input-group">
            <label for="">Bio</label>
            <textarea> </textarea>
          </div>
        </div>

        <div class="form-footer">
          <button class="btn">Create</button>
        </div>

      </div>

    </form>

  </section>

</body>

</html>
euoag5mw

euoag5mw3#

**编辑:**我在media query 500px部分添加了下面的代码,现在可以在所有屏幕尺寸下工作。另外,我在html文件中添加了一些div(form-header-bottom和blank-bottom)。并给出了注册表单类max-height:100vh;

@media only screen and (max-width: 500px) {
      .row{
        flex-direction:column; 
      }
        #registration-page {
          height: 100vh;
          background: #78a7ba;
          display: block;
          justify-content: center;
          align-items: center;
          position:relative;
          padding-right: 25px;
          padding-left:25px;
          
      }
      #blank-bottom {
        height: 59px;
        background: #78a7ba; 
        display: flex;
        position:relative;
        justify-content: center;
        align-items: center; 
    }

}

@media screen and (max-width: 900px) and (min-width: 501px){

    .row{
        flex-direction:column; 
      }
        #registration-page {
          height: 100vh;
          background: #78a7ba;
          display: flex;
          justify-content: center;
          align-items: center;
          position:relative;
          padding-right: 25px;
          padding-left:25px;
        
          
      }
      #blank-bottom {
        height: 59px;
        background: #78a7ba; 
        display: flex;
        position:relative;
        justify-content: center;
        align-items: center; 
    }

}

CSS和HTML代码:

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
    background-color: #78a7ba;

}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

html {
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
    font-family: 'Roboto', sans-serif;
    font-weight: bold;
    height:100vh;
}

#registration-page {
    height: 100%;
    background: #78a7ba; 
    display: flex;
    position:relative;
    justify-content: center;
    align-items: center;
    padding-top:50px;
}

.form-header-bottom {
    height: 59px;
    background: #EFF0F1; 
    display: flex;
    position:relative;
    justify-content: center;
    align-items: center;
    border-bottom-left-radius:10px;
    border-bottom-right-radius: 10px;

}

#blank-bottom {
        height: 59px;
        background: #78a7ba; 
        display: flex;
        position:relative;
        justify-content: center;
        align-items: center; 
    }

.signup-form {
    flex: 1;
    max-width: 600px;
    max-height:100vh;
    background-color: #EFF0F1;
    border-radius: 10px;

}

.form-header {
    padding: 15px 0;
    border-bottom: 1px solid #cccccc;
}


.form-header h1 {
    font-size: 28px;
    text-align: center;
    color: #666;
}

.row {
    display: flex;
    flex-direction: row;
}

.input-group {
    flex:1;  
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 10px 5px;
}

label {
    color: #1BBA93;
    font-size: 17px;
    font-weight: 500;
    padding-bottom: 5px;
}

input[type="text"],
input[type="email"], 
input[type="password"],
input[type="file"],
input[type="number"],
textarea,
select {
    font-size: 18px;
    height: 34px;
    padding: 0px 10px;
    color: #666;
    border: 1px solid #d6d6d6;
    border-radius: 4px;
    background: white;
    outline: none;
    }

    .form-body {
        background: white;
        padding: 5px 10px;
    }

    .radio-group,
    .checkbox-group,
    .range-group {
        display: flex;
    }

    .radio-group div, 
    .checkbox-group div,
    .range-group input {
        flex: 1 ;
    }

    .radio-group label, 
    .checkbox-group label{
        color:#666;
        cursor:pointer;
        
    }
    .range-group label {
        margin-left: 10px;
        background-color: #1BBA93;
        color: white;
        border-radius: 5px;
        padding: 5px;
        font-size: 17px;
        text-align: center;
      }

    textarea {
        resize: none;
        height: 100px;
    }

    .form-footer {
        display:flex;
        justify-content: flex-end;
    }

    .btn {
        padding:10px 20px;
        background-color: #1BBA93;
        font-size:17px;
        border:none;
        border-radius:5px;
        color:#bcf5e7;
        cursor:pointer;
    }

    @media only screen and (max-width: 500px) {
      .row{
        flex-direction:column; 
      }
        #registration-page {
          height: 100vh;
          background: #78a7ba;
          display: block;
          justify-content: center;
          align-items: center;
          position:relative;
          padding-right: 25px;
          padding-left:25px;
          
      }
      #blank-bottom {
        height: 59px;
        background: #78a7ba; 
        display: flex;
        position:relative;
        justify-content: center;
        align-items: center; 
    }

}

@media screen and (max-width: 900px) and (min-width: 501px){

    .row{
        flex-direction:column; 
      }
        #registration-page {
          height: 100vh;
          background: #78a7ba;
          display: flex;
          justify-content: center;
          align-items: center;
          position:relative;
          padding-right: 25px;
          padding-left:25px;
        
          
      }
      #blank-bottom {
        height: 59px;
        background: #78a7ba; 
        display: flex;
        position:relative;
        justify-content: center;
        align-items: center; 
    }

}
<!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">
  <title>Document</title>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Us</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="./style.css">
</head>
<body>
  
    <section id="registration-page">
        <form class="signup-form">  
            <div class="form-header">
                <h1>Create Account</h1>
            </div>
          <div class="form-body">
            <div class="row">
              <div class="input-group">
                <label>First name </label>
                <input type="text" placeholder="Enter your first name">
              </div>
              <div class="input-group">
                <label>Last name</label>
                <input type="text" placeholder="Enter your last name">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Email </label>
                <input type="email" placeholder="Enter your email address">
              </div>
            </div>

            <div class="row">
              <div class="input-group">
                <label>Password </label>
                <input type="password" placeholder="Enter your your password">
              </div>
              <div class="input-group">
                <label>Confirm Password</label>
                <input type="password" placeholder="Enter your password again">
              </div>
            </div>

              
            <div class="row">
              <div class="input-group">
                <label for="">Gender</label>
            
                <div class="radio-group">
            
                  <div>
                    <label for="male">
                      <input type="radio" name="gender" id="male">
                      Male
                    </label>
                  </div>
            
                  <div>
                    <label for="female">
                      <input type="radio" name="gender" id="female">
                      Female
                    </label>
                  </div>
            
                  <div>
                    <label for="other">
                      <input type="radio" name="gender" id="other"> Other
                    </label>
                  </div>
            
                </div> <!-- .radio-group -->
              </div> <!-- .input-group -->
            

              <div class="input-group">
                <label for="">Hobbies</label>
                <div class="checkbox-group">
                  <div>
                    <label for="music">
                      <input type="checkbox" name="hobbies" id="music">
                      Music
                    </label>
                  </div>
             
                  <div>
                    <label for="cooking">
                      <input type="checkbox" name="cooking" id="cooking">
                      Cook
                    </label>
                  </div>
             
                  <div>
                    <label for="travel">
                      <input type="checkbox" name="travel" id="travel">
                      Travel
                    </label>
                  </div>
             
                  <div>
                    <label for="movies">
                      <input type="checkbox" name="movies" id="movies">
                      Movie
                    </label>
                  </div>
                </div>

                </div> <!-- .checkbox-group -->
              </div><!-- .input-group -->
              
              
              <div class="row"> 
                <div class="input-group">
                  <label for="">Source of Income</label>
                  <select>
                    <option>Employed</option>
                    <option>Self-Employed</option>
                    <option>Unemployed</option>
                  </select>
                </div>
                <div class="input-group">
                  <label>Income</label>
                  <div class="range-group">
                    <input type="range" min="0" max="100" value="10" oninput="rangeValue.innerText = this.value">
                    <label id="rangeValue">10</label>
                  </div>
                </div>
              </div>
              
              <div class="row">
                <div class="input-group">
                  <label>Upload Profile Picture</label>
                  <input type="file">
                </div>
                <div class="input-group">
                  <label>Age</label>
                  <input type="number">
                </div>
              </div>

              <div class="row">
                <div class="input-group">
                  <label for="">Bio</label>
                  <textarea> </textarea>
                </div>
              </div>

              <div class="form-footer">
                <button class="btn">Create</button>
              </div>

          </div>

          <div class="form-header-bottom">
        </div>
        <div id="blank-bottom"></div>
        </form> 
      
</section>
</body>
</html>

相关问题