我正在尝试在div内放置三个网格并使之响应。但是无法正确处理。网格有一些平衡问题。第一个网格有一个图像。第二个(中心)网格具有文本。最后一个(第三个)网格将具有一个按钮。
当我尝试缩小浏览器尺寸或通过电话连接时。网格没有变得平衡且没有响应。我在这里做错了什么?我非常感谢您的帮助!谢谢。
html, body {
background-color: #fff;
color: #636b6f;
font-family: "Helvetica Neue", 'lato', sans-serif;
font-weight: 300;
margin: 0;
}
.row {
width: 50%;
margin: 0 auto;
}
.banner-back-ground {
width: 100%;
background-color: #f5f6fa;
}
h1 {
color: #4CAF50;
padding-top: 15px;
padding-bottom: 15px;
margin: 0;
}
.nav-back-ground {
background-color: #333;
margin-bottom: 50px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
img {
height: 130px;
width: 130px;
border-radius: 3px;
}
.all-content-wrapper {
border: solid 1px #333;
border-radius: 3px;
box-sizing: border-box;
padding: 10px;
}
/* SECTIONS */
.all-content-wrapper {
clear: both;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF THREE */
.span_3_of_3 { width: 20%; margin: auto; }
.span_2_of_3 { width: 60%; margin: auto; }
.span_1_of_3 { width: 20%; }
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; }
}
.content-text ul {
background-color: white;
list-style-type: none;
margin: 0;
padding: 0;
}
.content-text li {
float: left;
}
<div class="banner-back-ground">
<div class="row">
<h1>BEN</h1>
</div>
</div>
<div class="nav-back-ground">
<div class="row">
<ul>
<li><a class="active" href="#home">東北</a></li>
<li><a href="#news">関西</a></li>
<li><a href="#contact">北海道</a></li>
<li><a href="#contact">関東</a></li>
<li style="float:right"><a href="#about"><i class="fa fa-search"></i> 検査</a></li>
</ul>
</div>
</div>
<section>
<div class="row">
<div class="all-content-wrapper group">
<div class="col span_1_of_3">
<img src="https://dummyimage.com/130x130/000/fff.jpg" alt="">
</div>
<div class="col span_2_of_3">
<span class="content-text">
<ul>
<li>asldkas;ldka;sldka;sdlka;sdlka;sdja;sdjasdjlakjsdlakjsdlakjddasdasdsa</li>
<li>sdlalsdka;sdkad</li>
<li>;alskda;slkda;lsdkasd</li>
<li>alksd:a;sklda;ksda;sdk;askd</li>
</ul>
</span>
</div>
<div class="col span_3_of_3">
Here Button
</div>
</div>
</div>
</section>
如您在代码段导航栏和div内部所看到的那样,它们并不是很灵巧...
答案 0 :(得分:1)
html, body {
background-color: #fff;
color: #636b6f;
font-family: "Helvetica Neue", 'lato', sans-serif;
font-weight: 300;
margin: 0;
}
.row {
width: 50%;
margin: 0 auto;
}
.banner-back-ground {
width: 100%;
background-color: #f5f6fa;
}
h1 {
color: #4CAF50;
padding-top: 15px;
padding-bottom: 15px;
margin: 0;
}
.nav-back-ground {
background-color: #333;
margin-bottom: 50px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
img {
height: 130px;
width: 130px;
border-radius: 3px;
}
.all-content-wrapper {
border: solid 1px #333;
border-radius: 3px;
box-sizing: border-box;
padding: 10px;
}
/* SECTIONS */
.all-content-wrapper {
clear: both;
margin: 0px;
/* flex layout with wrap for ease of achieving responsive design */
display:flex;
flex-wrap:wrap;
}
/* COLUMN SETUP */
.col {
display: block;
/* don't need float with flex - float:left; */
/* specify grow, shrink and basis width */
flex:0 0 auto;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF THREE */
.span_3_of_3 { width: 20%; margin: auto; }
.span_2_of_3 { width: 60%; margin: auto; }
.span_1_of_3 { width: 20%; }
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; }
}
.content-text ul {
background-color: white;
list-style-type: none;
margin: 0;
padding: 0;
}
.content-text li {
float: left;
}
<div class="banner-back-ground">
<div class="row">
<h1>BEN</h1>
</div>
</div>
<div class="nav-back-ground">
<div class="row">
<ul>
<li><a class="active" href="#home">東北</a></li>
<li><a href="#news">関西</a></li>
<li><a href="#contact">北海道</a></li>
<li><a href="#contact">関東</a></li>
<li style="float:right"><a href="#about"><i class="fa fa-search"></i> 検査</a></li>
</ul>
</div>
</div>
<section>
<div class="row">
<div class="all-content-wrapper group">
<div class="col span_1_of_3">
<img src="https://dummyimage.com/130x130/000/fff.jpg" alt="">
</div>
<div class="col span_2_of_3">
<span class="content-text">
<ul>
<li>asldkas;ldka;sldka;sdlka;sdlka;sdja;sdjasdjlakjsdlakjsdlakjddasdasdsa</li>
<li>sdlalsdka;sdkad</li>
<li>;alskda;slkda;lsdkasd</li>
<li>alksd:a;sklda;ksda;sdk;askd</li>
</ul>
</span>
</div>
<div class="col span_3_of_3">
Here Button
</div>
</div>
</div>
</section>