css - 在 div 中将文本排到图像顶部

标签 css html margin

我想在我的 div 中将文本排到图像的顶部。

当前标题:网络研讨会、博客等位于方 block 顶部下方。我在那里有一个样式:vertical-align: top;但它没有与正方形的顶部对齐。

查看我的 fiddle - http://jsfiddle.net/huskydawgs/e9pZr/ HTML

<div id="wrapper-resources">
        <div id="resources_row">
            <div class="resources_cell1">
                <div class="resources_lt">
                    <img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
                <div class="resources_rt">
                    <p><strong>Webinar</strong></p>
                </div>
            </div>
            <div class="resources_cell2">
                <div class="resources_lt">
                    <img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
                <div class="resources_rt">
                    <p><strong>Article</strong></p>
                </div>
            </div>
            <div class="resources_cell3">
                <div class="resources_lt">
                    <img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
                <div class="resources_rt">
                    <p><strong>Blog</strong></p>
                </div>
            </div>
            <div class="resources_cell4">
                <div class="resources_lt">
                    <img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
                <div class="resources_rt">
                    <p><strong>Market</strong></p>
                </div>
            </div>
        </div>
    </div>

CSS

#wrapper-resources {
position:relative;
width:100%;
border: none;
margin: 50px 0 0 0;

#resources_row {
height:100%;
white-space:nowrap;
}

.resources_cell1, .resources_cell2, .resources_cell3, .resources_cell4 {
height:100%;
width:25%;
display:inline-block;
white-space:normal;
}

.resources_lt {
height:100%;
width:33%;
display:inline-block;
white-space:normal;
margin-right: 20px;
vertical-align: top;
}

.resources_rt {
height:100%;
width:50%;
display:inline-block;
white-space:normal;
vertical-align: top;
}

/* Fonts */

#wrapper-resources p {
color: #666666;
font-family: 'SegoeRegular', Helvetica, Arial, sans-serif;
font-size: .9em;
line-height: 1.6em;

最佳答案

您需要将 <p> 的 margin 重置为 0 http://jsfiddle.net/e9pZr/3/

它默认有margin:1em 0;http://reference.sitepoint.com/css/collapsingmargins以获得更多解释。

关于css - 在 div 中将文本排到图像顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21003244/

相关文章:

css - 垂直导航背后的 HTML 文本换行

html - ng-grid 的列菜单的 z-index 问题

Javascript 正在重新加载时执行

css - 为什么 "*"CSS 样式会覆盖 "button"或 "nav button"样式?

css - Margin top 在 IE8 中不工作,但在所有其他浏览器中工作

jquery - 如何让标签动态出现在网页上?

javascript - Bootstrap 4切换不隐藏下一个div

jquery - 可调整大小 : Resize div smaller than contents and make scrollable

jquery - 向左切换菜单

html - margin-block-start 和 margin-top 有什么区别?