2
\$\begingroup\$

I would like to create a table where each column header contains a column name and a sort symbol. To do this, I'm using bootstrap. You can see my code below:

.glyphicon-menu-down,
.glyphicon-menu-up {
 display: block!important;
 font-size: 9px;
}
th {
 background-color: #0C69E8;
}
th {
 color: white;
}
th .align {
 display: flex;
 align-items: center;
}
.pointer {
 cursor: pointer;
}
<div class="container" align="center">
 <table class="table">
 <thead>
 <tr>
 <th scope="col">#</th>
 <th scope="col" class="pointer">
 <div style="float:left; margin-right:10px;">First</div>
 <div>
 <div id="up" class="glyphicon glyphicon-menu-up"></div>
 <div id="down" class="glyphicon glyphicon-menu-down"></div>
 </div>
 </th>
 <th scope="col" class="pointer">
 <div class="align">
 <div style="margin-right:10px">Last</div>
 <div class="glyphicon glyphicon-menu-up">
 <div class="glyphicon glyphicon-menu-down"></div>
 </div>
 </div>
 </th>
 <th scope="col" class="pointer">
 <div class="align">
 <div style="margin-right:10px">Handle</div>
 <div class="glyphicon glyphicon-menu-up">
 <div class="glyphicon glyphicon-menu-down"></div>
 </div>
 </div>
 </th>
 </tr>
 </thead>
 <tbody>
 <tr>
 <th scope="row">1</th>
 <td>Mark</td>
 <td>Otto</td>
 <td>@mdo</td>
 </tr>
 <tr>
 <th scope="row">2</th>
 <td>Jacob</td>
 <td>Thornton</td>
 <td>@fat</td>
 </tr>
 <tr>
 <th scope="row">3</th>
 <td>Larry</td>
 <td>the Bird</td>
 <td>@twitter</td>
 </tr>
 </tbody>
 </table>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">

My solution is to use a display flex on the headers column and 2 bootstrap glyphicons. If I don't use a flex display, the elements are not on the same line. I think my solution is not really clean so if someone had a better solution, I'll take it. Could someone give me his opinion on the code?

Thanks for any help

asked Sep 21, 2020 at 19:54
\$\endgroup\$

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.