Visibility utilities on no-block element (responsive.less)
Hi,
Visibility utilities on responsive.less are good, but seems to work fine only on "display: block" element.
In fact, these classes works fine when applied on already "display: block" element.
Example, apply '.hidden-phone' on a.btn element : the button is hided on phones resolution, but it is converted to "display: block" element on larger resolution.
Another example, on table, i want to hide some columns for phones devices resolution, so i put .hidden-phone on th and tr . This seems don't work because th and tr are not "display: block" by default, they are converted into block by visibility utilities. Table columns are hided on phone resolution, but table show ugly on larger resolution.
The same issue happen on all no-block elements.
An early resolution would be to replace "display: block" with "display:" to not override the default "display" value of the element :
// Visibility utilities
// For desktops
.visible-phone { display: none; }
.visible-tablet { display: none; }
.visible-desktop { display: ; }
.hidden-phone { display: ; }
.hidden-tablet { display: ; }
.hidden-desktop { display: none; }
But maybe that does not conform to standard, it is inelegant and it does not solve the problem completely.
Another early focus would be to create class for each type of element, for example ".hidden-inline-phone" with "display: inline" value by default, but again this does not seem to be a good solution.
+1
Here is what I did to make this work for any type of element (block, inline, inline-block, etc. ...), so for span, buttons, table columns, etc.... + added "!important" to force hiding, in some cases necessary :
Some selectors can be simply removed, those with "display: block" are not necessary, to prevent the override of default 'display' value, and assuming that elements are visible by default.
Maybe I should do a pull-request?
// Visibility utilities
// For desktops
.visible-phone { display: none; }
.visible-tablet { display: none; }
.visible-desktop { }
.hidden-phone { }
.hidden-tablet { }
.hidden-desktop { display: none; }
// Phones only
@media (max-width: 767px) {
// Show
.visible-phone { }
// Hide
.hidden-phone { display: none !important; }
// Hide everything else
.hidden-desktop { }
.visible-desktop { display: none !important; }
}
// Tablets & small desktops only
@media (min-width: 768px) and (max-width: 979px) {
// Show
.visible-tablet { }
// Hide
.hidden-tablet { display: none !important; }
// Hide everything else
.hidden-desktop { }
.visible-desktop { display: none !important; }
}
+1
+1
+1 cc @fat
I have tested the fix by @netatoo and it works!
This is great, should definitely be incorporated!
Consider using display: inherit; to unhide at smaller view-ports. This allows elements to return to their natural display type (i.e. div to block, span to inline, etc.)
I tested your suggestion and it seems to work in most cases, excepting one:
table
tr
td
td
td.hidden-phone
/tr
/table
The td.hidden-phone is hidden on phones devices, but on larger resolution, it's converted to "display: table-row" when it should be "display: table-cell", because of this "inherit" that retrieves the value of the parent element, the "tr".
+1 for @netatoo solution : empty CSS when visible and "!important"
Resolved in 2.0.3-wip with a huge update on the utilities classes: https://github.com/twitter/bootstrap/commit/a7b8e52f8e08cc821d7324153885c085fad25c1a
Thanks! It works fine!