Responsive table in css (properties in the rows instead of columns) - css

I have a table, which I am trying to format properly for the responsive design. I have figured out how to do that in the case when the different items of the table are listed in the first column and their different properties are in the following columns.
#media screen and (max-width: 480px) {
table {
width: 100%;
}
tbody td {
display: block;
text-align: center;
}
tbody td:before {
content: attr(data-th);
display: block;
text-align: center;
}
}
But I didn't figure out how to do it if I have a table, where different properties of the items are in different rows. For example, when there is a comparison of two products:
product a product b
100 200
5 years 7 years
and I would like it to be on a small screen like this:
product a
100
5 years
product b
200
7 years
What I have now is:
product a
product b
100
200
5 years
7 years
Any hints are very appreciated!

Yes, You can use CSS tricks to solve this issue.
You just need to set CSS something like this:
#media screen and (max-width: 480px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr { border: 1px solid #ccc; }
td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}
td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
/*
Label the data
*/
td:nth-of-type(1):before { content: "product a"; }
td:nth-of-type(2):before { content: "product b"; }
}

Related

How to override all classes within in a media query?

I am building a custom .css, but I do not know, how to override a bunch of classes within a media query with "nothing". Means, I do not want this in my output, but also I don't want to delete this from the css as it needs to stay original. I also don't want to copy the whole bunch of classes and write "none" or "unset" behind every single attribute. Is there any solution for this. Thanks a lot.
/*original.css*/
#media only screen and (max-device-width: 720px) {
ol.accord li {
width: 100%;
}
.content {
height: 149px;
width: 50%;
}
ol.accord li h3 {
height: 30px;
width: 100%;
margin: 0;
border-right: none;
border-bottom: 1px solid #fff;
padding: 7px 10px;
}
}
/*custom.css*/
/*here should be nothing like it wouldn´t even exist in the original*/
You can write as many classes in the media query within the parenthesis.
Here is an example for this
Just define the class above and change as per your requirement as per screen size.
.custom_class1 {
height : 1px;
}
#media only screen and (max-device-width: 720px) {
ol.accord li {
width: 100%;
}
.content {
height: 149px;
width: 50%;
}
ol.accord li h3 {
height: 30px;
width: 100%;
margin: 0;
border-right: none;
border-bottom: 1px solid #fff;
padding: 7px 10px;
}
.custom_class1 {
height:70px;
}
.custom_class2 {
height:70px;
}
}

How to contain feed items from overflowing into next column

I'm using WP RSS Aggregator, and I've styled the feed into containers, along with creating a 3 column layout. Limiting the feeds to 18 per page, I'm experiencing overflow issues. Setting the CSS to overflow:hidden !important; has not resolved the issue. Being the length of each feed item varies, I'm hoping for a solution that will carry through each feed category. Below is a link to the feed page, followed by the CSS I've implemented for feed imports into their respective pages. Thank you in advance for your help.
enter image description here
div.wprss-et-social-buttons {
display: none;
}
.thumbnail-excerpt img{
float: none !important;
}
.thumbnail-excerpt {
text-align: center;
}
li.feed-item{
overflow: hidden !important;
border: solid #000 2px;
border-radius: 5px;
padding: 10px;
width: 250px;
background: #eee;
}
.thumbnail-excerpt {
overflow: auto !important;
}
wprss-feed-excerpt{
font-size: 16px;
text-align: center;
}
li.feed-item > a{
font-size: 23px;
text-align: center;
}
ul.rss-aggregator{
column-count: 3 !important;
list-style-type: none;
}
#media only screen and (max-width: 980px) {
ul.rss-aggregator {
column-count: 2 !important;
}
}
#media only screen and (max-width: 479px) {
ul.rss-aggregator {
column-count: 1 !important;
}
}

Fullcalendar Scheduler Timeline Print Issue

