[英]I'm using a flex box to display label and input field. How do I make it responsive?
I have to use a flex class to make a label and input field one line.我必须使用 flex 类来制作标签和输入字段一行。 How do I force it to be responsive?我如何强制它响应?
My HTML Code is我的 HTML 代码是
.container{ width:1100px; margin:0 auto; } .form_single_wrap{ display:flex; flex-wrap: wrap; } .form_single_wrap label{ width:10%; } .form_single_wrap input{ width:80%; }
<div class="container"> <div class="form_wrap"> <form action=" "> <div class="form_single_wrap"> <label for="name">Name</label> <input type="text" name="name" placeholder="Name"/> </div> <div class="form_single_wrap"> <label for="email">Email Send Us</label> <input type="text" name="email" placeholder="Email"/> </div> </form> </div> </div>
How can I make it responsive?我怎样才能让它响应?
Use % instead of px for the container :)对容器使用 % 而不是 px :)
.container{
width:100%;
margin:0 auto;
}
I fix it also in bootstrap.我也在引导程序中修复它。 You can see in codepen你可以在codepen中看到
<html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous"> <link rel="stylesheet" href="style.css" /> <style type="text/css"> .form_wrap{ width:100%; } .form_single_wrap{ display:flex; flex-wrap: wrap; } .form_single_wrap label{ width:10%; } .form_single_wrap input{ width:80%; } </style> </head> <body> <div class="container"> <div class="row"> <div class="form_wrap"> <form action=" "> <div class="form_single_wrap"> <label for="name">Name </label> <input type="text" name="name" placeholder="Name"/> </div> <div class="form_single_wrap"> <label for="email">Email Send Us</label> <input type="text" name="email" placeholder="Email"/> </div> </form> </div> </div> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" ></script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.