作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带菜单的标题 div,下面有一个横幅 div。在横幅 div 中,我有一个背景颜色为红色的搜索 div,我不明白为什么这个背景颜色为红色的 div 与上面的 Logo 和菜单项不对齐。横幅 div 的左侧和横幅 div 的右侧有一点空间,导致此横幅 div 变得比上面的标题 div 大一点。你知道为什么会出现这个小空间吗?似乎随着宽度的增加,空间更加明显。
CSS:
*,
*:after,
*:before {
margin: 0;
padding: 0;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
outline: 0;
border-radius: 0;
}
fieldset {
border: 0;
}
input,
select,
textarea,
button {
padding: 15px;
width: 100%;
}
select,
input,
button {
border: 0;
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
cursor: pointer;
color:#94a3a8;
}
img {
width: 100%;
max-width: 100%;
vertical-align: middle;
margin: 0;
}
a img {
border: none;
margin: 0;
}
a {
text-decoration: none;
}
ul {
list-style: none;
margin:0;
padding: 0;
}
.container {
float: left;
width: 100%;
}
.content {
width: 96%;
margin: 0px auto;
padding: 30px;
}
.Header{
padding: 15px;
}
.Header, .main_nav{
display: flex;
align-items: center;
}
.title{
flex-grow:1;
}
.title a{
color:red;
font-size: 0.85em;
}
.main_nav{
background-color:red;
}
.nopaddingright:0;
.main_nav li{
padding: 0 15px;
}
.main_nav a{
font-weight: 700;
font-size: 0.85em;
color:brown;
}
.main_nav a:hover{
color:brown;
}
.create{
border:2px solid red;
padding: 10px;
color:red !important;
border-radius: 4px;
}
.create:hover{
border:2px solid red;
padding: 10px;
color:white !important;
background-color: red;
border-radius: 4px;
}
/*************** BANNER *****************/
.Banner{
background-color: gray;
width: 100%;
}
.search{
background-color: red;
padding: 30px;
border-radius: 4px;
}
.input{
background-color: #fff;
}
.search select{
background-color: #f8f8f8;
}
.search_form{
display: flex;
align-items: center;
margin: 0;
flex-wrap: wrap;
font-size: 0;
}
.Banner__search_form_element{
flex-grow: 1;
}
.Banner__search_form_element_search{
background-color: green;
color: white;
}
最佳答案
接近您想要的布局的一种方法...
*,
*:after,
*:before {
margin: 0;
padding: 0;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
outline: 0;
border-radius: 0;
}
fieldset {
border: 0;
}
input,
select,
textarea,
button {
padding: 15px;
/*width: 100%;*/
}
select,
input,
button {
border: 0;
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
cursor: pointer;
}
img {
width: 100%;
max-width: 100%;
vertical-align: middle;
margin: 0;
}
a img {
border: none;
margin: 0;
}
a {
text-decoration: none;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
.Header,
.header__inner,
.main_nav,
.Banner {
display: flex;
justify-content: center;
align-items: center;
}
.header__inner,
.search {
/* change this value as you need and target it with media queries */
width: 90%;
justify-content: space-between;
}
.title a {
color: $color-primary;
display: inline-block;
/* padding: 15px; */
font-size: 0.85em;
}
.main_nav li {
padding: 15px;
}
.main_nav li:last-of-type {
padding-right: 0;
}
.main_nav {
margin-top: 10px;
margin-bottom: 10px;
}
.main_nav a {
flex-direction: column;
font-weight: 700;
font-size: 0.85em;
color: gray;
}
.create {
padding: 10px;
color: red;
border-radius: 4px;
}
/** BANNER */
.Banner {
background-color: gray;
/* remove the padding to left and right */
padding: 30px 0;
}
.search {
background-color: green;
padding: 30px;
border-radius: 4px;
display: flex;
}
.search select {
background-color: #f8f8f8;
}
form {
font-size: 0;
}
.search_form {
display: flex;
width: 100%;
justify-content: space-between;
/*
align-items: center;
margin: 0; */
}
.search_form_element {
flex: 2;
/* use margin to separate instead if you prefer */
border: 1px solid red;
}
.search_form_element select,
.search_form_element input {
width: 100%;
}
.search_form_element:last-of-type {
flex: 1;
}
<header class="Header">
<div class="header__inner">
<h1 class="title"><a href="">LOGO</a> </h1>
<ul class="main_nav">
<li><a href="">Item 1</a></li>
<li><a href="">Item 2</a></li>
</ul>
</div>
</header>
<div class="Banner">
<div class="search">
<form class="search_form">
<div class="search_form_element">
<i class="fa fa-search" aria-hidden="true"></i>
<input type="search" value="Search">
</div>
<div class="search_form_element">
<i class="fa fa-search" aria-hidden="true"></i>
<select>
<option selected>Option 1</option>
</select>
</div>
<div class="search_form_element">
<i class="fa fa-search" aria-hidden="true"></i>
<select>
<option selected>Option 2</option>
</select>
</div>
<div class="search_form_element">
<i class="fa fa-search" aria-hidden="true"></i>
<input type="submit" value="Search">
</div>
</form>
</div>
</div>
关于html - Banner div 在左右边距上有一点空间,这导致这个 div 比上面的 header div 大一点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45377624/
我是一名优秀的程序员,十分优秀!