使我的搜索栏在同一行响应

时间:2017-02-04 21:56:38

标签: html css

这是我搜索栏的html代码。我希望通过缩小设备来使其响应,如果可能的话,我希望搜索栏和搜索按钮在缩小时同时位于同一页面上。

<div class="main">
<input type="text" />
<input type="submit" value="Search">
</div>

css代码

input{
    border: none;
    padding: 10px;
    margin: 10px;
    height: 40px;
    width: 600px;
    border:1px solid #eaeaea;
    outline:none;
}

input:hover{
    border-color: #a0a0a0 #b9b9b9 #b9b9b9 #b9b9b9;
}

input:focus{
    border-color:#4d90fe;
}

input[type="submit"] {
    border-radius: 2px;
    background: #f2f2f2;
    border: 1px solid #f2f2f2;
    color: #757575;
    cursor: default;
    font-size: 14px;
    font-weight: bold;
    width: 100px;
    padding: 0 16px;
    height:40px;
}

input[type="submit"]:hover {
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    background: #f8f8f8;
    border: 1px solid #c6c6c6;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    color: #222;
}

2 个答案:

答案 0 :(得分:0)

display: flex; align-items: center;添加到父

&#13;
&#13;
.main {
  display: flex;
  align-items: center;
}

input{
    border: none;
    padding: 10px;
    margin: 10px;
    height: 40px;
    width: 600px;
    border:1px solid #eaeaea;
    outline:none;
}

input:hover{
    border-color: #a0a0a0 #b9b9b9 #b9b9b9 #b9b9b9;
}

input:focus{
    border-color:#4d90fe;
}

input[type="submit"] {
    border-radius: 2px;
    background: #f2f2f2;
    border: 1px solid #f2f2f2;
    color: #757575;
    cursor: default;
    font-size: 14px;
    font-weight: bold;
    width: 100px;
    padding: 0 16px;
    height:40px;
}

input[type="submit"]:hover {
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    background: #f8f8f8;
    border: 1px solid #c6c6c6;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    color: #222;
}
&#13;
<div class="main">
<input type="text" />
<input type="submit" value="Search">
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我用媒体查询做了一个快速示例来改变输入元素的样式。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width:device-width, initial-scale = 1">
        <style>
            
            body {
                width: 100%;
                height: 100%;
                margin: 0;
            }

            .main {
                width: 100%;
                margin: 0 auto;
            }

            input[type="text"], input[type="submit"]{
                margin: 0;
                padding: 10px 0;
                display: inline-block;
                border: 1px solid black;
            }

            input[type="text"]{
                width: 70%;
            }

            input[type="submit"]{
                width: 29%;
            }

            /** Tablet **/
            @media (max-width: 768px) {
                input[type="text"]{
                    width: 60%;
                }
                input[type="submit"]{
                    width: 38%;
                }
            }

            /** Mobile **/
            @media (max-width: 420px) {
                input[type="text"]{
                    width: 70%;
                }
                input[type="submit"]{
                    width: 28%;
                }
            }

        </style>
    </head>
    <body>
        <div class="main">
            <input type="text" />
            <input type="submit" value="Search">
        </div>
    </body>
</html>