Angular Material Design Layout custom sizes

百般思念 提交于 2019-12-13 07:41:14

问题


How to add custom flex attributes for different sizes of the screen? Referring to the spec here : https://material.angularjs.org/latest/#/layout/options

For example, the flex attribute flex-gt-lg Sets flex on devices greater than 1200px wide. I want to add one more attribute say something like flex-gt-lgx which sets flex on devices greater than 1600px wide, for which angular material does not provide support. How will do something like this?


回答1:


codeMan,

You will have to change the CSS in a way or another.

Complex way

Go to their css resources an alter it to fit your needs

Easier way

Create your own CSS changes overwriting theirs with !important

@media screen and (min-width:1200px) {     
.yourclass { 
      width:100% !important; 
      background:#ccc !important; 
      float:none !important;     }  
}

Cheers!




回答2:


I wrote a media query as follows :

@media only screen and (min-width: 1601px) {
    [flex-gt-lgx="25"] {
        -webkit-flex: 0 0 25%;
        -ms-flex: 0 0 25%;
        flex: 0 0 25%;
    }
}

and used the following span tag

<span flex-md="10" flex-sm="5" flex-lg="15" flex-gt-lg="20" flex-gt-lgx="25" ></span>

and it worked as expected!!

Note: Downside of doing this is that flex-gt-lgx should be always set to 25 value.




回答3:


Based on @codeMan answer with media query ...

@media only screen and (min-width: 1601px) {
    [flex-gt-lgx="25"] {
        -webkit-flex: 0 0 25%;
        -ms-flex: 0 0 25%;
        flex: 0 0 25%;
    }
}

Custom Angular directive

You could write a custom directive for flex-gt-lgx that would generate the CSS to be apply in the style attribute with the desired flex value passed from the directive parameter.

That way you wouldn't be limited to the hardcoded CSS values.

Mimic the Angular Material CSS

You could make the same thing as Angular Material and create all the CSS for possible flex values as stated in their documentation and than use the flex-gt-lgx attribute on the desired HTML tag just like any other flex directive.

Currently, the flex directive value is restricted to multiples of five, 33 or 66.

For example: flex="5", flex="20", flex="33", flex="50", flex="66", flex="75", ... flex="100".

https://material.angularjs.org/latest/layout/children



来源:https://stackoverflow.com/questions/32591898/angular-material-design-layout-custom-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!