如何让3张图像适合一行

时间:2015-09-08 20:37:26

标签: html css

我试图让图片在页面上并排放置,但是它没有用完。正如您所看到的,有2列,但是当我添加另一个图像时,应该创建第3列,它会添加到第一列。 HALP!



.nav a {
  color: #5a5a5a;
  font-size: 11px;
  font-weight: bold;
  padding: 14px 10px;
  text-transform: uppercase;
}

.nav li {
  display: inline;
}

.jumbotron {
  background-image:url('http://i.imgur.com/3ay8hjS.jpg');
  height: 500px;
  background-repeat: no-repeat;
  background-size: cover;
}

.jumbotron .container {
  position: relative;
  top:100px;
}

.jumbotron h1 {
  color: #fff;
  font-size: 48px;  
  font-family: 'Shift', sans-serif;
  font-weight: bold;
}

.jumbotron p {
  font-size: 20px;
  color: #fff;
}

.learn-more {
  background-color: #fff;
}

.learn-more h3 {
  font-family: 'Shift', sans-serif;
  font-size: 18px;
  font-weight: bold;
}

.learn-more a {
  color: #00b0ff;
}

.neighborhoood-guides {
    background-color: #fff;
    padding-left: 1px;
    padding-right: 1px;
    
}
 
.clearfix:after {
    display:block;
    clear:both;
}
 
/*----- Menu Outline -----*/
.menu-wrap {
    width:100%;
    box-shadow:0px 1px 3px rgba(0,0,0,0.2);
    background:#fff;
}
 
.menu {
    width:1000px;
    margin:0px auto;
}
 
.menu li {
    margin:0px;
    list-style:none;
}
 
.menu a {
    transition:all linear 0.15s;
    color:black;
    text-transform: uppercase;
   font-family: 'Shift', sans-serif;
}
 
.menu li:hover > a, .menu .current-item > a {
    text-decoration:none;
    color:deepskyblue;
}
 
.menu .arrow {
    font-size:11px;
    line-height:0%;
}
 
/*----- Top Level -----*/
.menu > ul > li {
    float:left;
    display:inline-block;
    position:relative;
    font-size:11px;
    font-weight:bold;
}
 
.menu > ul > li > a {
    padding:9px 9px;
    display:inline-block;
    text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
 
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
    background:#fff;
}
 
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
    z-index:1;
    opacity:1;
}
 
.sub-menu {
    width:160%;
    padding:5px 0px;
    position:absolute;
    top:100%;
    left:0px;
    z-index:-1;
    opacity:0;
    transition:opacity linear 0.15s;
    box-shadow:0px 2px 3px rgba(0,0,0,0.2);
    background:#fff;
}
 
.sub-menu li {
    display:block;
    font-size:11px;
    font-weight:bold;
}
 
.sub-menu li a {
    padding:10px 30px;
    display:inline;
}

<!DOCTYPE html>
<html>

  <head>
    <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/shift.css" rel="stylesheet">
    
    <link rel="stylesheet" href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css">
    <link rel="stylesheet" href="main.css">
      <title>iTravelAway - Destinations</title>
  </head>

  <body>
    
        <div class="menu-wrap">
    <nav class="menu">
        <ul class="clearfix">
            <li><a href="index.html">Home</a></li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Contact Us</a></li>
            <li>
                <a href="#">Useful Information<span class="arrow">&#9660;</span></a>
                <ul class="sub-menu">
                    <li><a href="#">Travel Insurance</a></li>
                </ul>
            </li>
            <li class ="current-item"><a href="destinations.html">Destinations</a></li>
            <li><a href="#">Airlines</a></li>
            <li><a href="#">Cruiselines</a></li>
            <li><a href="#">Hotels</a></li>
            <li><a href="#">Weddings & Honeymoons</a></li>
        </ul>
    </nav>
</div>
    <div class="jumbotron">
    </div> 
          <div class ="neighborhood-guides">
    <div class ="container">
