创建了一个联系表。为了使其具有响应性,我在 768px 添加了一个 mediquery 以减小输入字段的宽度。但它没有改变。
我将在下面附上代码供您引用
<div class="form-container">
<h1>send us a message</h1>
<form class="form">
<input id="name" type="text" placeholder="Full Name">
<input id="email" type="text" placeholder="E-Mail">
<textarea id="message" cols="30" rows="10" placeholder="Message"></textarea>
<button type="submit"><i class="fa fa-paper-plane" aria-hidden="true"></i>SEND</button>
</form>
</div>
我使用 SCSS 来设计我的联系表单...
.form-container {
margin: 6rem 0;
height: auto;
h1 {
color: $header-main;
text-align: center;
font-family: $primary-font;
text-transform: capitalize;
font-size: 2.3rem;
letter-spacing: 1px;
&:after {
@include shortBorder(10rem, 1rem, 3px, #111);
margin-bottom: 5rem;
}
}
.form {
input[type="text"],
textarea,button {
display: block;
margin: 2rem auto;
width: 600px;
padding: 1rem;
border-radius: 1rem;
border: 1px solid $plane-white;
box-shadow: 2px 3px 3px 3px #ccc;
outline: none;
transition: width 0.2s ease-in-out;
}
input:hover,
textarea:hover {
width: 620px;
}
::placeholder {
color: rgb(155, 148, 146);
font-weight: 900;
font-family: 'Roboto';
}
button {
background-color: $header-main;
color: $plane-white;
width: 140px;
box-shadow: none;
i {
margin-right: 0.5rem;
}
}
}
button:hover {
cursor: pointer;
width: 160px;
}
}
联系表上的媒体查询.. 应从 600 像素减少到 500 像素。
@mediaqueries screen and (max-width:768px) {
.form {
width: 500px;
}
}
最佳答案
有很多因素可以阻止输入缩减。
- 您已将行和列设置为文本区域的大小参数。
<textarea id="message" cols="30" rows="10" placeholder="Message"></textarea>
这充当 HTML 中的宽度和高度。您应该删除它并使用 CSS 进行设置。 - 取决于
box-model
你正在使用,margin
&padding
可能会增加元素的整体宽度。 - 您的媒体查询未针对正确的元素,因此未按您的预期应用。
基本 CSS:(您正在更改 .form
中输入的宽度)
.form input[type="text"],
.form textarea,
.form button {
width: 600px;
}
媒体查询(您正在更改表单,而不是输入)
.form {
width: 500px;
}
关于html - 无法减少使用媒体查询联系表格的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55675810/