Scheduler Fullcalendar timeline view doesn't REALLY support printing at all but unfortunately my client needs it. The issue is that the latter half of the calendar is getting cut off in print.
The potential solutions: Using zoom: 0.8 works amazing in Chrome and all the days of the week appear. However that doesn't do anything for Firefox. transform: scale(0.8) doesn't seem to have the same effect as part of calendar is still cut off, though it's all scaled down. If I emulate css in Chrome it shows up even with the transform scale toggled on, however does not show up in actual print.
Please excuse the potato styling of the calendar when it prints. I'm more concerned with friday the latter half of the calendar being cut off. In chrome toggle my comment for zoom and switch to scale to see the difference.
Here is codepen link https://codepen.io/bedelman851/pen/wXeZEO
I've been away from this project for a while and I don't think I solved this satisfactorily but I did solve it to be "good enough" for my situation. I looked into lots of options and spent way too much time on it.
The css I ended up going with is below. I can't vouch for how it looks or what you need, but if it's helpful then I am glad!
//CALENDAR CSS
.calendar-functions,
.calendar-functions div:last-child,
.calendar-functions a,
.calendar-view h1,
.fc-right,
.fc-right button,
.fc-license-message,
.print-button,
.print-button-week {
display: none;
}
.month-view .calendar-functions div,
.week-view .calendar-functions div {
display: none;
}
.fc-event:after {
content: attr(data-coll) !important;
}
.fc-body {
height: 400px !important;
}
.calendar-widget-week,
.fc-timeline {
width: 100%;
}
body {
width: 100%;
}
.fc-view-container {
// transform: scale(0.8);
zoom: 0.8;
}
.fc-timeline {
th {
height: 30px;
}
.fc-scroller-canvas {
min-width: 100% !important;
width: 100% !important;
}
}
.calendar-day tr td:first-child {
a[href]:after {
display: none;
}
}
.fc {
max-width: 100% !important;
th {
height: 30px;
}
}
.fc-event {
background: transparent !important;
color: #000 !important;
page-break-inside: avoid;
}
.fc-event .fc-resizer {
display: none;
}
.fc th,
.fc td,
.fc hr,
.fc thead,
.fc tbody,
.fc-row {
border-color: #ccc !important;
}
.fc-bgevent-skeleton,
.fc-highlight-skeleton,
.fc-helper-skeleton,
.fc-business-container,
.fc-highlight-container,
.fc-helper-container {
display: none;
}
.fc-ltr .fc-timeline-event {
margin-right: 5px;
}
.calendar-widget-week .fc-timeline-event {
padding-bottom: 97px;
}
/* don't force a min-height on rows (for DayGrid) */
.fc tbody .fc-row {
height: auto !important;
/* undo height that JS set in distributeHeight */
min-height: 0 !important;
/* undo the min-height from each view's specific stylesheet */ }
.fc tbody .fc-row .fc-content-skeleton {
position: static;
/* undo .fc-rigid */
padding-bottom: 0 !important;
/* use a more border-friendly method for this... */ }
.fc tbody .fc-row .fc-content-skeleton tbody tr:last-child td {
/* only works in newer browsers */
padding-bottom: 1em;
/* ...gives space within the skeleton. also ensures min height in a way */ }
.fc tbody .fc-row .fc-content-skeleton table {
/* provides a min-height for the row, but only effective for IE, which exaggerates this value,
making it look more like 3em. for other browers, it will already be this tall */
height: 1em; }
//List views
.pagination-right,
.pagination-left *,
.pagination-right *,
.pagination-left {
display: none;
}
.fc-day-grid-event,
.fc-timeline-event {
&:before {
content: attr(data-id);
}
&:after {
content: "";
}
&:before,
&:after {
display: inline-block !important;
}
}
.fc-scroller {
overflow: visible !important;
.fc-scroller-canvas {
min-width: none !important;
}
}
#page :left {
margin-left: 0;
}
#page :right {
margin-left: 0;
}
/* for vertical events */
.fc-event-bg {
display: none !important;
}
.fc-event .ui-resizable-handle {
display: none !important;
}
.print-window__exit {
display: none;
}
#calendar-week {
display: none;
}
.dt-print-view {
#calendar-week {
display: block;
}
}
.print-table,
.print-title {
display: block !important;
}
This worked from me on Chrome and Edge (Firefox is still working too)
#media print {
body {
zoom: 0.8;
}
}

Issues with Locked Header CSS

I have some tables in my HelpDesk software that I wanted to lock the headers. I found this:
Scrollable table with fixed header in bootstrap
I have edited the CSS and HTML and it's working where the header does lock in to place. However, I have 2 issues that I can't figure out. First, the header row will not span the complete width of the table. Second, the final column which is a note column, I want to make larger than the rest of the columns. Here is my CSS:
.formatTable tr:nth-child(odd) {
background-color:lightgray
}
.hoverTable tr:hover {
background-color: #ffff99;
cursor:pointer;
}
/*.hoverTable tr:first-child:hover {
background-color: #0c268d;
cursor:default;
}*/
.formatTable tr:first-child {
background-color: #0c268d;
font-weight: normal;
color:white;
}
th {
white-space: nowrap;
}
#media screen and (min-width:361px)
{
table.TicketLists {
width: 100%;
}
.TicketLists thead, tbody, tr, td, th {
display: block;
}
.TicketLists tr:after {
content: ' ';
display: block;
clear: both;
}
.TicketLists tbody {
height: 600px;
overflow-y: auto;
}
.TicketLists tbody td {
width: 12.2%;
float: left;
}
.TicketLists th {
float: left;
}
.notesColumn {
width: 22%;
}
}
Here is a jsfiddle for the code: Header Locking not working fully
and here is a picture of what it currently looks like:
As you can see in the CSS, I have tried to create one column which is wider (called .notesColumn) and it has not done anything.
have a look at:
https://jsfiddle.net/t4zwsrdw/10/
your the th needs a width, because it's display block and floating.
.TicketLists th {
float: left;
width: 12.2%;
text-align:left;
}
UPDATE
.notesColumn {
width: 49.8% !important;
}
Make your .noteColumn wider and add the class to the last th:
<th class="notesColumn">
Opening Note
</th>
https://jsfiddle.net/t4zwsrdw/12/
this version has the header above the whole table.

