Due to comments I add that .vmiddle, .vmiddle td, .vmiddle th doesn't work in my case because I'm using bootstrap and it defines .table thead > tr > th, .table tbody > tr > th, .table tfoot > tr > th, .table thead > tr > td, .table tbody > tr > td, .table tfoot > tr > td with vertical-align: top;
which take precedence.
I want to perform this css:
.vmiddle,
table.vmiddle thead tr td,
table.vmiddle tfoot tr td,
table.vmiddle tbody tr td,
table.vmiddle thead tr th,
table.vmiddle tfoot tr th,
table.vmiddle tbody tr th,
table thead.vmiddle tr td,
table tbody.vmiddle tr td,
table tfoot.vmiddle tr td,
table thead.vmiddle tr th,
table tbody.vmiddle tr th,
table tfoot.vmiddle tr th,
table thead tr.vmiddle td,
table tbody tr.vmiddle td,
table tfoot tr.vmiddle td,
table thead tr.vmiddle th,
table tbody tr.vmiddle th,
table tfoot tr.vmiddle th,
table thead tr td.vmiddle,
table thead tr th.vmiddle,
table tbody tr td.vmiddle,
table tbody tr th.vmiddle,
table tfoot tr td.vmiddle,
table tfoot tr th.vmiddle {
vertical-align: middle;
}
somehow i get it to work with this rules :
.vmiddle {
vertical-align:middle;
& {
table& {
& thead , tfoot, tbody {
tr, {
td, th {
vertical-align: middle;
}
}
}
}
thead&, tbody&, tfoot& {
table & {
tr {
td, th {
vertical-align: middle;
}
}
}
}
tr& {
thead &, tbody &, tfoot & {
table & {
td, th {
vertical-align: middle;
}
}
}
}
td&, th& {
tr & {
thead &, tbody &, tfoot & {
table & {
vertical-align: middle;
}
}
}
}
}
}
but looks actually more complicated than the standard soluction :D
Is there any shorter way to do it and without defining vertical-align:middle 5 times ?
It looks like your not using the '&' selectors properly.
From lesscss.org:
the & combinator - it’s used when you want a nested selector to be
concatenated to its parent selector, instead of acting as a
descendant. This is especially important for pseudo-classes like
:hover and :focus.
For example:
.bordered {
&.float {
float: left;
}
.top {
margin: 5px;
}
}
Will output
.bordered.float {
float: left;
}
.bordered .top {
margin: 5px;
}
But in your case it doesn't look like you even need to use it.
Edit:
Regarding the specificity issue (mentioned in the comments below) simply add a class on the root (table) element and the specificity problem goes away. So if we call the calss .table:
LESS:
.table .vmiddle
{
vertical-align: middle;
td, th
{
vertical-align: middle;
}
}
In most cases you should be able to shorten those long css rules. In certain situations it won't work but generally you should avoid unnecessary long selectors to get better performance and readability. An example of methodically reducing the rules:
Any thead, tbody, tfoot, tr, th and td will always be in a table, you can remove the table selector part.
.vmiddle,
.vmiddle thead tr td,
.vmiddle tfoot tr td,
.vmiddle tbody tr td,
.vmiddle thead tr th,
.vmiddle tfoot tr th,
.vmiddle tbody tr th,
thead.vmiddle tr td,
tbody.vmiddle tr td,
tfoot.vmiddle tr td,
thead.vmiddle tr th,
tbody.vmiddle tr th,
tfoot.vmiddle tr th,
thead tr.vmiddle td,
tbody tr.vmiddle td,
tfoot tr.vmiddle td,
thead tr.vmiddle th,
tbody tr.vmiddle th,
tfoot tr.vmiddle th,
thead tr td.vmiddle,
thead tr th.vmiddle,
tbody tr td.vmiddle,
tbody tr th.vmiddle,
tfoot tr td.vmiddle,
tfoot tr th.vmiddle {
vertical-align: middle;
}
Any tr, th and td will always either be in a thead, tbody or tfoot, you can remove those. Many rules are now identical, remove those too.
.vmiddle,
.vmiddle tr td,
.vmiddle tr th,
tr.vmiddle td,
tr.vmiddle td,
tr.vmiddle td,
tr.vmiddle th,
tr.vmiddle th,
tr.vmiddle th,
tr td.vmiddle,
tr th.vmiddle,
tr td.vmiddle,
tr th.vmiddle,
tr td.vmiddle,
tr th.vmiddle {
vertical-align: middle;
}
Any th and td will always be a child of a tr, remove tr. Remove all duplicates again.
.vmiddle,
.vmiddle td,
.vmiddle th,
td.vmiddle,
th.vmiddle {
vertical-align: middle;
}
td.vmiddle and th.vmiddle are already covered by .vmiddle.
.vmiddle,
.vmiddle td,
.vmiddle th {
vertical-align: middle;
}
Related
I have one format for html page. But it does not apply link but apply as a text in the html table.
There was no link everything was a text.
The format is like as below;
<title>Report</title>
<style>
table
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse:collapse;
}
td
{
font-size:1em;
border:1px solid #98bf21;
padding:5px 5px 5px 5px;
}
th
{
font-size:1.1em;
text-align:center;
padding-top:5px;
padding-bottom:5px;
padding-right:7px;
padding-left:7px;
background-color:#A7C942;
color:#ffffff;
}
name tr
{
color: #060606;
background-color:#EAF2D3;
}
</style>
I am using coreUI and I have a view where i set up a datatable. I want to have the thead sticky on top but nothing I do seems to work.
The thead consists of two rows (tr). one row contains the names of the headers and the second row contains some the column filters. These come right out the box with UI.
Whatever I tried only applies to the 2nd row and not the 1st.
eg. I have tried adding the below css code but only the second line seems to be working.
thead tr:nth-child(1) th { position: sticky; top: 0; }
thead tr:nth-child(2) th { position: sticky; top: 43px; }
Any ideas why?
thead tr:nth-child(1) th { position: sticky !important; top: 0; }
thead tr:nth-child(2) th { position: sticky !important; top: 43px; }
I have a table that is spanning across multiple pages. The thead is being repeated on the second page and is overlapping the content.
I am using bootstrap and have ensured the css from other wkhtmltopdf overlap solutions are implemented in my page.
thead { display: table-header-group; }
tfoot { display: table-row-group; }
tr { page-break-inside: avoid; }
table, tr, td, th, tbody, thead, tfoot, td div {
page-break-inside: avoid !important;
}
The table was wrapped in a <div class="table-responsive">. This was causing the issue.
I added the following CSS to change how overflow-x was handled on the table-responsive div
.table-responsive { overflow-x: visible !important; }
This fixed my issue.
Keith
this worked for me. in this table:
<table class="webgrid-table">
<thead>
<tr>
//your code
</tr>
</thead>
</table>
only add these css class:
.webgrid-table thead {
display: table-header-group;
}
.webgrid-table tfoot {
display: table-row-group;
}
.webgrid-table tr {
page-break-inside: avoid;
}
Just to add to this, sometimes it's a matter of overflowing.
.table-responsive { overflow-x: visible !important; }
Solved it once, but sometimes the problem is for example the body, etc
.table-responsive, .table, body { overflow-x: visible !important; }
In my case it was the body that had a weird overflow.
Have funsies
I'm using bootstrap3 modal and trying to create a table inside a modal.
I want the tbody to have vertical scroll. I've tried adding the height and overflow-y: auto to tbody, but it won't work.
I was able to have the entire modal scrollable, but I just want only the table body to be scrollable
Can anyone please help me?
I've finally found an answer for this.
I adapted the code from here: http://jsfiddle.net/T9Bhm/7/
The CSS Solution:
table {
width: 100%;
}
thead, tbody, tr, td, th { display: block; }
tr:after {
content: ' ';
display: block;
visibility: hidden;
clear: both;
}
thead th {
height: 30px;
/*text-align: left;*/
}
tbody {
height: 120px;
overflow-y: auto;
}
thead {
/* fallback */
}
tbody td, thead th {
width: 19.2%;
float: left;
}
I am trying to change the color of rows in datatable using the below CSS.
table.dataTable tr.odd { background-color: #E2E4FF; }
table.dataTable tr.even { background-color: white; }
This change doesnt seem to affect first column in datatables, I can see the new color in other columns.
Can someone please let me know the reason for this issue?
Solved the issue by using the below css.
table.dataTable td.sorting_1{ background-color: white; border:1px lightgrey; }
table.dataTable td{ background-color: white; border:1px lightgrey;}
table.dataTable tr.odd { background-color: white; border:1px lightgrey;}
table.dataTable tr.even{ background-color: white; border:1px lightgrey; }