English 中文(简体)
动态分配 CSS 类到其它类
原标题:Dynamically assign CSS class to another class
  • 时间:2012-05-25 17:20:46
  •  标签:
  • php
  • css

能否将一个 CSS 类的属性指定给另一个类? 如果不能用 CSS 来完成, 我可以使用服务器端脚本来传递变量 。

例如,如果我有从. my class1到.my class20的班级清单, 我知道对于用户7, 我需要用 MyClass7 取代.my Default, 我该怎么做?

最佳回答

您希望某类中的所有财产都由 CSS 中的另一类继承。

联合来文不能将这两个类别都积极应用于一个对象。

这不能直接与安保部直接合作,而联署材料的做法将花费相当长的时间,供你们执行。

最好的选择是让您查看 "less cs

它做你想做的事,无论是服务器方面还是客户方面。

问题回答

在 j 查询中, 您可以使用这个代码 :

$( .myDefault ).addClass( myClass7 );
$( .myClass7 ).removeClass( myDefault );

这不是直接的答案, 但如果您想要混合设置, 您可以使用多个类 :

bigFont{
  font-size:150%;
}
errorBox{
  border:4px dashed red;
}
typMessage{
  padding:2px;
  margin:1px;
  overflow-y:auto;
}


<div class="typMessage">Hello World</div>

中添加“ erorBox” 和/或“ bigFont” 类, 以“ 合并” CSS 属性。

这里简单的换班方式无需jQuery: http://jsfidle.net/imsky/mrKHB/

HTML :

<div id="test" class="big one sans phone">Hello world and </div>

CSS :

.one {background:blue;color:#fff}
.two {background:yellow;color:#000}
.sans {font-family:sans-serif}
.big {font-size:24px}
.phone:after {content:"phone!"}

JavaScript :

document.getElementById("test").onclick = (function(){
this.className = this.className.replace(/one/,"two");
});

You can use PHP to handle this for you. Just replace e.g.

<div class= myDefault ></div>

// you should have that info stored somewhere anyway :)
$userClass =  myClass7 ;

// now just echo out the right class for the user
<div class="<?php echo $userClass ?>"></div>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签