[英]Vertical alignment of elements
I have HTML code with an image and author description: 我有带有图像和作者描述的HTML代码:
<div class="blog-article-author">
<div class="blog-article-author-details">
<div class="post-author-image-desc">
<img alt="" src="1.jpg" height="75" width="75">
</div>
<h6><a href="#" title="Posts by admin">admin</a></h6>
<p>Lorem Ipsum</p>
</div>
</div>
I also have CSS: 我也有CSS:
.blog-article-author {
border: 1px solid #d7d7d7;
padding: 20px 30px 35px;
margin: 75px 0;
}
.blog-article-author-details {
padding-top: 5px;
}
.post-author-image-desc {
text-align: center;
}
.page-content .blog-article img {
float: left;
}
.blog-article-author-details h6 {
padding-top: 25px;
}
I want to align the description vertically. 我想垂直对齐描述。
image
image description here
image
I tried to use padding and margin. 我尝试使用填充和边距。 But I don't know the length of <p>
. 但是我不知道<p>
的长度。 So I need to correct my CSS. 因此,我需要更正我的CSS。
Use the property vertical-align: text-top; 使用属性vertical-align:text-top;
Or where ever you want it to align with. 或您希望它与之保持一致的地方。
I'm not sure I've completely understood you, but do you mean display elements in a line under the image? 我不确定我是否已完全理解您,但是您是说在图像下方的一行中显示元素吗? If that's what you want you could move the description inside the div that contains the image. 如果那是您想要的,则可以在包含图像的div中移动说明。 See snippet below: 请参见下面的代码段:
.blog-article-author { border: 1px solid #d7d7d7; padding: 20px 30px 35px; margin: 75px 0; } .blog-article-author-details { padding-top: 5px; } .post-author-image-desc { text-align: center; } .page-content .blog-article img { float: left; } .blog-article-author-details h6 { padding-top: 25px; }
<div class="blog-article-author"> <div class="blog-article-author-details"> <div class="post-author-image-desc"> <img alt="" src="http://placehold.it/200x200" height="75" width="75"> <h6><a href="#" title="Posts by admin">admin</a></h6> <p>Lorem Ipsum</p> </div> </div> </div>
I believe the css property vertical-align
will help? 我相信CSS属性vertical-align
会有所帮助吗?
For example: vertical-align:middle
例如: vertical-align:middle
The problem is really difficult to understand, but as far as I can understand, the following code will help you. 这个问题确实很难理解,但是据我所知,以下代码将为您提供帮助。
.blog-article-author { border: solid 1px #DDD; padding: 10px; } .post-author-image-desc { display:table; } .post-author-image-desc img { float:left; } .post-author-image-desc h6 { margin: 0px 0px 4px 0px; } .post-author-image-desc p { margin: 0px; } .post-author-image-desc .post-full-desc { display:table-cell; vertical-align:middle; padding: 4px; }
<div class="blog-article-author"> <div class="blog-article-author-details"> <div class="post-author-image-desc"> <img alt="" src="http://www.sheffield.com/wp-content/uploads/2013/06/placeholder.png" height="100" width="100"> <div class="post-full-desc"> <h6>Admin</h6> <p>Lorem ipsum dolor sit amet, ei vix ubique meliore. Vivendum honestatis mea ex.</p> </div> <div class="clear"> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.