我可以在每个标题内垂直对齐文字吗?
基本上,我想垂直对齐每个标题内的文本和
,如果它有1行或2行则独立。 ATM看起来好像是在顶部对齐。
我在这个网站上看过不同的帖子,我试图使用它的解决方案,但它们在我的项目中没有用。
请在下面找到代码(html和css)以及可以看到我想要做的图片。
.thumbnail {
position: relative !important;
padding: 0px !important;
margin-bottom: 0px !important;
border-radius:0px !important;
border-right: 1px solid #ddd !important;
border-top: 1px solid #ddd !important;
border-bottom: 1px solid #ddd !important;
border-left: 0px solid #ddd !important;
}
.thumbnail img {
width: 100% !important;
}
.thumbnail .caption {
background-color: #333;
color: #fff !important;
padding: 9px;
padding-top:15px;
height: 100% !important;
}
.hovereffect {
width:100%;
height:100%;
float:left;
overflow:hidden;
position:relative;
text-align:center;
cursor:default;
}
.hovereffect .overlay {
width:100%;
height:100%;
position:absolute;
overflow:hidden;
top:0;
left:0;
opacity:0;
background-color:rgba(0,0,0,0.5);
-webkit-transition:all .4s ease-in-out;
transition:all .4s ease-in-out
}
.hovereffect img {
display:block;
position:relative;
-webkit-transition:all .4s linear;
transition:all .4s linear;
}
.hovereffect:hover img {
-ms-transform:scale(1.2);
-webkit-transform:scale(1.2);
transform:scale(1.2);
}
.hovereffect:hover .overlay {
opacity:1;
filter:alpha(opacity=100);
}
.caption h4 {color:#fff !important; text-align:center; min-height: 55px; line-height:1.3em;}
.caption-2-line {text-align:center; margin-top:15px !important; min-height:50px; line-height:1.5em}
.caption-3-line {letter-spacing:1px; text-align:center; font-weight:600; margin-top:0px !important; margin-bottom:0px !important; line-height:1.3em !important; padding-bottom:30px; min-height:50px !important; font-size:112%; padding-left:0px !important; padding-right:0px !important}

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="Keywords" content="">
<link rel="stylesheet" href="animate.min.css">
<style type="text/css">
body,td,th {
font-family: Open Sans !important;
font-size: 16px !important;
color: #666666 !important;
padding-top:54px
}
</style>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<!--projects-->
<div>
<div class="container-fluid">
<div style="display: flex;" class="row"> <!--remove flex for XS-->
<!--pro4--><div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
<div class="thumbnail hovereffect">
<img src="http://placehold.it/500x300" alt="">
<div class="caption">
<h4>LIFE INSURANCE LANDINGPAGE</h4>
<p class="caption-2-line">Responsive Development / Bootstrap</p>
<br><p class="caption-3-line c0fcfd1">WEB DESIGN</p>
<div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a></div>
</div>
</div>
</div>
<!--pro5--><div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
<div class="thumbnail hovereffect">
<img src="http://placehold.it/500x300" alt="">
<div class="caption">
<h4>BUSINESS CARD</h4>
<p class="caption-2-line">Personalized Design / Print</p>
<br><p class="caption-3-line c0fcfd1">BRANDING</p>
<div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
&#13;
我已经在这篇文章中附上了一个看起来像atm的图像以及我想做的事情。
我试图使用其中一些答案,但它们没有用enter link description here
答案 0 :(得分:1)
这里display:flex
可以解决问题。
使用:
display: flex;
align-items: center;
justify-content: center;
您编辑了代码:
.thumbnail {
position: relative !important;
padding: 0px !important;
margin-bottom: 0px !important;
border-radius: 0px !important;
border-right: 1px solid #ddd !important;
border-top: 1px solid #ddd !important;
border-bottom: 1px solid #ddd !important;
border-left: 0px solid #ddd !important;
}
.thumbnail img {
width: 100% !important;
}
.thumbnail .caption {
background-color: #333;
color: #fff !important;
padding: 9px;
padding-top: 15px;
height: 100% !important;
}
.hovereffect {
width: 100%;
height: 100%;
float: left;
overflow: hidden;
position: relative;
text-align: center;
cursor: default;
}
.hovereffect .overlay {
width: 100%;
height: 100%;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
opacity: 0;
background-color: rgba(0, 0, 0, 0.5);
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out
}
.hovereffect img {
display: block;
position: relative;
-webkit-transition: all .4s linear;
transition: all .4s linear;
}
.hovereffect:hover img {
-ms-transform: scale(1.2);
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
.hovereffect:hover .overlay {
opacity: 1;
filter: alpha(opacity=100);
}
.caption h4 {
color: #fff !important;
text-align: center;
min-height: 55px;
line-height: 1.3em;
display: flex;
align-items: center;
justify-content: center;
}
.caption-2-line {
text-align: center;
margin-top: 15px !important;
min-height: 50px;
line-height: 1.5em;
display: flex;
align-items: center;
justify-content: center;
}
.caption-3-line {
letter-spacing: 1px;
text-align: center;
font-weight: 600;
margin-top: 0px !important;
margin-bottom: 0px !important;
line-height: 1.3em !important;
padding-bottom: 30px;
min-height: 50px !important;
font-size: 112%;
padding-left: 0px !important;
padding-right: 0px !important;
display: flex;
align-items: center;
justify-content: center;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="Keywords" content="">
<link rel="stylesheet" href="animate.min.css">
<style type="text/css">
body,
td,
th {
font-family: Open Sans !important;
font-size: 16px !important;
color: #666666 !important;
padding-top: 54px
}
</style>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<!--projects-->
<div>
<div class="container-fluid">
<div style="display: flex;" class="row">
<!--remove flex for XS-->
<!--pro4-->
<div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
<div class="thumbnail hovereffect">
<img src="http://placehold.it/500x300" alt="">
<div class="caption">
<h4>LIFE INSURANCE LANDINGPAGE</h4>
<p class="caption-2-line">Responsive Development / Bootstrap</p>
<br>
<p class="caption-3-line c0fcfd1">WEB DESIGN</p>
<div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a>
</div>
</div>
</div>
</div>
<!--pro5-->
<div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
<div class="thumbnail hovereffect">
<img src="http://placehold.it/500x300" alt="">
<div class="caption">
<h4>BUSINESS CARD</h4>
<p class="caption-2-line">Personalized Design / Print</p>
<br>
<p class="caption-3-line c0fcfd1">BRANDING</p>
<div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
答案 1 :(得分:0)
克里斯·科伊尔(Chris Coyier)在css-tricks.com上发表了一篇方便的小文章,内容涉及多种以CSS为中心的方法。