我目前正在研究一种方法来显示带有封面、标题和发行日期的缩略图的电影列表。对于短标题来说,整个过程都很好,但是如果涉及到更长的标题,整个事情就会变得一团糟。
你能告诉我如何使文本对齐的图像,我的结果如下所示的图片?
我感谢所有的小费。
代码(在“完整页面”-Mode中运行代码片段以获得最佳体验)
header {
background-color: grey;
margin: 3px;
padding-left: 7px;
}
header > h2 {
display: inline-block;
}
#info {
padding-left: 5px;
margin: 1px;
float: left;
width: 69%;
}
#result {
float: right;
width: 29%;
margin:1px;
}
.pillLink > h {
display: inline-block;
}
.pillLink {
display: inline-block;
padding-left: 20px;
}
.pill > #cover {
height: 100px;
outline: 2px solid white;
}
.pill {
padding: 7px;
margin: 10px;
background-color: silver;
-webkit-border-radius: 7px!important;
-moz-border-radius: 7px!important;
border-radius: 7px!important;
border: 1px solid grey
}
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="pills_style.css">
</head>
<body>
<div id="info">
</div>
<div id="result">
<h2>similar results</h2>
<div>
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" id="cover">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink"><h3>Very Long Sample Text 4: A new Hope Extended Cut</h3></a>
<span>(2014)</span>
</div>
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" id="cover">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink"><h3>Very Long Sample Text 7: The Force Awakens 3D</h3></a>
<span>(2014)</span>
</div>
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" id="cover">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink"><h3>Short Sample Text 10: XXS</h3></a>
<span>(2014)</span>
</div>
</div>
</div>
</body>
</html>
它应该是这样的:
发布于 2016-01-07 13:33:22
将下面的行添加到pillLink css类中,您就可以了。
max-width: calc(100% - 75px);
编辑完整片段:
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" class="cover">
<span class="pill-content">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink">Very Long Sample Text 4: A new Hope Extended Cut<span class="date">(2014)</span></a>
</span>
</div>
.pill-content{
display: inline-block;
vertical-align: middle;
max-width: calc(100% - 92px);
margin-left: 20px;
}
.pillLink {
display: inline-block;
font-size:24px;
}
.date{
font-size:14px;
color: initial;
margin-left: 8px;
}
.pill > .cover {
outline: 2px solid #FFF;
width: 68px;
max-height: 100px;
}
发布于 2016-01-07 14:24:39
您也可以使用Bootstrap的默认组件媒体-对象,否则您必须稍微更改html和css。
* {
box-sizing: border-box;
/* browser reset */
}
header {
background-color: grey;
margin: 3px;
padding-left: 7px;
}
header > h2 {
display: inline-block;
}
#result {
float: left;
width: 100%;
}
.pillLink > h {
display: inline-block;
}
.pillLink {
display: inline-block;
padding-left: 10px;
}
.pill {
padding: 7px;
background-color: silver;
-webkit-border-radius: 7px!important;
-moz-border-radius: 7px!important;
border-radius: 7px!important;
border: 1px solid grey;
margin-bottom: 20px;
/* for giving some space at bottom */
width: 100%;
overflow: hidden;
/* nothing goes outside */
}
.pill-img {
width: 68px;
/* some xyz width and height as you have given*/
height: 100px;
overflow: hidden;
position: relative;
z-index: 10;
float: left;
/* to make next div fall aside */
}
.pill-img img {
max-width: 100%;
height: auto;
}
.pill-text {
margin-left: -68px;
padding-left: 78px;
position: relative;
z-index: 5;
width: 100%;
float: left;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="pills_style.css">
<div id="result">
<h2>similar results</h2>
<div>
<div class="pill">
<div class="pill-img">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg">
</div>
<div class="pill-text">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink">
<h3>Very Long Sample Text 4: A new Hope Extended Cut</h3>
</a>
<span>(2014)</span>
</div>
</div>
<div class="pill">
<div class="pill-img">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg">
</div>
<div class="pill-text">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink">
<h3>Very Long Sample Text 7: The Force Awakens 3D</h3>
</a>
<span>(2014)</span>
</div>
</div>
<div class="pill">
<div class="pill-img">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg">
</div>
<div class="pill-text">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink">
<h3>Short Sample Text 10: XXS</h3>
</a>
<span>(2014)</span>
</div>
</div>
</div>
</div>
发布于 2016-01-07 13:58:23
header {
background-color: grey;
margin: 3px;
padding-left: 7px;
}
header > h2 {
display: inline-block;
}
#info {
padding-left: 5px;
margin: 1px;
float: left;
width: 69%;
}
#result {
float: right;
width: 29%;
margin:1px;
}
.pillLink > h {
display: inline-block;
}
.pillLink {
display: inline-block;
padding-left: 20px;
max-width: calc(100% - 75px);
}
.pill > #cover {
height: 100px;
outline: 2px solid white;
}
.pill {
padding: 7px;
margin: 10px;
background-color: silver;
-webkit-border-radius: 7px!important;
-moz-border-radius: 7px!important;
border-radius: 7px!important;
border: 1px solid grey
}
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="pills_style.css">
</head>
<body>
<div id="info">
</div>
<div id="result">
<h2>similar results</h2>
<div>
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" id="cover">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink"><h3>Very Long Sample Text 4: A new Hope Extended Cut <span>(2014)</span></h3></a>
</div>
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" id="cover">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink"><h3>Very Long Sample Text 7: The Force Awakens 3D <span>(2014)</span></h3></a>
</div>
<div class="pill">
<img src="http://3dprint.com/wp-content/uploads/2014/11/int3.jpg" id="cover">
<a href="http://www.imdb.com/title/tt0816692" class="pillLink"><h3>Short Sample Text 10: XXS <span>(2014)</span> </h3></a>
</div>
</div>
</div>
</body>
</html>
https://stackoverflow.com/questions/34656382
复制相似问题