Coder Social home page Coder Social logo

sass-mediaqueries's Introduction

sass-mediaqueries

It's a collection of useful Media Queries mixins for Sass (including iOS devices, TVs and more). Fully customizable and very easy to use.

How to install:

Using bower:

bower install sass-mediaqueries

Using npm:

npm install sass-mediaqueries

Using curl:

curl -O https://raw.githubusercontent.com/rafalbromirski/sass-mediaqueries/master/_media-queries.scss

Then, at the top of your sass/scss file (ie. application.scss) add:

@import "media-queries";

Doc:

Generator (v1.6.0):

mq($args...)

Generator allows you to create custom media-queries mixins by passing keywords arguments based on w3c media features specification (make sure you always provide key and value).

It's also a syntactic sugar for the standard media queries syntax (CSS).

Examples:

@include mq($max-width: 1000px) {
  ...
}

// will generate

@media only screen and (max-width: 1000px) {
  ...
}

Creating new mixins (like max-screen) is even easier:

@mixin max-screen($max)
  @include mq($max-width: $max) {
    @content;
  }
}

// usage

@include max-screen(1000px) {
  ...
}

// will generate

@media only screen and (max-width: 1000px) {
  ...
}

Or if you want to change $media-type and other properies:

@mixin custom-device($min, $max)
  @include mq($media-type: 'all', $min-width: $min, $max-width: $max) {
    @content;
  }
}

// usage

@include custom-device(500px, 1000px) {
  ...
}

// will generate

@media all and (min-width: 500px) and (max-width: 1000px) {
  ...
}

How cool is that?


Other Mixins:

@  screen(min-width, max-width, orientation)
@  min-screen(width)
@  max-screen(width)
--
@  screen-height(min-height, max-height, orientation)
@  min-screen-height(height)
@  max-screen-height(height)
--
@  hdpi(ratio)
--
@  landscape
@  portrait
--
@  iphone4(orientation)
@  iphone5(orientation)
@  iphone6(orientation)
@  iphone6-plus(orientation)
--
@  ipad(orientation)
@  ipad-retina(orientation)
--
@  hdtv(standard)

- screen($min-width, $max-width, $orientation: false)

It targets group of devices or just one with particular screen width and orientation (optional).

# Example:
@include screen(320px, 640px) { ... }
@include screen(768px, 1024px, landscape) { ... }

It will be compiled to:

@media screen and (min-width: 768px) and (max-width: 1280px) { ... }
@media screen and (min-width: 320px) and (max-width: 640px) and (orientation: landscape) { ... }

- min-screen($width)

It's a shortcut for @media screen and (min-width ... )

# Example:
@include min-screen(768px) { ... }
@include min-screen(1024px) { ... }

It will be compiled to:

@media screen and (min-width: 768px) { ... }
@media screen and (min-width: 1024px) { ... }

- max-screen($width)

It's a shortcut for @media screen and (max-width ... )

# Example:
@include max-screen(1024px) { ... }
@include max-screen(768px) { ... }

It will be compiled to:

@media screen and (max-width: 1024px) { ... }
@media screen and (max-width: 768px) { ... }

- screen-height($min-height, $max-height, $orientation: false)

It targets group of devices or just one with particular screen height and orientation (optional).

# Example:
@include screen-height(640px, 768px) { ... }
@include screen-height(640px, 768px, landscape) { ... }

It will be compiled to:

@media screen and (min-height: 768px) and (max-height: 1280px) { ... }
@media screen and (min-height: 768px) and (max-height: 1280px) and (orientation: landscape) { ... }

- min-screen-height($width)

It's a shortcut for @media screen and (min-height ... )

# Example:
@include min-screen-height(768px) { ... }
@include min-screen-height(1024px) { ... }

It will be compiled to:

@media screen and (min-height: 768px) { ... }
@media screen and (min-height: 1024px) { ... }

- max-screen-height($width)

It's a shortcut for @media screen and (max-height ... )

# Example:
@include max-screen-height(1024px) { ... }
@include max-screen-height(768px) { ... }

It will be compiled to:

@media screen and (max-height: 1024px) { ... }
@media screen and (max-height: 768px) { ... }

- hdpi($ratio: 1.3)

It targets devices with hdpi display.

# Example:
.brand {
	background-image: url(logo.png);

	@include hdpi {
		background-image: url(logo_2x.png);
	}
}

- landscape() & portrait()

Both mixins target different screen orientations.

# Example:
@include landscape { ... }
@include portrait { ... }

It will be compiled to:

@media screen and (orientation: landscape) { ... }
@media screen and (orientation: portrait) { ... }

$orientation: all | portrait | landscape

- iphone4($orientation: all)

It targets only iPhone 4 + orientation

- iphone5($orientation: all)

It targets only iPhone 5 + orientation

- iphone6($orientation: all)

It targets only iPhone 6 + orientation

- iphone6-plus($orientation: all)

It targets only iPhone 6 Plus + orientation

- ipad($orientation: all)

