Jekyll liquid variables as inline CSS values

被刻印的时光 ゝ 提交于 2019-12-06 08:25:33

问题


Is passing liquid variables as inline styles commonly frowned upon? Here is an example of my markup:

 <div class="span-8-12">
    <h6> {{page.role}}</h6>
    <h1 style="color:{{ page.accentColor }};"> {{page.title}} </h1>
 </div> 
 <article class="intro">
    <p style="color:{{ page.txtColor }};"> {{ page.summary }} </p>
 </article>

I am setting h1 and p colors using the liquid variables in my posts. I know I could pass the variable directly to a CSS file, but then'd i'd have to write even more markup and CSS. Is this method valid or is there a better method on systematically changing values of color based off page variables?


回答1:


Better would be to set a class, rather than directly setting the styles inline.

<div class=" {{ page.typeOfClass  }}">
    <div class="span-8-12">
        <h6> {{page.role}}</h6>
        <h1 > {{page.title}} </h1>
     </div> 
     <article class="intro">
        <p > {{ page.summary }} </p>
     </article>
</div>

Then in your whatever.css set the styles for the different classes you want:

.someClass h1{
    color:blue;
}
.someClass .intro p{
    color:red;
}

for example.



来源:https://stackoverflow.com/questions/28681926/jekyll-liquid-variables-as-inline-css-values

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