Semantic-Org / Semantic-UI

Semantic is a UI component framework based around useful principles from natural language.
http://www.semantic-ui.com
MIT License
51.07k stars 4.95k forks source link

[UI] Add Responsive Helper Classes #1114

Open ronnross opened 9 years ago

ronnross commented 9 years ago

I'm using semantic beta

I have an element That I only want to show in mobile view only. For example,

<div class="ui secondary button mobile only"> <i class="save icon"></i> Save </div>

This element shows in computer, tablet, and mobile views.

mzbyszynski commented 9 years ago

Hi @ronnross,

As far as I know the "mobile only" classes currently only work inside a ui grid in conjunction with the row and column tags. See an example of how it works here:

http://beta.semantic-ui.com/collections/grid.html#responsive-to-device

ronnross commented 9 years ago

@mzbyszynski it looks like you are correct. Is there an equivalent to bootstraps hidden-XX class in semantic? I'm looking to hide elements at a more granular level than grid/row conjunction.

mzbyszynski commented 9 years ago

Right now I don't think there is, but it sounds like a good idea to me :+1:

See #1066, that includes some workarounds suggested by @CharlesOkwuagwu as well.

jlukic commented 9 years ago

@ronnross It seems a lot of people want to use this, but I've been a bit stubborn about "free floating" ui helper classes in Semantic UI since the spirit of the project is to define variations in the context of each element.

ronnross commented 9 years ago

@jlukic I respect the decision to not have "free floating" ui helper classes. What are your thoughts about having mobile, tablet, computer only classes under each collection? For example, the menu collection would allow for "mobile only" classes. This would keep them within the context of the parent collection e.g., form, grid, menu. Am I way off base?

tmikaeld commented 9 years ago

I think it makes sense to support it in the menu at least.

Right now i'm looking for a solution to showing a large button for search on mobile while on the desktop showing the whole search bar and afaik i can't do that without manually adding a mediaquery breakpoint.

PLPeeters commented 9 years ago

+1 for at least supporting it in the menu.

Ehesp commented 9 years ago

Would be a good feature, hiding things like icons or text as a page gets smaller is handy.

pateketrueke commented 9 years ago

So, when this will be ready to use?

jlukic commented 9 years ago

Haven't started any development, probably a while.

ch3m1c commented 9 years ago

+1 for hidden-xx

watzon commented 9 years ago

Have we gotten anywhere on this? Need someone to develop it? I love Semantic UI, but this seems to be the one huge thing missing. I will implement it if it's not at the top of anyone else's priority list.

arvi commented 9 years ago

It would be great if Semantic UI has an equivalent for Zurb Foundation's Media Queries :) http://foundation.zurb.com/docs/media-queries.html

jlukic commented 9 years ago

Named breakpoint variables are built into Semantic UI, you can use them in your own custom less.

listepo commented 8 years ago

+1

lancetw commented 8 years ago

+1

mamluka commented 8 years ago

+1

rachellji commented 8 years ago

+1 ~~~ would be great if can conveniently hide any image, label or other elements .

prijindal commented 8 years ago

+1 On this, would be really helpful

KonsoltCorp commented 8 years ago

+10000 on this!

FernandoMueller commented 8 years ago

+1

hnordt commented 8 years ago

+1

prijindal commented 8 years ago

+1 would be a great addition

insign commented 8 years ago

+1

koddr commented 8 years ago

+1

btbjosh commented 8 years ago

+1

purplecones commented 8 years ago

+1

jurikern commented 8 years ago

+1

YamiOdymel commented 8 years ago

+1

Jur4iks commented 8 years ago

I have made my own super simple responsive css(only css) Taking the semantic default breakpoint

/* Mobile */

@media only screen and (max-width: 767px) {
    .mobile-hide{
        display: none !important;
    }
}

/* Tablet */

@media only screen and (min-width: 768px) and (max-width: 991px) {
    .tablet-hide{
        display: none !important;
    }
}

/* Small Monitor */

@media only screen and (min-width: 992px) and (max-width: 1199px) {
    .small-hide{
        display: none !important;
    }
}

/* Large Monitor */

@media only screen and (min-width: 1200px) {
    .large-hide{
        display: none !important;
    }
}

Whn you youse one of this class element is hiden on specific screen size. Simple, but works for me :)

purplecones commented 8 years ago

Hey, this works pretty well! Thanks for sharing

kappaknight commented 8 years ago

+99999 on this.

schabluk commented 8 years ago

+1

Panman82 commented 8 years ago

+1 as well. Taking @JOJOManLV's lead, I've changed the class names to be more "Semantic UI'ish" and expanded the "* only" classes to work for everything.

