一次更改多种颜色 [英] Changing multiple colours at once

查看:92
本文介绍了一次更改多种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我会尝试尽可能地解释这一点,但我学会了实际编写代码而实际上没有阅读那么多教程,所以请原谅任何使用错误的技术术语。



我已经在tumblr上编写了一段时间的主题,它们有一个功能,允许你在多个div上改变背景颜色(或字体,或字体大小,或填充,任何东西)在控制面板中选择一个新值。我可以找到更改侧边栏颜色的相关代码,例如:



< meta name =color :边栏content =/> 





头部,后来



< pre lang =text> #side {
top:60px;剩余
:60px;
头寸:固定; background:{color:Sidebar};
宽度:255px;边框:1px纯白色; box-shadow:2px 2px;
}





在用户可以看到的控制面板中(缺少更好的描述)有一个选项更改侧边栏的颜色。我不打算制作一个花哨的界面,让人们从下拉菜单或任何东西中选择一种颜色。只是一种在代码的一个部分中定义值并使代码中的其他div引用/使用该值的方法。



但是......我不知道如何在tumblr上编写主题代码。这甚至可能吗?如果可能的话,我想避免使用javascript。



非常感谢无论谁回答这个问题,如果这是一个明显和/或厚重的问题,我真诚地道歉。



我尝试了什么:



我真的不知道从哪里开始。我尝试使用< meta />以与tumblr上的主题代码相同的方式标记和引用它,但我认为这不会起作用,因为实际值没有在任何地方定义,并且,它没有做任何事情。

解决方案

我建​​议使用基本的javascript,因为CSS不允许变量。也许使用像Sass或LESS这样的框架,但这需要学习框架,这对大多数人来说可能很难。



例如,

  var  color1 =  #990dfa; 
var someDiv = Document.getElementById(' yourDivId');
someDiv.style.backgroundColor = color1;
var nextDiv = Document.getElementById(' aWeirdDiv')。style.color = color1;

请注意,这不仅适用于div - 它适用于所有html5元素。



来源:使用JavaScript获取DIV的内容 - Stack Overflow [ ^ ], Javascript更改Div样式 - 堆栈溢出 [ ^ ]



好日 - 成员13120882


Hello, I'll try to explain this as best as I can, but I learnt to code mostly practically without actually reading that many tutorials so please forgive any use of the wrong technical jargon.

I've been coding themes on tumblr for a while and they have a feature that allows you to change the background colour (or font, or font size, or padding, anything really) on multiple divs by selecting a new value in a 'control panel'. The relevant code I could find for change the colour of a sidebar, for example, is:

<meta name="color:Sidebar" content=""/>



in the head, and later

#side {
    top: 60px;
    left: 60px;
    position: fixed;  background: {color:Sidebar};
    width: 255px; border: 1px solid white; box-shadow: 2px 2px;  
}



In the 'control panel' that users can see (for lack of a better description) there is an option to change the colour of the sidebar. I'm not looking to make a fancy interface that lets people select a colour from a drop down menu or anything. Just a way to define a value in one section of the code and have that value referenced/used by other divs in the code.

However... I have no idea how to do this off of coding a theme on tumblr. Is this even possible to do? I'd like to avoid using javascript, if possible.

Many thanks to whoever answers this, and I sincerely apologise if this is an obvious and/or thick question to ask.

What I have tried:

I really don't know where to start here. I tried just using the <meta /> tag and referencing it in the same way a theme code on tumblr would, but I didn't think that would work since the actual value wasn't defined anywhere, and, surprise, it did nothing.

解决方案

I'd recommend using basic javascript as CSS doesn't allow for variables. Maybe use a framework like Sass or LESS but that requires learning the frameworks, which can be difficult for most people.

For example,

var color1 = "#990dfa";
var someDiv = Document.getElementById('yourDivId');
someDiv.style.backgroundColor = color1;
var nextDiv = Document.getElementById('aWeirdDiv').style.color = color1;

Note that this isn't just for divs - it's for all html5 elements.

Sources: Get content of a DIV using JavaScript - Stack Overflow[^], Javascript change Div style - Stack Overflow[^]

Good Day - Member 13120882


这篇关于一次更改多种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