-1

我有 3 个具有悬停属性的图像,它将作为指向我网站上另一个页面的超链接。但是,我不知道如何将 3 个图像定位到同一行。这是一个带有代码的 jsFiddle 页面

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

4

5 回答 5

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 */
}

一个固定的 jsFiddle

于 2013-07-10T16:15:04.060 回答
0

通过添加这个:

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

它为我解决了问题:D

于 2013-07-10T16:10:16.340 回答
0

将包含图像的 s的 CSSdisplay属性设置为:divinline-block

.view {
    display: inline-block;
}

jsFiddle

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

于 2013-07-10T16:15:10.017 回答
0

在您的视图类规则中,添加float:left;

jsFiddle 示例

于 2013-07-10T16:11:43.127 回答
0

所有你需要的是float: left.viewdiv

看看 - 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;
}
于 2013-07-10T16:11:45.707 回答