当我缩小浏览器窗口时,边框不会停留在表单周围,而是会重叠?我的判决也是如此。如何使边框保持在表单周围,并根据带有填充的表单长度调整边框高度?
#form_border{
margin: auto;
width: 400px;
border-style: solid;
border-color: black;
border-width: 1px;
}
#form {
width: 50%;
height: 50%;
margin: auto;
padding-top: 2em;
text-align: center;
}
#form form{display: block;}
#existing_account{ text-align: center;
text-decoration: none;
color: black;
}
input[type=submit] {
background:white;
border:1px solid;
border-color: #292929;
cursor:pointer;
border-radius: 5px; }
input[type=submit] {
background:white;
border:1px solid;
border-color: #292929;
cursor:pointer;
border-radius: 5px; }
<div id="form_border">
<form id="form" method="post" action="">
<p>Username:<br> <input type="text" name="user_name" /> <br></p>
<p>Password:<br> <input type="password" name="user_pass"><br></p>
<p>Password again:<br> <input type="password" name="user_pass_check"><br></p>
<p>E-mail:<br> <input type="email" name="user_email"><br></p>
<input type="submit" value="Sign Up" />
</form>
<a id="existing_account" href="sign_in.php">Already have an account?</a>
</div>
最佳答案
尝试使用这段代码:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<style>
#form_border{
margin: auto;
width: 400px;
border-style: solid;
border-color: black;
border-width: 1px;
}
#form {
width: 50%;
height: 50%;
margin: auto;
padding-top: 2em;
text-align: center;
}
#form form{
display: block;
}
#existing_account{
text-align: center;
text-decoration: none;
color: black;
}
input[type=submit] {
background:white;
border:1px solid;
border-color: #292929;
cursor:pointer;
border-radius: 5px;
}
@media screen and (max-width:399px){
input[type="text"],
input[type="password"],
input[type="email"]{
width:90%;
}
#form_border{
width:98%;
}
#form {
width: 50%;
height: 50%;
}
}
</style>
</head>
<body>
<div id="form_border">
<form id="form" method="post" action="">
<p>Username:<br> <input type="text" name="user_name" /> <br></p>
<p>Password:<br> <input type="password" name="user_pass"><br></p>
<p>Password again:<br> <input type="password" name="user_pass_check"><br></p>
<p>E-mail:<br> <input type="email" name="user_email"><br></p>
<input type="submit" value="Sign Up" />
</form>
<a id="existing_account" href="sign_in.php">Already have an account?</a>
</div>
</body>
</html>
您将观察到:
- 我引入了媒体查询来管理宽度小于 400 像素的屏幕的表单大小。
- 表单和表单元素的宽度已在媒体查询中得到处理。
改进范围:
重构 HTML,使其更易于管理。
更高效地使用媒体查询。
更有效地使用
width
值。
你用这个jsfiddle.net演示链接。
这里有一些更常用的媒体查询断点,您可以考虑将其包含在您的 CSS 中
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/**********
iPad 3
**********/
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
@media only screen and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* iPhone 5 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* iPhone 6 ----------- */
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* iPhone 6+ ----------- */
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* Samsung Galaxy S3 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* Samsung Galaxy S4 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
/* Samsung Galaxy S5 ----------- */
@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
关于html - 为什么我的边框会超过我的表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30822100/