css - 根据设备屏幕更改字体颜色的 Sass 功能
问题描述
我正在寻找一种方法来创建一个 sass 函数,将我的字体颜色从白色(在桌面上)更改为黑色(在平板电脑和移动设备上)。原因是我在桌面上的视频上覆盖文本,但在移动设备上,覆盖的文本切换到视频下方的阻止文本,因此字体颜色此时需要更改为黑色。
我对 sass 比较陌生,但到目前为止,我已经将它作为一个 mixin 尝试过(这不起作用)
** 我知道这可以用 css 完成,但我希望让它更具动态性和可重用性 **
$color-media-sizes: (
"max1024": #000 or #fff,
null: #000 or #fff
);
有了这个功能
@function color($mobile-color, $desktop-color){
@return ($mobile-color $desktop-color)
}
解决方案
我不认为你真的需要为此使用 SASS,CSS 可以解决问题。只需根据您的设备屏幕放置媒体查询和颜色(来源:https ://gist.github.com/gokulkrishh/242e68d1ee94ad05f488 )
阅读此文档,它将帮助您理解媒体查询:https ://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
/* CSS */
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px
*/
@media (min-width: 1025px) and (max-width: 1280px) {
/* CSS */
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px
*/
@media (min-width: 768px) and (max-width: 1024px) {
/* CSS */
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
/* CSS */
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
@media (min-width: 481px) and (max-width: 767px) {
/* CSS */
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 479px
*/
@media (min-width: 320px) and (max-width: 480px) {
/* CSS */
}
SASS 中的 Mixin 就像创建一个组件的“模板”。例如:一个按钮
@mixin button($text, $background) {
background: $background;
border-radius: 10px;
color: $text;
padding: 0 15px;
text-decoration: none;
text-transform: uppercase;
}
// Then you can call it this way :
.success-button {
@include button("#FFF", "#0F0");
}
.error-button {
@include button("#FFF", "#F00");
}
希望我能帮上忙
推荐阅读
- ruby-on-rails - 如何解决: SQLException: no such table: locations: ALTER TABLE "locations" ADD "user_id" integer
- python - 为什么调用 .clear() 后的 dict 大小为 72 字节,而实例化时为 240 字节?
- model - Prestashop 模型不从 lang 表中加载数据
- reactjs - FileManager 对话框内容区域中的 CKEditor 文本字段不起作用(替代文本、宽度、高度......)
- flutter - 如何在不重启应用的情况下更改 Flutter 应用语言?
- python - 使用交叉验证拟合 randomForest 模型
- javascript - 从 JSON 回显接收数据的 Javascript 错误
- apl - 从 GNU APL 会话加载 APL 脚本
- installation - 安装程序 PHOEBE 2
- javascript - 怎么把id放在url中间