Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Issues
  • #9209
Closed
Open
Issue created Aug 07, 2013 by Administrator@rootContributor

Responsive visibility utility styles can't be used as LESS mixins

Created by: zacwasielewski

While answering this StackOverflow question, I found that the responsive utility classes (.visible-sm, .hidden-sm, etc.) in responsive-utilities.less only work if they're embedded directly in your HTML.

So for example, this works:

// HTML:
<div id="box" class="hidden-lg"></div>

But trying to apply the .hidden-lg class as a LESS mixin does not work:

// HTML:
<div id="box"></div>

// LESS:
#box {
    .hidden-lg;
}

This isn't exactly a bug, but it's nice to have the option to divorce your codebase from Bootstrap-specific styles, as described in this article.

The problem is that the .visible-* and .hidden-* classes don't contain any media queries; instead, they're wrapped inside media queries, so they can't know about or respond to the screen size. Here's a snippet of those class definitions from responsive-utilities.less:

// Tablets & small desktops only
@media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) {
  .visible-sm {
    .responsive-invisibility();
  }
  .visible-md {
    .responsive-visibility();
  }
  .visible-lg {
    .responsive-invisibility();
  }
  ...

If a fix for this "broken" behavior is desirable, it would be as simple as reformatting the above styles as such:

.visible-sm {
  .responsive-visibility();
  @media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) { .responsive-invisibility(); }
  @media (min-width: @screen-desktop) { .responsive-invisibility(); }
}
.visible-md {
  .responsive-invisibility();
  @media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) { .responsive-visibility(); }
  @media (min-width: @screen-desktop) { .responsive-invisibility(); }
}
.visible-lg {
  .responsive-invisibility();
  @media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) { .responsive-invisibility(); }
  @media (min-width: @screen-desktop) { .responsive-visibility(); }
}
.hidden-sm {
  .responsive-invisibility();
  @media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) { .responsive-visibility(); }
  @media (min-width: @screen-desktop) { .responsive-visibility(); }
}
.hidden-md {
  .responsive-visibility();
  @media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) { .responsive-invisibility(); }
  @media (min-width: @screen-desktop) { .responsive-visibility(); }
}
.hidden-lg {
  .responsive-visibility();
  @media (min-width: @screen-tablet) and (max-width: @screen-tablet-max) { .responsive-visibility(); }
  @media (min-width: @screen-desktop) { .responsive-invisibility(); }
}

I've created some test jsFiddles:

  • Current Bootstrap ("broken")
  • Modified Bootstrap (fixed)

(And here's the diff of my branch of the Bootstrap rep.)

Any thoughts on this?

Assignee
Assign to
Time tracking