primefaces datatable reflow in desktop browser

primefaces 5.2
i have a primefaces datatable, the table is very long which is why i want to show it in column stacked mode, i tried using reflow attribute of the datatable.
now if i use the developers mode in chrome and switch to mobile view when i reduce the size of the screen it does in fact behave responsive and goes into stacked column mode, now i want to show that type of table in normal desktop view as well. i thought simple things like just reducing the size of the table would help but no matter how small i reduce the size it just crams the table into that tiny space instead of making it responsive.
am i missing something about how to make something behave responsive on a desktop browser.
<p:dataTable id="tb1" var="ths" value="#{thb.sitetracking}"
rowIndexVar="rowindex" reflow="true"
>
in normal size the table looks like this
in chrome developers mode mobile view
if i resize the table to get the same effect, instead of a responsive size change this happens
<p:dataTable id="tb1" var="ths" value="#{thb.sitetracking}"
rowIndexVar="rowindex" reflow="true" style="width:200px"
>
if i resize my browser with same table above and make it smaller, it works
maybe i am just not understanding what responsive actually means, is it not possible to trigger a responsive behaviour by changing the size of the table, it seems to only work when the size of the browser changes
My main objective of doing this doesn't really have much to do with making the table responsive the real thing that i want to achieve is getting the table into column stacked mode and from what i have seen this is the only way PF does it
any help would be appreciated
Reflow mode works with CSS media query. When your window width is less than 35em (see also the primefaces.css snippet below) then reflow mode is applied.
Thus, applying a width: 200px; to your dataTable isn't taken into account and will not result in a stacked datatable.
To achieve your goal (applying stack mode when your window width is larger than 35em) you could create (I can't figure out a cleaner solution) your own css class which got rid of the media query. Something like table-reflow-desktop:
.table-reflow-desktop .ui-datatable-data td .ui-column-title {
display: none;
}
.table-reflow-desktop thead th,
.table-reflow-desktop tfoot td {
display: none;
}
.table-reflow-desktop .ui-datatable-data td {
text-align: left;
display: block;
border: 0px none;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
float: left;
clear: left;
}
.table-reflow-desktop .ui-datatable-data.ui-widget-content {
border: 0px none;
}
.table-reflow-desktop .ui-datatable-data tr.ui-widget-content {
border-left: 0px none;
border-right: 0px none;
}
.table-reflow-desktop .ui-datatable-data td .ui-column-title {
padding: .4em;
min-width: 30%;
display: inline-block;
margin: -.4em 1em -.4em -.4em;
}
And don't forget to apply this class to your p:dataTable:
<p:dataTable id="tb1" var="ths" value="#{thb.sitetracking}" rowIndexVar="rowindex" styleClass="table-reflow-desktop">
For reference, here is the original PrimeFaces 5.2 css part which is responsible of the reflow mode:
/** Reflow **/
.ui-datatable-reflow .ui-datatable-data td .ui-column-title {
display: none;
}
#media ( max-width: 35em) {
.ui-datatable-reflow thead th,
.ui-datatable-reflow tfoot td {
display: none;
}
.ui-datatable-reflow .ui-datatable-data td {
text-align: left;
display: block;
border: 0px none;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
float: left;
clear: left;
}
.ui-datatable-reflow .ui-datatable-data.ui-widget-content {
border: 0px none;
}
.ui-datatable-reflow .ui-datatable-data tr.ui-widget-content {
border-left: 0px none;
border-right: 0px none;
}
.ui-datatable-reflow .ui-datatable-data td .ui-column-title {
padding: .4em;
min-width: 30%;
display: inline-block;
margin: -.4em 1em -.4em -.4em;
}
}

Resources