css - 如何垂直对齐div中的图像?

标签 css html image

如何在div 容器中将图像显示为垂直对齐?

图像“setting.png”放在我附加的代码的最后一列中。请建议解决方案。

.table{
width: 100%;
margin: 20px 0px 20px 0px;
background-color: #EEEEEE;
}

.tableRow{
width: 100%;
clear: both;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #cccccc;
}

.tableCol{
float: left;
height: 40px;
line-height: 40px;
}

<div class="table">
    <div class="tableRow">
        <div class="tableCol" style="width:10%; text-align:center;">1</div>
        <div class="tableCol" style="width:40%">Michael</div>
        <div class="tableCol" style="width:40%">webexp@gmail.com</div>
        <div class="tableCol" style="width:10%;">
        <a href="" ><img src="images/icons/setting.png" alt="Setting" align="absmiddle"  /></a>
        </div>
    </div>  
</div>  

最佳答案

只需添加 (链接前的空格)

  <div class="table">
        <div class="tableRow">
            <div class="tableCol" style="width:10%; text-align:center;">1</div>
            <div class="tableCol" style="width:40%">Michael</div>
            <div class="tableCol" style="width:40%">webexp@gmail.com</div>
            <div class="tableCol" style="width:10%;">&nbsp;
            <a href="" ><img src="images/icons/setting.png" alt="Setting" align="absmiddle"  /></a>
            </div>
        </div>  
    </div> 

更好的解决方案:
将此添加到 css:

img {
margin-top:10px;
}

关于css - 如何垂直对齐div中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12122447/

相关文章:

jquery - 一旦它到达容器 div,将导航栏背景更改为黑色

html - CSS Sprite RWD + 视网膜

javascript - extjs 中的链接按钮

image - 该页面无法在我的flutter应用程序中正确加载页面(已更新)无效的参数:源不得为null

html - 指定列的宽度和文本对齐方式

javascript - 如何禁用指针事件,但允许拖动

jquery - 多个 css 样式应用于一个元素,如何强制一种样式优于另一种样式

html - CSS 视差效果。如何更改上边距

java - 从字节数组中提取图像的宽度、高度、颜色和类型

android - ActionBarSherlock 背景的图像大小