It targets all iPads + orientation

- ipad-retina($orientation: all)

It targets only iPads with retina display + orientation

# Example:
@include ipad { ... }                 // all iPads
@include ipad-retina { ... }          // only iPad with retina

@include iphone5 { ... }              // only iPhone 5
@include iphone4 { ... }              // only iPhone 4/4S
# Example:
// common part for iPhone 5 - landscape & portrait
@include iphone5 { ... }

@include iphone5(landscape) { ... }
@include iphone5(portrait) { ... }

$standard: '720p' | '1080' | '2K' | '4K'

- hdtv($standard: '1080')

It targets TVs with particular standard like 1080 or 4K

# Example:
.title {
	font-size: 5vm;

	@include hdtv {
		font-size: 10vm;
	}

	@include hdtv('4K') {
		font-size: 15vm;
	}
}

Credits:

Feel free to check my website or follow me on twitter.


License:

The MIT license

Copyright © 2015 Rafal Bromirski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sass-mediaqueries's People

Contributors

iamsebastian avatar mkempe avatar rafalbromirski avatar sapegin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sass-mediaqueries's Issues

version 2.0 is available

Hello Everyone!

Today I've pushed new code! I've changed many things and added new mixins for iPhone5 and totally changed the approach.

Tomorrow I will write short note about it.

Cheers,
Rafal Bromirski

Why sass

Why you call it sass-mediaqueries? But actually it is SCSS not SASS

No detection when using Ripple ( Chrome extension )

When I use:

@include iphone4(portrait) {
 .item-body {
    background: red;
  }
}

Together with Ripple & device called "iPhone 4/4S", the CSS doesn't change.
While, when querying:

@include min-screen(320px) {
  .item-body {
    background: red;
  }
}

It works, but I wanted to use iPhone rather than screen sizes ...
Are you familiar with this issue ? or is it just me ?

Just noting that I'm using Ionic framework as well ( incase it matters )

Min, max range contained in a single variable?

Would it be possible to add support for a single variable containing a comma-separated range, something like:

$small_display: 768px, 960px;

So that it could be used as follows:

@include screen($small_display) { }

(Forgive me if this is already possible and I just don't understand the syntax.)

Media types

Hey,

Good work here - thanks

Any thoughts on extending these scripts for media types ala http://www.w3.org/TR/CSS2/media.html or have I missed something?

// all
// braille
// embossed
// handheld
// print
// projection
// screen
// speech
// tty
// tv

Kind thanks,

Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi)

I get the following console warning:

Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi)

Is it better to use dppx instead of dpi?

Underscore the file so it doesn't get compiled?

Shouldn't this file start with an underscore so it doesn't get compiled?

For example: _media-queries.scss

That way folks can curl -O https://raw.github.com/paranoida/sass-mediaqueries/master/media-queries.scss to the location the need to store it in their project?

Add support for iPhone 6 & 6 plus

Have you planned to add support for iPhone 6 & 6 Plus?

I would ideally like to target iPhones in general or combine devices.

Any thoughts appreciated.

Adding the generic WVGA, FWVGA, HVGA

Will it be possible to add the Android's templates of: WVGA, FWVGA, HVGA etc .. ?
And their orientation just like your did for the iOS ?

I find it very difficult to implement them using your lib, because I need both width & height to nail a device.
Otherwise, the width of 480px will match X in portrait, but won't match 480px in landscape for template Y.

Thanks.

remove units

No units means that you will be able to use both em or px in one file. It's impossible right now.

Nexus targets as well

I would say 'Android' but that's way to broad. Getting Nexus 4/7/10 (and perhaps even Galaxy Nexus) would be awesome.

And even a generic 'phone' (targeting iPhones & Nexus 4 & Galaxy) and 'tablet' mixins which are aliases for the respective sizes would be interesting.

However, I expect that there is some overlap with the resolutions of the various iPhones & Nexus devices.

v1.6.0 is not compatible with libsass

Looks like v1.6.0 is not compatible with libsass.
You can try here http://sassmeister.com/ - open control panel and you can easly jump between versions.

Console error:

assets/styles/common/_mixins.scss
  45:15  mixin mq has no parameter named $min-width
assets/styles/common/_mixins.scss
  45:15  mixin mq has no parameter named $min-width

npm

Could you please publish it to npm too?

I could submit a pull request with the package.json file.

HDTV (beta)

I know the HDTV Detection is still in beta, but I would like to assist if I can.. I would like to hear your input or others who use HDMI screens.. So maybe we can get this going right..

I would like to hear some feedback & input.. this would make an awesome detection utility..
The reason for such in-depth of resolution.. is because I am thinking about "Media-Queries" that could serve images based on exact resolution @2x, @3x, @4x.. and more.. not just images, but content too.


Here are some of my findings...

  • Windows 7 x64 (Awesome) laptop w/ HDMI Out
  • HP W2338H 23" Monitor (not TV) (& excellent picture by the way..)
  • I use an HDMI Cable to connect them (Type 'A' Full size HDMI cable)

