【问题标题】:Using Bootstrap Grid to align content使用 Bootstrap Grid 对齐内容
【发布时间】:2017-04-30 11:51:02
【问题描述】:

我使用了 Bootstrap Grid 格式,以便能够对齐我的图像,但由于某种原因它无法正常工作。它们都在左侧,就好像我将它们设置为块一样,如果我将它们的位置作为内联块也将不起作用。我将如何编辑它以使我的 5 张图像具有响应式网格格式?

<div id="section2" class="container-fluid">
    <h2>The Members</h2>
    <h3 id="hoverovertext">(Hover-over each member to learn more)</h3>
        <div class="row1" width="100%">
            <div class="members col-md-4" id="ohno" height="225px">
                <img src="images/ohno.jpg" class="images" height="225px">
                <span class="text">Satoshi Ohno(Leader)<br>Birth: 26-11-1980, <br>Tokyo (Jpn)<br>Joined "Johnnys" in 1994</span>
            </div>    

            <div class="members col-md-4" id="sakurai" height="225px">
                <img src="images/sakurai.jpg" class="images" height="225px">
                <span class="text">Sho Sakurai<br>Birth: 25-01-1982, <br>Tokyo (Jpn)<br>Joined "Johnnys" in 1995<br>Graduated Keio University</span>
            </div>
        </div>
            <div class="members col-md-4" id="aiba" height="225px">
                <img src="images/aiba.jpg" class="images" height="225px">
                <span class="text">Masaki Aiba<br>Birth: 24-12-1982, <br>Chiba (Jpn)<br>Joined "Johnnys" in 1996</span>
            </div>    
        <div class="row2" width="100%">
            <div class="members col-md-6" id="ninomiya" height="225px">
                <img src="images/ninomiya.jpg" class="images" height="225px">
                <span class="text">Kazunari Ninomiya<br>Birth: 17-06-1983,<br>Tokyo (Jpn)<br>Joined "Johnnys" in 1996</span>
            </div>    

            <div class="members col-md-6" id="matsumoto" height="225px">
                <img src="images/matsumoto.jpg" class="images" height="225px">
                <span class="text">Jun Matsumoto<br>Birth:30-08-1983, <br>Tokyo (Jpn)<br>Joined "Johnnys" in 1996</span>
            </div>    
        </div>

【问题讨论】:

  • 我认为col-md-4 需要在row1 中。还要确保图像的width100%
  • 我想要顶行有 3 个图像,底部有 2 个图像,但随着屏幕变小,它就像一个棋盘

标签: html css twitter-bootstrap gridview grid


【解决方案1】:

这样的事情应该让你开始......

每个水平行都应该在&lt;div class="row"&gt;

在一行内,所有col 加起来应该是 12。所以,有 2+4+4+2 行,还有 6+6 行,等等。

不要忘记class="img-responsive" 用于图片...非常有用。

.imgIB{display:inline-block !important;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div id="section2" class="container-fluid">
    <h2>The Members</h2>
    <h3 id="hoverovertext">(Hover-over each member to learn more)</h3>

	<div class="row1" width="100%">
		<div class="col-xs-2"></div>
		<div class="col-xs-4 members" id="ohno">
			<img src="http://placeimg.com/100/100/animals" class="img-responsive">
			<span class="text">Satoshi Ohno(Leader)<br>Birth: 26-11-1980, <br>Tokyo (Jpn)<br>Joined "Johnnys" in 1994</span>
		</div>
		<div class="col-xs-4 members" id="sakurai">
			<img src="http://placeimg.com/100/100/animals" class="img-responsive">
			<span class="text">Sho Sakurai<br>Birth: 25-01-1982, <br>Tokyo (Jpn)<br>Joined "Johnnys" in 1995<br>Graduated Keio University</span>
		</div>
		<div class="col-xs-2"></div>
	</div><!-- .row -->

	<div class="row1" width="100%">
		<div class="col-xs-4"></div>
		<div class="col-xs-4 members" id="aiba">
			<img src="http://placeimg.com/100/100/animals" class="img-responsive">
			<span class="text">Masaki Aiba<br>Birth: 24-12-1982, <br>Chiba (Jpn)<br>Joined "Johnnys" in 1996</span>
		</div>    
		<div class="col-xs-4"></div>
	</div><!-- .row -->

	<div class="row" width="100%">
		<div class="col-xs-6 members text-center" id="ninomiya">
			<div>
              <img src="http://placeimg.com/100/100/animals" class="img-responsive imgIB">
            </div>
			<span class="text">Kazunari Ninomiya<br>Birth: 17-06-1983,<br>Tokyo (Jpn)<br>Joined "Johnnys" in 1996</span>
		</div>
		<div class="col-xs-6 members text-center" id="matsumoto">
			<div>
               <img src="http://placeimg.com/100/100/animals" class="img-responsive imgIB">
            </div>
			<span class="text">Jun Matsumoto<br>Birth:30-08-1983, <br>Tokyo (Jpn)<br>Joined "Johnnys" in 1996</span>
		</div>    
	</div><!-- .row -->
</div>

【讨论】:

  • 我试图将更改包含在内,但除了我包含 text-center 并且仅将文本单独移动到页面中心时,它似乎并没有起作用。这是我的页面css。
  • /*网页成员部分的css*/ #section2 { padding-top:50px;高度:775px;颜色:#0000CD;背景颜色:#ADD8E6;宽度:100%; } #hoverovertext { 字体大小:16px; } .members { 位置:相对;填充:0px 0px 200px 0px;宽度:100%; } .images { 位置:绝对;填充:20px; z-索引:1; } .images:hover { 不透明度:0.35; } .text { 位置:绝对;填充:25px;宽度:100%; } .imgIB { 显示:内联块; }
  • 你的造型过分了。使用 Bootstrap 的原因是利用它的样式。当您将position:absolute 应用于图像时,您将撤消引导默认值。 Bootstrap 旨在让您尽可能少地使用手动 css 样式。对于样式,添加额外的引导类(如“文本中心”等)。在 Bootstrap 上观看更多 YouTube tuts。这是一个很好的来源:codedamn YouTube channel
  • 我可以在没有绝对定位的情况下使用 z-index 吗?
  • 它也适用于position:relative——它根本不应该移动元素,只是使它适用于topleftz-index等。(默认为@ 987654333@ 与position:relative 几乎相同)css-tricks.com/what-if-there-was-no-position-static
猜你喜欢
  • 1970-01-01
  • 2016-03-19
  • 2019-10-28
  • 1970-01-01
  • 2015-05-31
  • 2013-12-20
  • 2013-07-28
  • 1970-01-01
  • 2017-08-31
相关资源
最近更新 更多