bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Visibility utilities on no-block element (responsive.less)

Open netatoo opened this issue 14 years ago • 12 comments

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.

netatoo avatar Mar 13 '12 18:03 netatoo

+1

francocatena avatar Mar 15 '12 14:03 francocatena

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; }
}

netatoo avatar Mar 15 '12 21:03 netatoo

+1

toin0u avatar Mar 18 '12 17:03 toin0u

+1

fgruner avatar Mar 20 '12 15:03 fgruner

+1 cc @fat

julionc avatar Mar 21 '12 01:03 julionc

I have tested the fix by @netatoo and it works!

sorcix avatar Mar 21 '12 13:03 sorcix

This is great, should definitely be incorporated!

ehedaya avatar Mar 21 '12 14:03 ehedaya

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.)

jeremyworboys avatar Mar 23 '12 06:03 jeremyworboys

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".

netatoo avatar Mar 23 '12 16:03 netatoo

+1 for @netatoo solution : empty CSS when visible and "!important"

pauldijou avatar Mar 24 '12 10:03 pauldijou

Resolved in 2.0.3-wip with a huge update on the utilities classes: https://github.com/twitter/bootstrap/commit/a7b8e52f8e08cc821d7324153885c085fad25c1a

mdo avatar Mar 25 '12 08:03 mdo

Thanks! It works fine!

netatoo avatar Mar 25 '12 16:03 netatoo