首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角6定义全局scss航向样式-引导

角6定义全局scss航向样式-引导
EN

Stack Overflow用户
提问于 2018-10-20 15:27:01
回答 1查看 1.1K关注 0票数 1

我试图覆盖和定义我的角6应用程序的全局标题样式。如果我在styles.scss文件中这样做,它就能工作!

代码语言:javascript
复制
$h1-font-size: 50px;

但是,当我尝试根据屏幕大小(媒体查询)定义$h1字体大小时,它没有显示正确的字体大小,我有类似于这个ATM的东西:

//屏幕大小断点

代码语言:javascript
复制
$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px
);

// media queries xs, md and lg
@media only screen and (min-width: map-get($grid-breakpoints, xs)) {
    $h1-font-size: 12px;
}

@media only screen and (min-width: map-get($grid-breakpoints, md)) {
    $h1-font-size: 18px;
}

@media only screen and (min-width: map-get($grid-breakpoints, lg)) {
    $h1-font-size: 50px;
}

angular.json:

代码语言:javascript
复制
  "styles": [
              "node_modules/bootstrap/dist/css/bootstrap-reboot.css",
              "node_modules/bootstrap/dist/css/bootstrap-grid.css",
              "src/styles.scss",
              ...
            ],

引导-SCSS.Variables.scss文件:scss文件

代码语言:javascript
复制
$h1-font-size:                $font-size-base * 2.5 !default;
$h2-font-size:                $font-size-base * 2 !default;
$h3-font-size:                $font-size-base * 1.75 !default;
$h4-font-size:                $font-size-base * 1.5 !default;
$h5-font-size:                $font-size-base * 1.25 !default;
$h6-font-size:                $font-size-base !default;

styles.scss文件:

代码语言:javascript
复制
/* You can add global styles to this file, and also import other style files */

@import '~bootstrap/scss/bootstrap-reboot';
@import '~bootstrap/scss/bootstrap-grid';
// Required
@import "~node_modules/bootstrap/scss/bootstrap";

/* Set global default font family */
$font-family-base: 'Source Sans Pro',
sans-serif;
body,
html {
    font-family: $font-family-base
}

$grid-breakpoints: ( xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px);
@media only screen and (min-width: map-get($grid-breakpoints, xs)) {
    $h1-font-size: 12px;
}

@media only screen and (min-width: map-get($grid-breakpoints, md)) {
    $h1-font-size: 12px;
}

@media only screen and (min-width: map-get($grid-breakpoints, lg)) {
    $h1-font-size: 50px;
}

有可能吗?根据屏幕大小覆盖引导-scss标题的最佳实践是什么?

链接到stackblitz示例- https://stackblitz.com/edit/angular-scss-global-headings

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-20 17:42:20

问题是,为变量分配一个新的vlaue取决于屏幕大小,但您从不使用它。只需选择h1并设置一个值。它适用于您的stackblitz示例。

代码语言:javascript
复制
@media only screen and (min-width: map-get($grid-breakpoints, xs)) {
    $h1-font-size: 10px;
    h1 {
      font-size: $h1-font-size
      }
}

@media only screen and (min-width: map-get($grid-breakpoints, md)) {
    $h1-font-size: 30px;
    h1 {
      font-size: $h1-font-size
      }
}

@media only screen and (min-width: map-get($grid-breakpoints, lg)) {
    $h1-font-size: 50px;
    h1 {
      font-size: $h1-font-size
      } 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52907215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档