I have a Table and in the <thead> I have a background image, I have a coubple of rows and <th> this is the structure of my markup:
(Im using bootstrap by the way)
<table className="table">
<thead>
<tr>
<th colSpan="12">
<h3 className="table-title">POST APOCALYPTIC HIGHWAY</h3>
</th>
</tr>
<tr className="attributes">
<th className="position"></th>
<th className="img d-none d-sm-table-cell"></th>
<th className="fullname"></th>
<th className="bib text-center">Bib</th>
<th className="age d-none d-sm-table-cell text-center">
Age
</th>
<th className="gender text-center">Gender</th>
<th className="time text-center">Time</th>
<th className="score text-center">Score</th>
</tr>
{/** Ghost row to simulate margin */}
<tr style={{ height: "10px" }}>
<th colSpan="12"></th>
</tr>
</thead>
Im applying a background image through CSS to the <thead> this way:
.leaderboard thead {
background-image: url(./images/black-square-pattern.jpeg);
background-repeat: repeat;
color: #fff;
}
I also make sure there's 0 padding and margin in the <th> elements
.leaderboard thead th {
padding: 0;
margin: 0;
border: none;
}
It looks okay in desktop but for some reason when I test it in Google chrome inspecter the different mobile previews I see some tiny white spaces between the cells, I cannot find why it's happening, any idea how to fix it? I also tested in Safari and the same happens.
Related
How do I go about making the 'description' column responsive? As you can see the bootstrap description is pushing my site. I would like the description go for a specific width, and the text to go behind the 'language' and have just one horizontal scroll bar for all of the description column.
I'm using bootstrap btw so the code doesn't contain a css but maybe it helps you anyway :)
<div className="table-responsive-lg">
<table className="table table-hover text-nowrap">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Language</th>
<th scope="col">Date Created</th>
<th scope="col">File Size (kb)</th>
<th scope="col">Open Issues</th>
</tr>
</thead>
<tbody>{data.map(item => (
<tr key={item.id}>
<td><a href={item.html_url}>{item.name}</a></td>
<td>{item.description}</td>
<td>{item.language}</td>
<td>{item.created_at.slice(0,10)}</td>
<td>{item.size}</td>
<td>{item.open_issues}</td>
</tr>
))}</tbody>
</table>
</div>
You can define a class with some CSS as below:
.fixed-width {
width: 400px;
display: block;
overflow-x: auto;
}
then add class fixed-width to all <th> and <td> tags in your "description" column.
Use this CSS.
.table {border-collapse:collapse; table-layout:fixed; width:310px;}
.table td {width:100px; /*add as per your requirements*/ word-wrap:break-word;}
Using Child Pseudo Or Unique Id OR Class.
Set as per screen required. Using #media.
I modified the previous answer a bit and add the .fixed-width class only on the column containing the description
.fixed-width {
max-width: 400px;
display: block;
overflow-x: scroll;
}
<div className="table-responsive-lg">
<table className="table table-hover text-nowrap">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Language</th>
<th scope="col">Date Created</th>
<th scope="col">File Size (kb)</th>
<th scope="col">Open Issues</th>
</tr>
</thead>
<tbody>
<tr key="1">
<td>Google</td>
<td class="fixed-width">some looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong description here</td>
<td>English</td>
<td>19/01/2021</td>
<td>38</td>
<td>5</td>
</tr>
</tbody>
</table>
</div>
You can define your css Like this:
tbody tr td:nth-child(2) {
width: 245px;
overflow-x: scroll;
max-width: 245px;
}
The text font is really weird compared to the default one. It's bigger than the light font should be.
I already tried to change Font weight etc.
<table>
<tr>
<th style="border-right: none; width: 130px;">
<div></div>
</th>
<th style="width: 40%;">
<div></div>
</th>
<th style="width: 25%;">
<div>Threads</div>
</th>
<th style="border-right: none; width: 25%;">
<div>Author</div>
</th>
</tr>
</table>
Current: http://prntscr.com/om9wwa
In the table cell: the font is bigger than the light one when you ignore that the one on the upper side is bigger.
both fonts are "fontLight" (font face)
Thanks for any help.
Try this
th tag has the default css font-weight: bold; To make th normal, you should add css font weight: normal;
check out the code snippet
th {
font-weight: normal;
}
<table>
<tr>
<th style="border-right: none; width: 130px;"><div></div></th>
<th style="width: 40%;"><div></div></th>
<th style="width: 25%;"><div>Threads</div></th>
<th style="border-right: none; width: 25%;"><div>Author</div>
</th>
</tr>
</table>
I have my table inside which i have header with two rows to display two headers as shown in image.
Right now as per my css code i am adding scroll to the table body,hence tbody is get scrolled but the main header (having class="table-main-heading") doesn't remain sticky, so what should i do keep that main header sticky even when i scroll ? (check below image-main header gets hide on scroll down)
Following are my html and css file
table.html
<div class="tableFixHead tbody-scroll">
<table class="table text-center">
<thead class="top-head">
<tr class="table-main-heading">
<th scope="col" colspan="2" class="border-right-b">User</th>
<th scope="col" colspan="3" class="border-right-b">Usage</th>
<th scope="col" colspan="6" class="border-right-b">Brain Data</th>
<th scope="col" colspan="2">Notes</th>
</tr>
<tr class="sub-heading-table text-left">
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Compliance</th>
<th scope="col">Total Days</th>
<th scope="col">Days Used</th>
<th scope="col">Sessions/Day</th>
<th scope="col">Ideal</th>
<th scope="col">Start BFV</th>
<th scope="col">Current BFV</th>
<th scope="col">Min</th>
<th scope="col">Max</th>
<th scope="col">Avg</th>
<th scope="col" width="250px">Notes</th>
<!-- <th scope="col">Comments</th> -->
</tr>
</thead>
<tbody class="text-left table-body" *ngIf="view==='Organization'">
<tr *ngFor="let user of users" (click)="onUserSelect(user)" class="user-tbl-row">
<th scope="row">{{user?.userId}}</th>
<td class="border-right-b">{{user?.userName ? user?.userName : '-'}}</td>
<td>{{user?.compliance ? user?.compliance :0}}</td>
<td>{{user?.totalDays ? user?.totalDays : 0}}</td>
<td> </td>
<td class="border-right-b">{{user?.sessionPerDay ? user?.sessionPerDay : 0}}</td>
<td>{{user?.ideal ? user?.ideal : 0 }}</td>
<td>{{user?.beforeStartValue ? user?.beforeStartValue : 0}}</td>
<td>{{user?.afterValue ? user?.afterValue : 0}}</td>
<td>{{user?.min}}</td>
<td>{{user?.max ? user?.max : 0}}</td>
<td class="border-right-b">{{user?.avg | number:'2.1-2'}}</td>
<!-- <td class="border-right-b">{{user?.notes ? user?.notes : '-'}} </td> -->
<td class="border-right-b">
<span>{{user?.notes | ellipses :
(user.isViewMore ?
ellipsesLength
: user?.notes?.length)}}</span>
<a href="javascript:;" *ngIf="ellipsesLength < user?.notes?.length && user?.isViewMore"
(click)="viewMore($event,user)" class="cc-pro-reviews-read-full-btn"> ...show more</a>
<a href="javascript:;" *ngIf="ellipsesLength < user?.notes?.length && !user?.isViewMore"
(click)="viewMore($event,user)" class="cc-pro-reviews-read-full-btn less"> show less</a>
</td>
<!-- <td>{{user?.comments ? user?.comments : '-'}}
</td> -->
</tr>
<tr *ngIf="users.length===0">
<td class="text-center" colspan="13">No Data Available</td>
</tr>
</tbody>
</table>
</div>
table.css code
.tableFixHead {
overflow-y: auto;
max-height: 511px;
}
.tableFixHead th {
position: sticky;
top: 0;
height: 42px;
}
.tableFixHead thead th {
z-index: 9999;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 8px 16px;
}
.dashboard-sidebar .sidebar-select>div:last-child::-webkit-scrollbar,
.tbody-scroll::-webkit-scrollbar {
width: 6px;
background-color: #F5F5F5;
}
.dashboard-sidebar .sidebar-select>div:last-child::-webkit-scrollbar-thumb,
.tbody-scroll::-webkit-scrollbar-thumb {
background-color: #4B6D79;
border-radius: 10px;
}
.tbody-scroll {
position: relative;
max-height: 397px;
overflow-y: scroll;
bottom: 17px;
}
Your code is working but the first row just remains sticky under the second row as the value for all th (both rows is): top:0.
You need to give diferent values for each header row like this:
.tableFixHead .table-main-heading th {
position: sticky;
top: 0;
height: 42px;
}
.tableFixHead .sub-heading-table th {
position: sticky;
top: 56px;
height: 42px;
}
beign 56px the height for the first row.
I have a table with this
<table class="table table-striped table-bordered table-hover ">
<thead>
<tr>
<th>
Network Name
</th>
<th>
Abbreviated
</th>
<th>
Description
</th>
<th>
Has Channel
</th>
<th>
IsActive
</th>
<th>Action</th>
</tr>
</thead>
</table>
The output I am getting is like this
I want each of them to be alligned left.
How to do it?
In your browser, right-click one of the table header texts (i.e. “Network name“), click "Inspect element". In the newly opened Developer Tools, click the “Styles“ window.
In the "Styles" tab you can find all rules that are applied to the selected element. One of these rules will contain said text-align: right;. That's the rule that you want to overwrite, i.e. by being more specific than the mentioned rule.
Example
you have a general rule for the table header as in your mentioned case.
table {
width: 300px;
border: 1px solid black;
}
table tr th {
text-align: right;
}
<table>
<tr>
<th>Row header</th>
</tr>
<tr>
<td>Row data</td>
<tr>
</table>
Being more specific can be achieved by using an ID or class, I'll use a class in my example:
table {
width: 300px;
border: 1px solid black;
}
/* existing rule just for illustration */
table tr th {
text-align: right;
}
/* more specific than above rule */
table.left-header tr th {
text-align: left;
}
<table class="left-header">
<tr>
<th>Row header</th>
</tr>
<tr>
<td>Row data</td>
<tr>
</table>
Lets assume your code is working and your bootstrap css is working.. then it should be in one line aligned left but in your case if not Bootstrap has a class that could do it : class="text-left"
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<table class="table table-striped table-bordered table-hover pull-left">
<thead>
<tr>
<th class="text-left">
Network Name
</th>
<th class="text-left">
Abbreviated
</th>
<th class="text-right">
Description
</th>
<th class="text-left">
Has Channel
</th>
<th class="text-left">
IsActive
</th>
<th class="text-left">Action</th>
</tr>
</thead>
</table>
i would not prefer adding the class to each th but its a solution since you dont really provide code to work with.
Description is aligned right just to give you an idea of whats happening. just by adding classes using bootstrap.
text-align: left;
This property is used for aligning text left. Kindly inspect and find the class which has text-align: right; and change it.
You can add a class to th element then style the class:
<th class="align-to-left">
.align-to-left{
text-align:left;
}
This question already has answers here:
Using calc() with tables
(2 answers)
Closed 6 years ago.
I created two tables, and I want to set the width of the right 3 columns depending on the size of the first one. I tried calc((100% - 200px)/3) but it doesn't work in all browsers: Firefox 40 fails, IE11 fails, and Chrome 44 seems to do it right. How can I do it so that calc() is understood in all browsers? Or should I just forget it?
I created a much simpler version that fails just as well.
<table class="tableauTable">
<thead>
<tr class="tableauRow first">
<th colspan="3" rowspan="2" class="tableauCell first"><span class="xspTextComputedField">Objet - Acteurs</span>
</th>
<th class="tableauCell header col3"><span class="xspTextComputedField">Julien GARDIN</span>
</th>
<th class="tableauCell header col3"><span class="xspTextComputedField">Justine VINCLAIR</span>
</th>
<th class="tableauCell header col3"><span class="xspTextComputedField">Marcel COMMAS</span>
</th>
</tr>
</thead>
<tfoot>
<tr class="tableauRow first">
<th colspan="3" header="" class="tableauCell first"></th>
<th class="tableauCell header col3"><span class="xspTextComputedField">Julien GARDIN</span>
</th>
<th class="tableauCell header col3"><span class="xspTextComputedField">Justine VINCLAIR</span>
</th>
<th class="tableauCell header col3"><span class="xspTextComputedField">Marcel COMMAS</span>
</th>
</tr>
</tfoot>
</table>
The same, with calc():
<table class="tableauTable">
<thead>
<tr class="tableauRow first">
<th colspan="3" rowspan="2" class="tableauCell first"><span class="xspTextComputedField">Objet - Acteurs</span>
</th>
<th class="tableauCell header col3x"><span class="xspTextComputedField">Julien GARDIN</span>
</th>
<th class="tableauCell header col3x"><span class="xspTextComputedField">Justine VINCLAIR</span>
</th>
<th class="tableauCell header col3x"><span class="xspTextComputedField">Marcel COMMAS</span>
</th>
</tr>
</thead>
<tfoot>
<tr class="tableauRow first">
<th colspan="3" header="" class="tableauCell first"></th>
<th class="tableauCell header col3x"><span class="xspTextComputedField">Julien GARDIN</span>
</th>
<th class="tableauCell header col3x"><span class="xspTextComputedField">Justine VINCLAIR</span>
</th>
<th class="tableauCell header col3x"><span class="xspTextComputedField">Marcel COMMAS</span>
</th>
</tr>
</tfoot>
The CSS:
.tableauTable {
width:100%;
border-spacing: 1px;
}
.tableauRow.first .tableauCell {
background: #d2d2d2 none repeat scroll 0 0 !important;
text-align: center;
}
.tableauCell.first {
width: 150px;
}
.tableauCell.col3 {
width: 30%;
}
.tableauCell.col3x {
width: calc(30%);
}
.tableauCell.first {
background: #d2d2d2 none repeat scroll 0 0 !important;
text-align: center;
}
.tableauCell {
background: #eee none repeat scroll 0 0;
border: 2px solid white;
color: black;
}
See http://jsfiddle.net/sjefb/19vrf52o/
why are you trying to calc a single value? calc(30%);
calc is very picky about syntax, particularly the gaps between resource values. You need to add spaces :
width: calc((100% - 200px) / 3);
^^^^ ^^^^^
Edit: This seems not to be the issue, instead approach that the width value is being applied to the cell (because firebug shows it is), but is different depending on cell contents, so this shows that the width value is being over-ridden, so try setting some other values:
in the table and the cell CSS definitions set:
box-sizing: border-box;
margin:0;
I solved my problem, using table-layout: fixed and, in order to fix column sizes, I used colgroup and col tags. Now calc() seems to behave, that is to say: the leftmost column has a fixed width and all other columns are equally sized.
Thanks all, for thinking with me!