** This is what I see on your Demo page :
720


** This is what my Windows 7 settings are :
resolution


** This is just to show different options :
resolution_2


** This is interesting, so even tho I am using -- 1920 x 1080
..the browser window is less.. [1920 x 955]... Maybe you have to adjust for the little bit less, to correctly guess-timate it? a 125px's less...
[ source: https://useragent.openadmintools.com ]

useragent openadmintools com


I dont know what the pixels would be for the 720p (maybe 595px) if you subtract 125px to give room for browser.

Maybe you could add-on to it, add 480p and others.. what about "i" & "p".. ex. 480i or 480p


i found this list on Wikipedia -- [ source: https://en.wikipedia.org/wiki/Display_resolution ]

hd


So in the end maybe it could detect:

Standard-definition television (SDTV) :
    480i
    576i

Enhanced-definition television (EDTV) :
    480p (720 × 480)
    576p (720 × 576)

High-definition television (HDTV) :
    720p (1,280 × 720)
    1080i (1,920 × 1,080 split into two interlaced fields of 540 lines)
    1080p (1,920 × 1,080 progressive scan)

Ultra-high-definition television (UHDTV) :
    2160p (3,840 × 2,160 - aka "4K UHD")
    4320p (7,680 × 4,320 - aka "8K FUHD")
    8640p (15,360 × 8,640 - aka "16K QUHD")

I also came across this too,
[source: http://www.javascriptkit.com/howto/newtech3.shtml ]

jskit


@Paranoida, Nice work.. 👍

maybe the second keyword only should remove

@mixin hdpi($ratio: 1.3) {
  @media only screen and (-webkit-min-device-pixel-ratio: $ratio),
  only screen and (min-resolution: #{round($ratio*96)}dpi) {
    @content;
  }
}

i have a demo in jsbin 0.5px demo, and find the second keyword only must be removed.

@mixin hdpi($ratio: 1.3) {
  @media only screen and (-webkit-min-device-pixel-ratio: $ratio),
  screen and (min-resolution: #{round($ratio*96)}dpi) {
    @content;
  }
}

1.6 does not seem to compile with libsass

It would be nice to have a warning about which SASS version is needed for compilation.
I use gulp-sass, which uses node-sass, which uses libsass:

Libsass is written in C, and although it's quite fast, it's slow to implement new functionalities, like it's ruby-based counterpart.

I got the following error, after upgrading to 1.6 from 1.4, and I think it's caused by libsass' implementation:

{ [Error: expected '{' in media query]
  message: 'expected \'{\' in media query',
  fileName: './front_src/bower_components/sass-mediaqueries/_media-queries.scss',
  lineNumber: 29,
  showStack: false,
  showProperties: true,
  plugin: 'gulp-sass',
  __safety: { toString: [Function] } }

syntax error in readme.md

There is a missing opening bracket on the first line:

@mixin max-screen($max)
  @include mq($max-width: $max) {
    @content;
  }
}

Add iphone7

Of course iphone7 and iphone SE have the same screen size as iphone 6 and iphone 5, but maybe it can be more intuitive to have these mixins?

Does not work on landscape

Hiya,
I've noticed that the code does not work correctly on landscape for the mac devices but portrait?

On the other hand, it would be good if you can declare the variables for the different devices you have created so I can use them around my sass.

Cheers,
jaume

Support grunt-bower-install

I got following error and get some stackoverflow question (http://stackoverflow.com/questions/21840776/popcorn-was-not-injected-in-your-file). please look for it and fix for this problem.

Running "serve" task

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "bowerInstall:app" (bowerInstall) task

sass-mediaqueries was not injected in your file.
Please go take a look in "app/bower_components/sass-mediaqueries" for the file you need, then manually include it in your file.

Running "bowerInstall:sass" (bowerInstall) task

sass-mediaqueries was not injected in your file.
Please go take a look in "app/bower_components/sass-mediaqueries" for the file you need, then manually include it in your file.

@mixin screen with orientation

Maybe It's a important thing to implement on the code. A optional orientation param on the screen mixin. I have used this one in my personal website yesterday.

Ex:

@mixin screen($resMin, $resMax, $orientation : default)
{

  @if $orientation == default
  {
    @media screen and (min-width: $resMin) and (max-width: $resMax)
    {
      @content;
    }
  }
  @else
  {
    @media screen and (min-width: $resMin) and (max-width: $resMax) and (orientation:#{$orientation})
    {
      @content;
    }
  }

}

Error when importing

I get this when importing via "@import "media-queries";
Syntax error: Invalid CSS after "...d ( min-width: ": expected expression (e.g. 1px, bold), was "$res-min ) and ..."
on line 57 of /Users/xx/Desktop/xxx/Web/CSS/media-queries.scss
from line 3 of /Users/xx/Desktop/xxx/CSS/main.scss

any ideas?

Support for em/rem

Any chance you could support for EM-based Media Queries?

Maybe a boolean and a default value on the root element could do the trick.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.