我正在尝试将两个div并排对齐 - 一个div包含一个图像,另一个包含有关图像中人物的文本(即个人资料),我无法弄清楚如何将div添加到虽然排队在一起,我已经尝试浮动和使用表格单元格显示,它似乎永远不会坚持。也许其他人可以帮我解决问题?
HTML
<div id="tai-prof">
<div class="prof-content">
<div class="picture">
<img src="http://i.imgur.com/BXgeNF3.png">
</div>
<div class="profile">
<div class="prof-desc">
<h2>Name</h2>
<h2 class="desc">Description</h2>
<h2 class="email">email (maybe)</h2>
<span class="prof-bio">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally</span>
<span class="sites"> <a href="#">www.mysite.com</a> | <a href="#">www.mypage.com</a> | <a href="#">my blog</a>
</span>
</div>
</div>
</div>
</div>
CSS
.prof-content, .profile {
float: left;
}
.prof-content .picture {
float: left;
}
.prof-content .picture img {
width: 45%;
}
.prof-content .prof-desc {
display: table-cell;
/*position: relative;
left: -25%;*/
}
答案 0 :(得分:1)
检查你的CSS
.prof-content, .profile {
float: left;
}
.prof-content, .picture {
float: left;
}
.prof-content, .picture, img {
width: 45%;
}
.prof-content .prof-desc {
display: table-cell;
/*position: relative;
left: -25%;*/
}
你错过了逗号
答案 1 :(得分:1)
这应该是你的css:
.prof-content .profile, .prof-content .picture {
float: left;
width:50%;
}
.prof-content .picture img {
width: 90%;
}
请参阅此处的小提琴:http://jsfiddle.net/rqPVD/1/
答案 2 :(得分:1)
如果您在使用display: table-cell
时遇到的问题是文本的第一行有一个空格,那么很可能您忘记默认情况下表格单元格在其基线上垂直对齐。并且由于您在第一个单元格中有一个图像,然后该图像的底部与文本的第一行底部对齐。
所以请记住将vertical-align: top
用于需要与上边缘对齐的单元格(或者您需要的任何内容)。
使用相同的HTML:
<div id="tai-prof">
<div class="prof-content">
<div class="picture">
<img src="http://i.imgur.com/BXgeNF3.png">
</div>
<div class="profile">
<div class="prof-desc">
<h2>Name</h2>
<h2 class="desc">Description</h2>
<h2 class="email">email (maybe)</h2>
<span class="prof-bio">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally</span>
<span class="sites"> <a href="#">www.mysite.com</a> | <a href="#">www.mypage.com</a> | <a href="#">my blog</a>
</span>
</div>
</div>
</div>
</div>
将CSS更改为:
#tai-prof {display: table}
.prof-content {display: table-row}
.prof-content, .profile ,
.prof-content .picture {
display: table-cell;
vertical-align: top;
}
.prof-content .picture {width: 30%}
.prof-content .picture img {
width: 100%;
}