Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html CSS列表项文本和图标对齐_Html_Css - Fatal编程技术网

Html CSS列表项文本和图标对齐

Html CSS列表项文本和图标对齐,html,css,Html,Css,我正在创建一个具有css属性的ul列表 <div class="footer" style="width: 100%; height: 40px; background-color: #00b3ee"> <ul style="list-style-type: none; margin: 0; padding: 0; overflow: hidden; "> <li style="float: left; border-right:1px so

我正在创建一个具有css属性的ul列表

<div class="footer" style="width: 100%; height: 40px; background-color: #00b3ee">
    <ul style="list-style-type: none; margin: 0; padding: 0; overflow: hidden; ">
        <li style="float: left; border-right:1px solid #bbb;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-bell"></i></a>
        </li>
        <li style="float: left; border-right:1px solid #bbb;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-cog"></i></a>
        </li>
    </ul>
</div>

看起来是这样的:

<div class="footer" style="width: 100%; height: 40px; background-color: #00b3ee">
    <ul style="list-style-type: none; margin: 0; padding: 0; overflow: hidden; ">
        <li style="float: left; border-right:1px solid #bbb; overflow: hidden;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-bell" style="display: block;"></i></a>
        </li>
        <li style="float: left; border-right:1px solid #bbb; overflow: hidden;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-cog" style="display: block;"></i></a>
        </li>
    </ul>
</div>

但是我想让文本和图标在中间对齐,一个在另一个下面。

只需这样做:

.footer{
    width: 100%;
    height: 40px; 
    background-color: #00b3ee;
}
.footer li{
    float: left; 
    border-right:1px solid #bbb;
}
.footer li a{
    display: block;
    color: white;
    text-align: center; 
    padding: 10px 10px; 
    text-decoration: none;
}
/* For the icon : */
.footer li a i{
    text-align: center;
    display: block;
}
这将在按钮文本上方设置图标。

只需执行以下操作:

.footer{
    width: 100%;
    height: 40px; 
    background-color: #00b3ee;
}
.footer li{
    float: left; 
    border-right:1px solid #bbb;
}
.footer li a{
    display: block;
    color: white;
    text-align: center; 
    padding: 10px 10px; 
    text-decoration: none;
}
/* For the icon : */
.footer li a i{
    text-align: center;
    display: block;
}

这将在按钮中的文本上方设置图标。

要使图标显示在文本下方,必须将
li
元素设置为
溢出:隐藏
,并将
i
设置为
显示:块
,如下所示:

<div class="footer" style="width: 100%; height: 40px; background-color: #00b3ee">
    <ul style="list-style-type: none; margin: 0; padding: 0; overflow: hidden; ">
        <li style="float: left; border-right:1px solid #bbb; overflow: hidden;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-bell" style="display: block;"></i></a>
        </li>
        <li style="float: left; border-right:1px solid #bbb; overflow: hidden;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-cog" style="display: block;"></i></a>
        </li>
    </ul>
</div>


应该说,将所有的样式化代码放在CSS样式表中会更好,因为在大多数情况下,内联样式化是不好的做法。

要使图标显示在文本下方,必须将
li
元素设置为
溢出:隐藏
i
设置为
显示:块
,如下所示:

<div class="footer" style="width: 100%; height: 40px; background-color: #00b3ee">
    <ul style="list-style-type: none; margin: 0; padding: 0; overflow: hidden; ">
        <li style="float: left; border-right:1px solid #bbb; overflow: hidden;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-bell" style="display: block;"></i></a>
        </li>
        <li style="float: left; border-right:1px solid #bbb; overflow: hidden;">
            <a href="#" style="display: block;color: white;text-align: center; padding: 10px 10px; text-decoration: none;">item-1 <i class="fa fa-cog" style="display: block;"></i></a>
        </li>
    </ul>
</div>


应该说,将所有样式化代码放在CSS样式表中会更好,因为在大多数情况下,内联样式化是不好的做法。

请将以下内容设置为相应的元素:
div
-
宽度=20%;高度=100px
li


它在chrome中运行良好。

请将以下各项设置为相应的元素:
div
-
宽度=20%;高度=100px
li

它在铬合金中工作良好