【问题标题】:Wordpress Redux Framework Media QueriesWordpress Redux 框架媒体查询
【发布时间】:2017-09-15 10:00:39
【问题描述】:

我一直在四处寻找,但仍然没有找到任何答案。我的问题是:

  1. 如何在媒体查询中输出动态 CSS?在我看来,wordpress redux-framework 的 CSS 输出是全局编写的(编译器/内联样式),并且会影响所有屏幕尺寸。

  2. 以媒体查询方式在redux-framework中输出动态CSS的更简单方法是什么?

【问题讨论】:

    标签: php css wordpress redux-framework


    【解决方案1】:

    尚未对此进行测试,但应该给您一个粗略的开始。 您可以使用多个字段(例如 480、768、991 等),只需使用 wp_add_inline_style 输出代码。

    function my_custom_css(){
    
     //get the theme option
     $option = get_option('opt_name');
    
     // get the fields holding the custom css for each media query
     $media_991_css = $option['css991'];
     $media_768_css = $option['css768'];
     $media_480_css = $option['css480'];
    
     // store the values in a variable
     $output  = "@media screen and (max-width: 991px){" . $media_991_css . "}";
     $output .= "@media screen and (max-width: 768px){" . $media_768_css . "}";
     $output .= "@media screen and (max-width: 480px){" . $media_480_css . "}";
    
     // output it with wp_add_inline_style
     if(!empty($output)){
            wp_add_inline_style('style',$output);
        }
    }
    
    add_action('wp_enqueue_scripts','my_custom_css');
    

    您当然需要确保正确转义,但这应该可以满足您的需求。

    【讨论】:

      猜你喜欢
      • 2020-07-09
      • 2018-06-29
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      相关资源
      最近更新 更多