我在图像滑块的每一侧都有div箭头按钮,我希望它们垂直对齐,两者对齐到div的各自边,左箭头对齐div的左边,右箭头对齐右边它的div。我的问题是,当我使用float:right
和line-height
时,箭头的图像会垂直对齐,但按钮不会垂直对齐。
这是我的HTML:
<div class="row">
<div class="large-1 columns arrow">
<div class="button tertiary previous">
<img src="{{ asset('/img/left-arrow.svg') }}" />
</div>
</div>
<div class="large-10 columns">
<div class="swiper-container">
<div class="swiper-wrapper">
@foreach($issues as $issue)
<div class="swiper-slide">
<img
src="/imagecache/large/{{ $issue->first()->image }}"
onclick="magazineDetail(
'{{ $issue->first()->magazine->id }}',
'{{ $issue->first()->magazine->name }}',
'{{ $issue->first()->magazine->summary ?: '' }}',
'{{ $issue->first()->magazine->image ?: '' }}',
'{{ $issue->first()->image }}'
)"
>
</div>
@endforeach
</div>
</div>
</div>
<div class="large-1 columns arrow">
<div class="button tertiary next">
<img src="{{ asset('/img/right-arrow.svg') }}" />
</div>
</div>
</div>
这是我的scss:
ul {
&.button-group {
margin-left: 0;
li:first-child {
width: 30%;
}
li:not(:last-child) {
margin-right: .7rem;
}
}
}
.button {
text-decoration: none;
line-height: inherit;
&:focus {
outline: none;
background-color: none;
}
&:active {
box-shadow: 0 0 0 0 transparent;
}
&.primary {
background-color: $purple;
color: $white;
&:hover {
background: rgba($purple, 0.4);
}
}
&.secondary {
background-color: $white;
border-color: $black;
color: $black;
&:hover {
background: $white;
border-color: $light-gray;
color: $black;
}
}
&.tertiary {
background: transparent;
border-color: $white;
color: $white;
height: 100%;
font-size: 1.1rem;
padding: .4rem;
&:active {
background: $white;
color: $black;
}
}
&.narrow {
padding-left: 2.2em;
padding-right: 2.2em;
}
&.expand {
width: 100%;
}
}
.carousel {
margin-top: 10%;
.carousel-nav {
text-align: right;
}
.featured-magazines {
margin-top: $global-margin;
}
.button.tertiary {
height: 40px;
line-height: normal;
&.next {
vertical-align:middle;
float:right;
line-height: 200px
}
}
.all {
margin-top: 30px;
width: 100%;
}
.swiper-container{
text-align: center;
}
.arrow {
line-height: 200px;
}
}
答案 0 :(得分:2)
我理解你的问题。只需添加此CSS
即可CSS: -
.columns{
display: inline-block;
vertical-align: middle;
}
您的箭头将垂直对齐滑块图像的中间位置,右箭头和左箭头将水平对齐。
您的问题: -
添加我给定的CSS后: -
答案 1 :(得分:0)
您可以对顶部的箭头使用绝对定位:50%
您还需要在容器row
上进行相对定位,以便绝对定位将其用作锚点。
这是我如何设置它的笔。 http://codepen.io/pstonier/pen/mAvgEV