简体   繁体   English

如何在不使用Bootstrap的情况下使HTML表单输入字段响应

[英]How to make HTML form input fields responsive without using Bootstrap

I have a really basic HTML form with two text input fields side by side (Name and Company) and a Submit and Back button underneith. 我有一个非常基本的HTML表单,并排有两个文本输入字段(“名称”和“公司”),下面是一个“提交”和“后退”按钮。

I want to make the width of my input fields scale down as the browser width is decreased. 我想使输入字段的宽度随着浏览器宽度的减小而缩小。

See 1st attached image for how it currently looks at full width, and 2nd attached image for how I want it to look when the browser window is decreased. 请参阅第一个附加图像以了解当前在全宽时的外观,以及第二个附加图像以查看当浏览器窗口缩小时我想要的外观。

在此处输入图片说明 在此处输入图片说明

I've tried wrapping the whole Form in a Div and setting the Div to width: 100%; 我试过将整个Form包裹在Div中,并将Div设置为width:100%; but it has no effect.. I've also tried various other tweaks but feel like I'm blowing in the wind as I don't really know what I should be changing.. any ideas? 但这没有效果。.我也尝试了其他各种调整,但感觉好像不知所措,因为我真的不知道我应该改变什么。

<form action="" method="post">
    <div class="row" align="center">

        <div class="column left">
            <label for="name">Name<span class="err"></span></label><br>
            <input id="name" type="text" name="Name"><br>
        </div>
        <div class="column right">
            <label for="company">Company<span class="err"></span></label><br>
            <input id="company" type="text" name="Company"><br>
        </div>

    </div>

    <div align="center">
        <a href="#"><button class="back-btn" type="button">Back</button></a>
        <input class="sign-in-btn" type="submit" value="Sign In">
    </div>

</form>



    * {
        box-sizing: border-box;
    }

    .row {
        display: flex;
        flex-direction: row;
        justify-content: center;
        padding-top: 45px;
        text-align: left;
    }


    input[type=text], select {
        width: 550px;
        height: 100px;
        margin: 10px 15px 50px;
        border: 3px solid #d9569f;
        border-radius: 50px;
        outline: none;
        font-family: sofia-pro-soft, sans-serif;
        font-weight: 300;
        font-size: 30px;
        text-align: center;
        text-align-last: center;
    }


    label {
        font-family: sofia-pro-soft, sans-serif;
        font-weight: 300;
        font-size: 30px;
        color: #555;
        margin-left: 30px;
    }


    input.sign-in-btn {
        width: 250px;
        height: 100px;
        border: 3px solid #fff;
        border-radius: 50px;
        outline: none;
        font-family: sofia-pro-soft, sans-serif;
        font-weight: 300;
        font-size: 30px;
        color: #fff;
        background: #d9569f;
        margin-left: 30px;
    }


    .sign-in-btn:active {
        color: #d9569f;
        background-color: #fff;
        border: 3px solid #d9569f;
    }


    .back-btn {
        width: 250px;
        height: 100px;
        border: 3px solid #fff;
        border-radius: 50px;
        outline: none;
        font-family: sofia-pro-soft, sans-serif;
        font-weight: 300;
        font-size: 30px;
        color: #fff;
        background: #d9569f;
        margin-right: 30px;
    }


    .back-btn:active {
        color: #d9569f;
        background-color: #fff;
        border: 3px solid #d9569f;
    }


    a {
        color: #fff;
        text-decoration: none;
    }

You Can Use media querie for responsive view 您可以使用媒体查询器进行响应式查看

 @media screen and (max-width:767px){ input[type=text]{ width:100%; display:inline-block; } } 

You could try something like this: 您可以尝试这样的事情:

@media only screen 
and (max-device-width: 800px)
    { 
        input[type=text], select {
            width: 400px;
            ...
    }
}

The part inside of the brackets of the max-device-width are only valid under the specified device screen width value. max-device-width括号内的部分仅在指定的设备屏幕宽度值下有效。

Media queries are the best option to keep your content scale down as the browser width is decreased. 媒体查询是减少浏览器宽度时缩小内容规模的最佳选择。 You can include these media queries in your css 您可以在CSS中包含这些媒体查询

/* Extra small devices (phones, 600px and down) */ / *超小型设备(电话,600像素及以下)* /

@media only screen and (max-width: 600px) {}

/* Small devices (portrait tablets and large phones, 600px and up) */ / *小型设备(纵向平板电脑和大型手机,600像素及以上)* /

@media only screen and (min-width: 600px) {}

/* Medium devices (landscape tablets, 768px and up) */ / *中型设备(横向平板电脑,768像素及以上)* /

@media only screen and (min-width: 768px) {} 

/* Large devices (laptops/desktops, 992px and up) */ / *大型设备(笔记本电脑/台式机,992px及以上)* /

@media only screen and (min-width: 992px) {}

/* Extra large devices (large laptops and desktops, 1200px and up) */ / *超大型设备(大型笔记本电脑和台式机,1200px及以上)* /

@media only screen and (min-width: 1200px) {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM