jaymc Posted July 20, 2008 Share Posted July 20, 2008 Is their a way to do this .mytext { color:#ff0000; } .someclass { text-align:center; background-color:#000000; color: .mytext } I know thats not the correct syntax, but in my head thats how i'd like it to work. This means that rather than constantly defined the text colour in each class i make, I can just do it once and import it into each class This is just a dummy example, so dont say put it in the body {} etc, it needs to work like above Can this be done? If so, how Thanks Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/ Share on other sites More sharing options...
ToonMariner Posted July 20, 2008 Share Posted July 20, 2008 you have a couple of possibilities. in css.... .mytext, .someclass { color:#ff0000; } .someclass { text-align:center; background-color:#000000; } or kind of using your original code... (note the color: .mytext WILL fail so don't use it) .mytext { color:#ff0000; } .someclass { text-align:center; background-color:#000000; } <p class="someclass mytext"> ... </p> Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/#findComment-595062 Share on other sites More sharing options...
TheFilmGod Posted July 21, 2008 Share Posted July 21, 2008 Is their a way to do this .mytext { color:#ff0000; } .someclass { text-align:center; background-color:#000000; color: .mytext } I know thats not the correct syntax, but in my head thats how i'd like it to work. This means that rather than constantly defined the text colour in each class i make, I can just do it once and import it into each class This is just a dummy example, so dont say put it in the body {} etc, it needs to work like above Can this be done? If so, how Thanks The code you posted will not work. You can not define classes within other classes. Instead, css cascades from the parent div to the child divs - this is called inheritance and in many ways, is similar to your idea. Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/#findComment-595121 Share on other sites More sharing options...
haku Posted July 21, 2008 Share Posted July 21, 2008 The only real way to do this is to make your stylesheets php documents, then add the color using php. You will want to look at how to cache php documents if you decide to use this method however. It's not easy. Using the find and replace function in whatever text editor you are using would probably be easier and faster in the long run. If you want to change from #123456 to #654321, then you just use ctrl+f and enter in the first one. Every time it finds it, change it. Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/#findComment-595289 Share on other sites More sharing options...
jaymc Posted July 21, 2008 Author Share Posted July 21, 2008 Yeh as i thought, thanks Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/#findComment-595487 Share on other sites More sharing options...
ToonMariner Posted July 22, 2008 Share Posted July 22, 2008 The only real way to do this is to make your stylesheets php documents, then add the color using php... No it isn't. You should have NO need for php to generate a css file ever - the beauty of cs files is that they are cached and hence speed up the rendering of your site... The ONLY situation where I use php to control anything to do with my presentational layer would be to generate inline styles - and then I'll only use it to put background-image: url(/path/to/image); in something like a product list... Use css well and you don't end up with reams of css to manage - the technique I gave earlier in this thread is very much the way you should build your presentational layer. Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/#findComment-596118 Share on other sites More sharing options...
haku Posted July 22, 2008 Share Posted July 22, 2008 His point was that he wanted to be able to change the color once, and have it changed for all items that used the same color. I at the time couldn't think of a way to do it other than PHP, which is why I suggested it. As for caching, php files can be cached, though it is a bit of a pain in the ass to do it. BUT that all being said, anything that requires the color could be put into one selector so that the color would only have to be changed once. For example: a.this_class, #some_id, div span a.link, pre.another_class // add all other areas that use the color in question { color: red; } It would make that one statement very bulky, but it would solve the problem of only having to change the color in one spot, and having that be reflected anywhere that color is used. Quote Link to comment https://forums.phpfreaks.com/topic/115704-solved-apply-a-class-to-another-class/#findComment-596188 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.