图像不会排成一行

时间:2013-07-10 16:05:00

标签: html css image alignment

我有3个具有悬停属性的图像,它将作为我网站上另一个页面的超链接。但是,我无法弄清楚如何将3张图像放在同一条线上。以下是a jsFiddle page代码。

HTML:

<div class="view view-sixth" style="margin-bottom:30px">
     <img src="champions/mode/ashe.jpg">
     <div class="mask">
     <h2>1</h2>
     <p>1</p>
         <a href="http://www.google.com" class="info" target="_blank">Google</a>
     </div>
</div>

<div class="view view-sixth" style="margin-bottom:30px">
     <img src="champions/mode/garen.jpg">
     <div class="mask">
     <h2>2</h2>
     <p>2</p>
         <a href="http://www.google.com" class="info" target="_blank">Google</a>
     </div>
</div>


<div class="view view-sixth" style="margin-bottom:30px">
     <img src="champions/mode/ryze.jpg">
     <div class="mask">
     <h2>3</h2>
     <p>3</p>
          <a href="http://www.google.com" class="info" target="_blank">Google</a>
     </div>
</div>

CSS:

.view-sixth img {
   -webkit-transition: all 0.4s ease-in-out 0.5s;
   -moz-transition: all 0.4s ease-in-out 0.5s;
   -o-transition: all 0.4s ease-in-out 0.5s;
   -ms-transition: all 0.4s ease-in-out 0.5s;
   transition: all 0.4s ease-in-out 0.5s;

}
.view-sixth .mask {
   background: rgba(146,96,91,0.5);
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=0)";
   filter: alpha(opacity=0);
   opacity: 0;
   -webkit-transition: all 0.2s ease-in 0.2s;
   -moz-transition: all 0.2s ease-in 0.2s;
   -o-transition: all 0.2s ease-in 0.2s;
   -ms-transition: all 0.2s ease-in 0.2s;
   transition: all 0.2s ease-in 0.2s;

}
.view-sixth h2 {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=0)";
   filter: alpha(opacity=0);
   opacity: 0;
   background: transparent;
   margin: 20px 40px 0px 40px;
   -webkit-transform: scale(10);
   -moz-transform: scale(10);
   -o-transform: scale(10);
   -ms-transform: scale(10);
   transform: scale(10);
   -webkit-transition: all 0.3s ease-in-out 0.1s;
   -moz-transition: all 0.3s ease-in-out 0.1s;
   -o-transition: all 0.3s ease-in-out 0.1s;
   -ms-transition: all 0.3s ease-in-out 0.1s;
   transition: all 0.3s ease-in-out 0.1s;

}
.view-sixth p {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=0)";
   filter: alpha(opacity=0);
   opacity: 0;
   -webkit-transform: scale(10);
   -moz-transform: scale(10);
   -o-transform: scale(10);
   -ms-transform: scale(10);
   transform: scale(10);
   -webkit-transition: all 0.3s ease-in-out 0.2s;
   -moz-transition: all 0.3s ease-in-out 0.2s;
   -o-transition: all 0.3s ease-in-out 0.2s;
   -ms-transition: all 0.3s ease-in-out 0.2s;
   transition: all 0.3s ease-in-out 0.2s;

}
.view-sixth a.info {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=0)";
   filter: alpha(opacity=0);
   opacity: 0;
   -webkit-transform: translateY(100px);
   -moz-transform: translateY(100px);
   -o-transform: translateY(100px);
   -ms-transform: translateY(100px);
   transform: translateY(100px);
   -webkit-transition: all 0.3s ease-in-out 0.1s;
   -moz-transition: all 0.3s ease-in-out 0.1s;
   -o-transition: all 0.3s ease-in-out 0.1s;
   -ms-transition: all 0.3s ease-in-out 0.1s;
   transition: all 0.3s ease-in-out 0.1s;

}
.view-sixth:hover .mask {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=100)";
   filter: alpha(opacity=100);
   opacity: 1;
   -webkit-transition-delay: 0s;
   -moz-transition-delay: 0s;
   -o-transition-delay: 0s;
   -ms-transition-delay: 0s;
   transition-delay: 0s;


}
.view-sixth:hover img {
   -webkit-transition-delay: 0s;
   -moz-transition-delay: 0s;
   -o-transition-delay: 0s;
   -ms-transition-delay: 0s;
   transition-delay: 0s;


}
.view-sixth:hover h2 {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=100)";
   filter: alpha(opacity=100);
   opacity: 1;
   -webkit-transform: scale(1);
   -moz-transform: scale(1);
   -o-transform: scale(1);
   -ms-transform: scale(1);
   transform: scale(1);
   -webkit-transition-delay: 0.1s;
   -moz-transition-delay: 0.1s;
   -o-transition-delay: 0.1s;
   -ms-transition-delay: 0.1s;
   transition-delay: 0.1s;

}
.view-sixth:hover p {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=100)";
   filter: alpha(opacity=100);
   opacity: 1;
   -webkit-transform: scale(1);
   -moz-transform: scale(1);
   -o-transform: scale(1);
   -ms-transform: scale(1);
   transform: scale(1);
   -webkit-transition-delay: 0.2s;
   -moz-transition-delay: 0.2s;
   -o-transition-delay: 0.2s;
   -ms-transition-delay: 0.2s;
   transition-delay: 0.2s;

}
.view-sixth:hover a.info {
   -ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=100)";
   filter: alpha(opacity=100);
   opacity: 1;
   -webkit-transform: translateY(0px);
   -moz-transform: translateY(0px);
   -o-transform: translateY(0px);
   -ms-transform: translateY(0px);
   transform: translateY(0px);
   -webkit-transition-delay: 0.3s;
   -moz-transition-delay: 0.3s;
   -o-transition-delay: 0.3s;
   -ms-transition-delay: 0.3s;
   transition-delay: 0.3s;

}

