html - 框内文本中心

标签 html css

我有一个问题,我现在花了几个小时交易来计算我们的数字,我快要疯了。

我希望图标旁边的文本位于框的中间。但是我不知道我做错了什么,你能不能也批评一下我正在学习的代码。

我的 CSS

#newaltcoins .boximg {
    background-color: #cccccc;
    width: 50px;
    height: 50px;

}

#newaltcoins .box{
    float:left;
    border:#cccccc solid 1px;
    color: black;
    width: 200px;
    height: 50px;
    margin: 5px;
    background-color: #EEEEEE;
    white-space:nowrap;
    text-align: center;

我的html

        <a href="http://google.com">
            <div class="box">  
                    <div class="boximg" >
                           <img src="./alt/alt_logo/etherieum.png">
                               <br>Etherieum
                    </div>    
            </div>
        </a>

example

最佳答案

您可以使用现代浏览器支持的display:flex。此外,您还必须将文本换行,这样您才能更轻松地使用它。

#newaltcoins .boximg {
    display: flex;
    align-items: center;
}

#newaltcoins .boximg span{
    display: block;
    width: 100%;
}
#newaltcoins .boximg img {
    width: 50px;
    height: 50px;
    background-color: #cccccc;
}

#newaltcoins .box{
    float:left;
    border:#cccccc solid 1px;
    color: black;
    width: 200px;
    height: 50px;
    margin: 5px;
    background-color: #EEEEEE;
    white-space:nowrap;
    text-align: center;
   }
<a href="http://google.com" id="newaltcoins">
            <div class="box">   
                    <div class="boximg" >
                           <img src="https://www.ethereum.org/images/logos/ETHEREUM-ICON_Black_small.png">
                           <span>Etherieum</span>
                    </div>    
            </div>
        </a>

关于html - 框内文本中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48696974/

相关文章:

html - 电话号码链接在 Samsung Galaxy S8 上的 Chrome 中打开空白页面

css - 有没有办法,不用手动,给 prismjs 类名加上前缀,因为它与前端框架冲突?

html - 如何将框阴影应用于相邻元素而不出现重叠?

html - 使用 Bootstrap 使一列固定为水平滚动?

html - css 段落跳转

javascript - 得到 NaN,不增加属性值

html - Explorer 11 上的 SharePoint html 脚本编辑器片段问题

javascript - css 过渡高度以隐藏容器中的内容

html - 如何防止 Windows 8.1/8 上的 Modern UI IE 11 自动缩放?

html - Bootstrap 菜单悬停