473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

css selector as alias of another

is it possible, create a selector as alias of another selector...
(maybe) in another stylesheet file?

ex:

html page
....
<link rel="stylesheet" type="text/css" href="style1.css" />
<link rel="stylesheet" type="text/css" href="style2.css" />
....
<span class="test1">test1</span>
<span class="test2">test2</span>
....

style1.css
....
test1{
font-size: 20px;
}
....

style2.css
....
test2{
# syntax to get style's information from another selector in another
stylesheet (ex: .test in style1.css file)
}
....

another way that I have found is this below...

..test_alias:.test_style{
}

..test_style{
color: #000000;
font-size: 40px;
font-weight: bold;
}

but it don't work... or my syntax is incorrect... you can help me?
thx

Mar 28 '07 #1
3 1905
JakDaniel <ja*********@hotmail.comwrote:
is it possible, create a selector as alias of another selector...
(maybe) in another stylesheet file?
thru Javascript YES

for example u have :

selector1 with rule1

and you want to copy rule1 into selector2
the values for selector1 {rule1} for example :

..test1 {font-size:12px;...}

and you want to copy rule1 "font-size:12px;..." into selector2 ***AS
IF*** you had a stylesheet with :

selctor2 {rule1} for example :

H5.test2 {<same rules as rule1>}

you can do that by javascript DOM mainpulation :

//initialize rule_copy, is (index of the correct sheet):
var rule_copy,is,jr;

// get ref to all the style sheets:
var csss=document.getElementByTagName('style');

//loop over the style sheets:
for(var i=0;i<csss.length;i++) {

//get all the rules for the style sheet i:
var rules=document.styleSheets[i].cssRules;

//loop over the selectors for a given style sheet:
for(var j=0;j<rules.length;j++) {

// catch selector1 (might be better using a RegExp):
if(rules[i]['selectorText'] === '.test1') {

//save the rule for that selector :
rule_copy=rules[i]['cssText'];

//save index of style sheet:
ir=i;
}
}

// now you're are ready to insert a new rule with selector2 having the
// cssText equal to the one of selector1 :
var aRule=selector2+"{"+rule_copy+"}";
document.styleSheets[ir].insertRule(aRule,document.styleSheets[ir]..leng
th);
>>NOT TESTED BUT SHOULD WORK <<<
give me a more precise example, i'll do a page to test that.
--
Une Bévue
Mar 28 '07 #2
Une Bévue said the following on 3/28/2007 1:30 PM:
JakDaniel <ja*********@hotmail.comwrote:
>is it possible, create a selector as alias of another selector...
(maybe) in another stylesheet file?
<snip>

Note the "stylesheet file"
// get ref to all the style sheets:
var csss=document.getElementByTagName('style');
That will miss external files as they are not included using a style
tag, they are included using a link tag.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 28 '07 #3
Randy Webb <Hi************@aol.comwrote:
>
Note the "stylesheet file"
// get ref to all the style sheets:
var csss=document.getElementByTagName('style');

That will miss external files as they are not included using a style
tag, they are included using a link tag.
Thanks, you are RIGHT ! ;-)

in fact I'm using "document.styleSheets" rather than
"document.getElementByTagName('style')"

I've done a test page here :

<http://www.une-bevue.fr/CSS/copy_rule.xhtml>

It's "a bit" more complicated as i wrotre before...

i wrote two cases :

- 1 - Copy rule of selector "h1.test"
where the whole properties of selector "h1.test" are copied, including
the computed ones.

- 2 - Copy rule property "font-size" of selector "p.sized"
where the only property "font-size" of selector "p.sized" is copied.

In hope my test case (tested ONLY using Firefox 2.0.0.3) is clear
enough.
--
Une Bévue
Mar 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
6
by: Richard Barnet | last post by:
Dear CSS gurus, My question regarding 'the cascade' is a simple one, but one that I haven't heard anyone talk about before: When cascading (for instance, when applying two linked stylesheets),...
25
by: Tim & Alethea Larson | last post by:
In order to mark links leaving my site, I recently added this rule to my stylesheet. A:after { content: "\2197" } The character is a northeast-pointing arrow, since that seems to be fairly...
2
by: Andrew Poulos | last post by:
If I have some HTML that looks like this: <div class="option"> <table> <tbody> <tr> <td>blah</td> <td>blah</td> </tr> </tbody>
2
by: datactrl | last post by:
Hi, Can I define a css class selector depending on another class selector? Thanks a lot! Jack
2
by: Chris Sharman | last post by:
See http://services.ccagroup.co.uk/testform.htm Looks as intended in firefox, is valid (bulk of inputs centred in a div occupying the left half of the page). ie ignores the child selector,...
21
by: Peter Olcott | last post by:
I got the previous alias to std::vector working, and found that it takes up the space of a pointer. I want to find a way to do an alias to a std::vector that does not take up any space. Is there...
8
by: sajid | last post by:
The CSS 2.1 Specification describes how to sort a list of selectors in order of specificity, but it doesn't provide a method to calculate the specificity of a single selector in isolation. I've...
0
by: JakDaniel | last post by:
is it possible, create a selector as alias of another selector... (maybe) in another stylesheet file? ex: html page .... <link rel="stylesheet" type="text/css" href="style1.css" /> <link...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.