.view {
   width: 260px;
   height: 390px;
   border:  solid purple;
   position: relative;
   text-align: center;
   box-shadow: 1px 1px 2px purple;
   cursor: default;


}
.view .mask,.view .content {
   width: 260px;
   height: 390px;
   position: absolute;
      background: rgba(0, 0, 0, 0.7);
   overflow: hidden;
   top: 0;
   left: 0;

}
.view img {
   display: block;
   position: relative;

}
.view h2 {
   text-transform: uppercase;
   color: white;
   text-align: center;
   position: relative;
   font-family: Candara;
   font-size: 20px;
   padding: 30px;
}
.view p {
   font-family: Candara, serif;
   font-size: 20px;
   position: relative;
   color: white;
   padding: 10px 20px 20px;
   text-align: center;
}
.view a.info {
   display: inline-block;
   text-decoration: none;
   padding: 7px 14px;
   background: white;
   color: black;
   text-transform: uppercase;
   -webkit-box-shadow: 0 0 1px #000;
   -moz-box-shadow: 0 0 1px #000;
   box-shadow: 0 0 1px #000;
   border-radius: 5px;
}
.view a.info:hover {
   -webkit-box-shadow: 0 0 5px #000;
   -moz-box-shadow: 0 0 5px #000;
   box-shadow: 0 0 5px #000;
}

任何人都可以给我一些指示吗?


修改:谢谢大家的回复。我的问题现在已经解决了。 :d

5 个答案:

答案 0 :(得分:1)

float: left;添加到.view规则集:

.view {
   width: 260px;
   height: 390px;
   border: solid #800080;
   position: relative;
   text-align: center;
   box-shadow: 1px 1px 2px #800080;
   cursor: default;
   float: left; /* ← add this */
}

A fixed jsFiddle

答案 1 :(得分:0)

添加:

.view-sixth {
    display:inline-block;
width:33%;    
}

它解决了我的问题:D

答案 2 :(得分:0)

根据您的视图类规则,添加float:left;

<强> jsFiddle example

答案 3 :(得分:0)

float: left div

上只需要.view

看看 - http://jsfiddle.net/8P7rB/

.view {
   width: 260px;
   height: 390px;
   border:  solid purple;
   position: relative;
   text-align: center;
   box-shadow: 1px 1px 2px purple;
   cursor: default;
    float: left;
    margin-right: 10px;
}

答案 4 :(得分:0)

将包含图片的display的CSS div属性设置为inline-block

.view {
    display: inline-block;
}

jsFiddle

如果有足够的空间,图像应该对齐。如果您希望图像始终对齐,即使没有足够的空间,请将它们包含在容器中并设置容器的min-width