<h2></h2>
        <h2></h2>
    <center><div class="row">
    <div class="col-md-4">
    <div class="Thumbnail">
    <img src="http://i.imgur.com/6mrToqb.jpg">
        <h3><font face="minecraft">Bermuda</font></h3>
       <p><font face="minecraft">Description</font></p>
        <h2></h2>
       <img src="http://i.imgur.com/eu38Pjt.jpg">
            <h3><font face="minecraft">Dominican Republic</font></h3>
            <p><font face="minecraft">Description</font></p>
        <h2></h2>
    </div>
    </div>
    <div class="col-md-4">
         <img src="http://i.imgur.com/iYueold.jpg">
     <h3><font face="minecraft">Mexico</font></h3>
 <p><font face="minecraft">Description</font></p>
        <h2></h2>
        <img src="http://i.imgur.com/8dn74Ao.jpg">
     <h3><font face="minecraft">Bahamas</font></h3>
 <p><font face="minecraft">Description</font></p>
   </div>
    </div>
    <div class="col-md-4">
    <div class="Thumbnail">
    <image src="http://i.imgur.com/ekLNRWw.png">
    </div>
    </div>
        </div>
        </div>
        </div>
        </center>
    
 

   <center><div class="learn-more">
	  <div class="container">
		<div class="row">
	      <div class="col-md-4">
			<h3></h3>
			<p></p>
	      </div>
		  <div class ="col-md-4">
			<h3></h3>
			<p></p>
		  </div>
		  <div class ="col-md-4">
			<h3></h3>
			<p></p>
              </center>
		  </div>
	    </div>
	  </div>
	</div>
  </body>
</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

你在这里完全错误地使用了列和行。 我是否正确猜测你希望每一行都有3个标志? 如果是这样,您的布局应如下

    <div class="row">
    <div class="col-md-4">
        <div class="Thumbnail">
            <img src="http://i.imgur.com/6mrToqb.jpg">
            <h3><font face="minecraft">.......</font></h3>
            <p><font face="minecraft">........</font></p>
        </div>
    </div>

    <div class="col-md-4">
        <div class="Thumbnail">
            <img src="http://i.imgur.com/eu38Pjt.jpg">
            <h3><font face="minecraft">.......</font></h3>
            <p><font face="minecraft">........</font></p>
        </div>
    </div>    

    <div class="col-md-4">
        <div class="Thumbnail">
            <img src="http://i.imgur.com/iYueold.jpg">
            <h3><font face="minecraft">.......</font></h3>
            <p><font face="minecraft">........</font></p>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-4">
        <div class="Thumbnail">
            <img src="http://i.imgur.com/8dn74Ao.jpg">
            <h3><font face="minecraft">.......</font></h3>
            <p><font face="minecraft">........</font></p>
        </div>
    </div>

    <div class="col-md-4">
        <div class="Thumbnail">
            <img src="http://i.imgur.com/ekLNRWw.png">
            <h3><font face="minecraft">.......</font></h3>
            <p><font face="minecraft">........</font></p>
        </div>
    </div>    

</div>

这也将在第二行留出空间,以便添加另一个图像,其中包含跨越剩余4列的div

答案 1 :(得分:0)

你关闭最后一个div太快了。在您的代码中,您在最后一列附近有错误。你有:

   <div class="col-md-4">
         <img src="http://i.imgur.com/iYueold.jpg">
     <h3><font face="minecraft">Mexico</font></h3>
 <p><font face="minecraft">Description</font></p>
        <h2></h2>
        <img src="http://i.imgur.com/8dn74Ao.jpg">
     <h3><font face="minecraft">Bahamas</font></h3>
 <p><font face="minecraft">Description</font></p>
   </div>
    </div><!-- Closes Row --> 
    <div class="col-md-4">
    <div class="Thumbnail">
    <image src="http://i.imgur.com/ekLNRWw.png">
    </div>
    </div>

应该是:

   <div class="col-md-4">
         <img src="http://i.imgur.com/iYueold.jpg">
     <h3><font face="minecraft">Mexico</font></h3>
 <p><font face="minecraft">Description</font></p>
        <h2></h2>
        <img src="http://i.imgur.com/8dn74Ao.jpg">
     <h3><font face="minecraft">Bahamas</font></h3>
 <p><font face="minecraft">Description</font></p>
   </div>
    <div class="col-md-4">
    <div class="Thumbnail">
    <image src="http://i.imgur.com/ekLNRWw.png">
    </div>
    </div>
   </div><!-- Closes Row -->