@media only screen and (max-width: 767px) {
    .mobile.hidden,
    .tablet.only,
    .small.monitor.only,
    .large.monitor.only {
        display: none !important;
    }
}
@media only screen and (min-width: 768px) and (max-width: 991px) {
    .mobile.only,
    .tablet.hidden,
    .small.monitor.only,
    .large.monitor.only {
        display: none !important;
    }
}
@media only screen and (min-width: 992px) and (max-width: 1199px) {
    .mobile.only,
    .tablet.only,
    .small.monitor.hidden,
    .large.monitor.only {
        display: none !important;
    }
}
@media only screen and (min-width: 1200px) {
    .mobile.only,
    .tablet.only,
    .small.monitor.only,
    .large.monitor.hidden {
        display: none !important;
    }
}

Note: I didn't add .ui to the .only classes so that it would work on "non-UI" elements, such as .menu > .item.mobile.only

manish2535 commented 8 years ago

+1

suhaboncukcu commented 8 years ago

+1 I've used @Panman8201 's classes for a project. Works superb.

niksmac commented 8 years ago

+1 and thanks @Panman8201

sgarbesi commented 8 years ago

+1

gszathmari commented 8 years ago

+0.5 * 2

fumbleforce commented 8 years ago

Thanks @Panman8201!

Bitz commented 8 years ago

+1

nordbit commented 8 years ago

+√ 1

sgeraldes commented 8 years ago

+1!! thank you @Panman8201 and @Jur4iks for the snippet! Works great.

sgeraldes commented 8 years ago

Updating the snippet to match the latest version. It adds a widescreen monitor, and changes small monitor to computer.

/* Mobile */
@media only screen and (max-width: 767px) {
    .mobile.hidden,
    .tablet.only,
    .computer.only,
    .large.monitor.only,
    .widescreen.monitor.only {
        display: none !important;
    }
}

/* Tablet / iPad Portrait */
@media only screen and (min-width: 768px) and (max-width: 991px) {
    .mobile.only,
    .tablet.hidden,
    .computer.only,
    .large.monitor.only,
    .widescreen.monitor.only {
        display: none !important;
    }
}

/* Computer / Desktop / iPad Landscape */
@media only screen and (min-width: 992px) and (max-width: 1199px) {
    .mobile.only,
    .tablet.only,
    .computer.hidden,
    .large.monitor.only,
    .widescreen.monitor.only {
        display: none !important;
    }
}

/* Large Monitor */
@media only screen and (min-width: 1200px) and (max-width: 1919px) {
    .mobile.only,
    .tablet.only,
    .computer.only,
    .large.monitor.hidden,
    .widescreen.monitor.only {
        display: none !important;
    }
}

/* Widescreen Monitor */
@media only screen and (min-width: 1920px) {
    .mobile.only,
    .tablet.only,
    .computer.only,
    .large.monitor.only,
    .widescreen.monitor.hidden  {
        display: none !important;
    }
}
elldritch commented 8 years ago

:+1: These classes would be an incredibly pragmatic addition.

suhaboncukcu commented 8 years ago

Why hasn't this been implemented yet? I've never seen an issue with that much thumbs up :)

sgeraldes commented 8 years ago

Here is a new version, this time it adds a new class:

screen or lower hidden

Screen can be: mobile, tablet, computer, large monitor, widescreen monitor

e.g.: "tablet or lower hidden" will hide in everything but computer, large monitor, or widescreen monitor. You can get the idea. I also changed the css selectors so you can do things like: "mobile only tablet only" to show the element only on those two screens. Keep in mind: "mobile tablet only" is not equal to "mobile only tablet only". Also, due to how semantic is coded, the choosen words in "large monitor" interferes with some elements which has sizes. e.g.: <div class="ui large monitor only label"> will give you a "large label". The oposite is not true, where <div class="ui widescreen monitor only large label"> will give you a large label only visible in a widescreen monitor.

jsFiddle: https://jsfiddle.net/8LkLoxcx/

The workaround is to enclose the label in a div like so: <div class="large monitor only"><div class="ui label"></div></div>

CSS code follows:

/* Mobile */

@media only screen and (max-width: 767px) {
  [class*="mobile hidden"],
  [class*="tablet only"]:not(.mobile),
  [class*="computer only"]:not(.mobile),
  [class*="large monitor only"]:not(.mobile),
  [class*="widescreen monitor only"]:not(.mobile),
  [class*="or lower hidden"] {
    display: none !important;
  }
}

/* Tablet / iPad Portrait */

