我有这个图标fa fa-long-arrow-right
,我希望它们在我的div中居中。我怎样才能实现这一目标?可以用bootstrap完成吗?
jQuery(document).ready(function($) {
//portfolio - show link
$('.fdw-background').hover(
function() {
$(this).animate({
opacity: '1'
});
},
function() {
$(this).animate({
opacity: '0'
});
}
);
});
.tiles_border {
border: 1px #ffffff solid;
border-radius: 6px;
}
.fdw-background {
background-color: rgba(0, 0, 0, 0.6);
opacity: 0;
width: 100%;
height: 100%;
border: 1px #ffffff solid;
border-radius: 6px;
cursor: pointer;
}
.fdw-background h2 {
font-weight: 700;
font-family: 'Dosis', sans-serif;
text-align: center;
color: #FFF;
}
.fdw-background p {
text-align: center;
color: #fff;
font-size: 20px;
}
.fdw-background .fdw-port {
text-align: center;
padding: 0 40px 0;
}
.fdw-background .fdw-port a {
padding: 8px 15px;
font-size: 1em;
}
/*subtitle*/
.fdw-subtitle {
font-size: 0.8em;
margin-top: -20px;
color: #0CF;
}
.fdw-subtitle a {
color: #F90;
}
#koncerty {
background-image: url("http://placehold.it/400x550");
height: 400px;
background-repeat: no-repeat;
background-size: cover;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/62cf094036.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div id="koncerty" class="tiles_border">
<div style="opacity: 0;" class="fdw-background atrakcje-tekst">
<h2>KONCERTY</h2>
<br>
<p>Na targach wystąpią:
<br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Andre</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Bobi</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Kosmokwaki</i>
</p>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
你首先要做的两种方法是使用div上的bootstrap col-offset-4类,它包含图标,它将为你提供4个白色空格列 请注意,div中的类从col-md-6更改为col-md-offset-4
<div class="col-md-offset-4 col-sm-12">
<div id="koncerty" class="tiles_border">
<div style="opacity: 0;" class="fdw-background atrakcje-tekst">
<h2>KONCERTY</h2>
<br>
<p>Na targach wystąpią:
<br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Andre</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Bobi</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Kosmokwaki</i>
</p>
</div>
</div>
</div>
其他方法是使用col-md-12设置全宽列,并使用文本中心类将图标置于中心
<div class="col-sm-12 text-center">
<div id="koncerty" class="tiles_border">
<div style="opacity: 0;" class="fdw-background atrakcje-tekst">
<h2>KONCERTY</h2>
<br>
<p>Na targach wystąpią:
<br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Andre</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Bobi</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Kosmokwaki</i>
</p>
</div>
</div>
</div>
答案 1 :(得分:0)
您可以在div中使用内置类.text-center,它将使所有内联元素或文本成为div的中心。
您可以避免每个i标记的CSS声明居中。
此外,如果你想让你的div包装器与浏览器居中对齐,你应该在div中使用col-md-offset-4 col-md-5 col-sm-12而不是你目前使用的使用
随时回复并讨论以获得更多说明。
jQuery(document).ready(function($) {
//portfolio - show link
$('.fdw-background').hover(
function() {
$(this).animate({
opacity: '1'
});
},
function() {
$(this).animate({
opacity: '0'
});
}
);
});
.tiles_border {
border: 1px #ffffff solid;
border-radius: 6px;
}
.fdw-background {
background-color: rgba(0, 0, 0, 0.6);
opacity: 0;
width: 100%;
height: 100%;
border: 1px #ffffff solid;
border-radius: 6px;
cursor: pointer;
}
.fdw-background h2 {
font-weight: 700;
font-family: 'Dosis', sans-serif;
text-align: center;
color: #FFF;
}
.fdw-background p {
text-align: center;
color: #fff;
font-size: 20px;
}
.fdw-background .fdw-port {
text-align: center;
padding: 0 40px 0;
}
.fdw-background .fdw-port a {
padding: 8px 15px;
font-size: 1em;
}
/*subtitle*/
.fdw-subtitle {
font-size: 0.8em;
margin-top: -20px;
color: #0CF;
}
.fdw-subtitle a {
color: #F90;
}
#koncerty {
background-image: url("http://placehold.it/400x550");
height: 400px;
background-repeat: no-repeat;
background-size: cover;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/62cf094036.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div id="koncerty" class="tiles_border">
<div style="opacity: 0;" class="fdw-background atrakcje-tekst">
<h2>KONCERTY</h2>
<br>
<p>Na targach wystąpią:
<br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Andre</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Bobi</i> <br>
<i class="fa fa-long-arrow-right" aria-hidden="true">Kosmokwaki</i>
</p>
</div>
</div>
</div>
</div>
</div>