首页 > 其他 > 详细

[TypeStyle] Add responsive styles using TypeStyle Media Queries

时间:2017-06-05 18:42:27      阅读:274      评论:0      收藏:0      [点我收藏+]

Media queries are very important for designs that you want to work on both mobile and desktop browsers. TypeStyle gives media queries special attention, making it easy to write them using CSS in JS.

In this lesson we show TypeStyle‘s media function. We also demonstrate how you can add non standard media queries if you want. Finally we show how organizing media queries this way is encapsulated under CSS class names.

 

import { style, media } from typestyle;
import * as React from react;
import * as ReactDOM from react-dom;

const fontSize = (value: number | string) => {
    const valueStr = typeof value === string ?
                     value :
                     value + px;
    return {
        fontSize: valueStr
    }
};
const className = style(
    {color: red, transition: font-size 0.2s},
    media({maxWidth: 700, minWidth: 500}, fontSize(20)),
    media({minWidth: 701}, fontSize(30)),
    media({maxWidth: 499}, fontSize(15))
);

ReactDOM.render(
    <div className={className}>
        Hello Typestyle
    </div>,
    document.getElementById(root)
);

 

[TypeStyle] Add responsive styles using TypeStyle Media Queries

原文:http://www.cnblogs.com/Answer1215/p/6946460.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!