@media only screen and (min-width: 768px) and (max-width: 991px) {
  [class*="mobile only"]:not(.tablet),
  [class*="tablet hidden"],
  [class*="computer only"]:not(.tablet),
  [class*="large monitor only"]:not(.tablet),
  [class*="widescreen monitor only"]:not(.tablet),
  [class*="or lower hidden"]:not(.mobile) {
    display: none !important;
  }
}

/* Computer / Desktop / iPad Landscape */

@media only screen and (min-width: 992px) and (max-width: 1199px) {
  [class*="mobile only"]:not(.computer),
  [class*="tablet only"]:not(.computer),
  [class*="computer hidden"],
  [class*="large monitor only"]:not(.computer),
  [class*="widescreen monitor only"]:not(.computer),
  [class*="or lower hidden"]:not(.tablet):not(.mobile) {
    display: none !important;
  }
}

/* Large Monitor */

@media only screen and (min-width: 1200px) and (max-width: 1919px) {
  [class*="mobile only"]:not([class*="large monitor"]),
  [class*="tablet only"]:not([class*="large monitor"]),
  [class*="computer only"]:not([class*="large monitor"]),
  [class*="large monitor hidden"],
  [class*="widescreen monitor only"]:not([class*="large monitor"]),
  [class*="or lower hidden"]:not(.computer):not(.tablet):not(.mobile) {
    display: none !important;
  }
}

/* Widescreen Monitor */

@media only screen and (min-width: 1920px) {
  [class*="mobile only"]:not([class*="widescreen monitor"]),
  [class*="tablet only"]:not([class*="widescreen monitor"]),
  [class*="computer only"]:not([class*="widescreen monitor"]),
  [class*="large monitor only"]:not([class*="widescreen monitor"]),
  [class*="widescreen monitor hidden"],
  [class*="widescreen monitor or lower hidden"] {
    display: none !important;
  }
}

`
jokeronaldo commented 8 years ago

@suhaboncukcu look at milestone, @jlukic marked into 2.x Changes milestone, we are working on it. There's a lot of requests and changes, be patient :smile:

jokeronaldo commented 8 years ago

@scumie Thanks for the contribution :+1:

aliok commented 8 years ago

here is the @scumie 's snippet with class names consistent with Semantic UI. (ie. large monitor --> large screen, widescreen monitor --> widescreen)

// Semantic UI has these classes, however they're only applicable to
// grids, containers, rows and columns.
// plus, there isn't any `mobile hidden`, `X hidden` class.
// this snippet is using the same class names and same approach
// plus a bit more but to all elements.
//
// see https://github.com/Semantic-Org/Semantic-UI/issues/1114

/* Mobile */
@media only screen and (max-width: 767px) {
  [class*="mobile hidden"],
  [class*="tablet only"]:not(.mobile),
  [class*="computer only"]:not(.mobile),
  [class*="large screen only"]:not(.mobile),
  [class*="widescreen only"]:not(.mobile),
  [class*="or lower hidden"] {
    display: none !important;
  }
}

/* Tablet / iPad Portrait */
@media only screen and (min-width: 768px) and (max-width: 991px) {
  [class*="mobile only"]:not(.tablet),
  [class*="tablet hidden"],
  [class*="computer only"]:not(.tablet),
  [class*="large screen only"]:not(.tablet),
  [class*="widescreen only"]:not(.tablet),
  [class*="or lower hidden"]:not(.mobile) {
    display: none !important;
  }
}

/* Computer / Desktop / iPad Landscape */
@media only screen and (min-width: 992px) and (max-width: 1199px) {
  [class*="mobile only"]:not(.computer),
  [class*="tablet only"]:not(.computer),
  [class*="computer hidden"],
  [class*="large screen only"]:not(.computer),
  [class*="widescreen only"]:not(.computer),
  [class*="or lower hidden"]:not(.tablet):not(.mobile) {
    display: none !important;
  }
}

/* Large Monitor */
@media only screen and (min-width: 1200px) and (max-width: 1919px) {
  [class*="mobile only"]:not([class*="large screen"]),
  [class*="tablet only"]:not([class*="large screen"]),
  [class*="computer only"]:not([class*="large screen"]),
  [class*="large screen hidden"],
  [class*="widescreen only"]:not([class*="large screen"]),
  [class*="or lower hidden"]:not(.computer):not(.tablet):not(.mobile) {
    display: none !important;
  }
}

/* Widescreen Monitor */
@media only screen and (min-width: 1920px) {
  [class*="mobile only"]:not([class*="widescreen"]),
  [class*="tablet only"]:not([class*="widescreen"]),
  [class*="computer only"]:not([class*="widescreen"]),
  [class*="large screen only"]:not([class*="widescreen"]),
  [class*="widescreen hidden"],
  [class*="widescreen or lower hidden"] {
    display: none !important;
  }
}