[英]How to style font-awesome icons in css?
I have a screenshot below which I have replicated in HTML/CSS. 我在下面有一个截图,我已经在HTML / CSS中复制了。 The design is exactly the same both for mobile and desktop view .
移动和桌面视图的设计完全相同 。 In the design, the angle dropdown font-awesome icons (marked with arrow in the screenshot) are aligned properly with the headings which is not the case in my design in mobile view.
在设计中,角度下拉字体 - 令人敬畏的图标(在屏幕截图中用箭头标记)与标题正确对齐,这在我的移动视图设计中并非如此。
1st Image: 第一张图片:
I have created the fiddle for the above screenshot. 我为上面的截图创建了小提琴 。 For some reasons, I am not seeing the mobile view in the fiddle (Is there any way we can enable mobile view in the fiddle?) .
由于某些原因,我没有看到小提琴中的移动视图(我们有什么方法可以在小提琴中启用移动视图?) 。 The snippets of HTML code which I have used in the fiddle is:
我在小提琴中使用的HTML代码片段是:
<tr>
<th scope="col">Name <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
<th scope="col" class="number">Number <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
<th scope="col" class="table2">Table <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
<th scope="col" class="status">Status <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
</tr>
On mobile view (as shown below in the screenshot) on my pc, I am seeing the Number and Table headings over the angle dropdown icon. 在我的电脑上的移动视图(如屏幕截图中所示)中 ,我看到角度下拉图标上的数字和表格标题。
2nd Image : 第二张图片 :
Problem Statement: 问题陈述:
I am wondering what changes I need to make in the fiddle so that Number and Table headings are aligned with the angle dropdown font-awesome icon ( marked by arrow in the 1st image ) in the mobile view. 我想知道我需要在小提琴中进行哪些更改,以便数字和表格标题与移动视图中的角度下拉字体 - 真棒图标 ( 在第一张图像中用箭头标记) 对齐 。
For some reasons, I am not able to see the mobile view in the fiddle. 由于某些原因,我无法在小提琴中看到移动视图。
Just use the Bootstrap 4 text-nowrap
class to the table th... 只需使用Bootstrap 4
text-nowrap
类到表...
https://jsfiddle.net/9shn3qxz/ https://jsfiddle.net/9shn3qxz/
<div class="table-responsive body-manage-attendees">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Name <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
<th scope="col" class="number text-nowrap">Number <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
<th scope="col" class="table2 text-nowrap">Table <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
<th scope="col" class="status text-nowrap">Status <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th>
</tr>
</thead>
<tbody>
<tr>
<td class="left">Amanda Doe</td>
<td class="number1">250</td>
<td class="table1">2</td>
<td class="right-bill">Bill</td>
</tr>
<tr>
<td class="left">Andy Doe</td>
<td class="number1">14</td>
<td class="table1">1</td>
<td class="right-bill">Bill</td>
</tr>
</tbody>
</table>
</div>
It seems as though you have two options that immediately come to mind. 好像你有两个选项可以立即浮现在脑海中。
Surround your table with <div class="table-responsive">
to ensure responsiveness. 使用
<div class="table-responsive">
围绕您的桌子,以确保响应。
Since you are using Bootstrap 4, I'll keep it as "mobile-first." 由于您使用的是Bootstrap 4,我会将其保持为“移动优先”。
th {
font-size: 14px; // Smallest font size you want them to render
}
@media (min-width: 768px) {
// After the screen is at least 768px wide, use larger font size
// alter the min-width as many times as needed or appropriate
th{
font-size: 16px;
}
}
This is basically what you would do inside of your CSS. 这基本上就是你在CSS里面做的事情。 Maintain the mobile view first, and build up to the larger display sizes.
首先保持移动视图,并构建更大的显示尺寸。
Playing around with the styles, removing the left/right padding on .table td, .table th
seemed to fix the icon issue. 玩这些样式,删除
.table td, .table th
上的左/右填充.table td, .table th
似乎解决了图标问题。 You might just want to work on adjusting the column padding for mobile views. 您可能只想调整移动视图的列填充。
The easiest way to do this will be to add white-space:nowrap
to the th
, so that the words won't get splitted up. 最简单的方法是添加
white-space:nowrap
到th
,这样单词就不会被分割出来。 You should however add some responsiveness to the table. 但是,您应该为表添加一些响应。
.table td, .table th { border-top: none! important; padding-left: 3%; } .table thead th { border-bottom: none! important; white-space: nowrap; } .table td.left { padding-right: 32%; } .dropdown a { color: #676767; font-weight: bold; font-size: 14px; } .dropdown li { padding-left: 20px; } .dropdown li:hover { background-color: #EDEDED; } .body-manage-attendees { width: 100% !important; } .body-manage-attendees tbody tr:hover { background-color: #EDEDED; } .body-manage-attendees .number { padding-left: 2%; padding-right: 6%; } .body-manage-attendees .table1 { padding-left: 1%; text-align: center; padding-right: 6%; } .body-manage-attendees .table2 { padding-left: 1%; text-align: center; padding-right: 6%; } .body-manage-attendees .status { padding-left: 1%; text-align: center; } .body-manage-attendees .right { padding-left: 1%; text-align: center; } .body-manage-attendees .right-bill { padding-left: 1%; color: white; text-align: center; border: 1px solid white; background-color: #1173B7; } .body-manage-attendees .right-nobill { padding-left: 1%; text-align: center; border: 1px solid white; color: black; } .body-manage-attendees .right-unapid { padding-left: 1%; color: white; text-align: center; border: 1px solid white; background-color: #1173B7; } .body-manage-attendees .right-itemsreceived { padding-left: 1%; color: white; text-align: center; border: 1px solid white; background-color: #10314C; } .square { display: inline-block; border-radius: 5px; border: 1px solid white; margin-right: 5%; height: 15px; width: 15px; vertical-align: middle; } .square.white { display: inline-block; border-radius: 5px; border: 1px solid white; background-color: white; height: 15px; margin-right: 10%; width: 15px; vertical-align: middle; } .right-itemswaiting span { vertical-align: middle; padding-left: 1%; } .table td, .table th { border-top: none! important; padding-left: 3%; } .table thead th { border-bottom: none! important; } .table td.left { padding-right: 32%; } .right-itemswaiting { user-select: none; -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; -o-user-select: none; } .right-itemsreceived { user-select: none; -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; -o-user-select: none; } .body-manage-attendees tbody tr:hover { background-color: #EDEDED; } .body-manage-attendees .number { padding-left: 2%; padding-right: 6%; } .body-manage-attendees .table1 { padding-left: 1%; text-align: center; padding-right: 6%; } .body-manage-attendees .table2 { padding-left: 1%; text-align: center; padding-right: 6%; } .body-manage-attendees .status { padding-left: 1%; text-align: center; } .body-manage-attendees .right { padding-left: 1%; text-align: center; } .body-manage-attendees .right-bill { padding-left: 1%; color: white; text-align: center; border: 1px solid white; background-color: #1173B7; } .body-manage-attendees .right-nobill { padding-left: 1%; text-align: center; border: 1px solid white; color: black; } .body-manage-attendees .right-unpaid { padding-left: 1%; color: white; text-align: center; border: 1px solid white; background-color: #1173B7; } .body-manage-attendees .right-itemsreceived { padding-left: 1%; color: white; text-align: center; background-color: #10314C; } .body-manage-attendees .right-itemswaiting { padding-left: 1%; text-align: center; color: white; border: 1px solid white; background-color: #10314C; } .body-manage-attendees .right-unpaid { padding-left: 1%; color: white; background-color: #1173B7; text-align: center; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="table-responsive body-manage-attendees"> <table class="table table-hover"> <thead> <tr> <th scope="col">Name <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th> <th scope="col" class="number">Number <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th> <th scope="col" class="table2">Table <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th> <th scope="col" class="status">Status <i class="fa fa-angle-down" style="font-size: 15px;" aria-hidden="true"></i></th> </tr> </thead> <tbody> <tr> <td class="left">Amanda Doe</td> <td class="number1">250</td> <td class="table1">2</td> <td class="right-bill">Bill</td> </tr> <tr> <td class="left">Andy Doe</td> <td class="number1">14</td> <td class="table1">1</td> <td class="right-bill">Bill</td> </tr> </tbody> </table> </div>
You could set a min-width of the table td and th. 您可以设置表td和th的最小宽度。
.table td,
.table th {
border-top: none! important;
padding-left: 3%;
min-width:140px;
}
You may have to tweak the actual value applied to min-width. 您可能需要调整应用于最小宽度的实际值。 This will prevent the columns from taking up less than the set width, but will not restrict the columns to take up only that amount of space.
这将防止列占用小于设置的宽度,但不会限制列仅占用该空间量。
I would also consider applying a different min-width per column since the Number column will require around 140px but the Table column only needs about 80px. 我还会考虑每列应用不同的最小宽度,因为Number列需要大约140px,但Table列只需要大约80px。 This will leave more space available for the Name.
这将为Name留出更多可用空间。
To fix this, you can try adding the Bootstrap 4 text-nowrap
class to the table th. 要解决此问题,您可以尝试将Bootstrap 4
text-nowrap
类添加到表中。
OR you can edit the css property of table th to have white-space:nowrap
或者您可以编辑表格的css属性以获得
white-space:nowrap
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.