Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variables in CSS file

I have a Java Web Project and I want to have a split test in my application. I want to be able to select different header images according to the passed query string. For instance, if the user retrieves the following url:

http://www.website.com/?header=1

Then I show the image A for the header. If the user retrieves the url like this:

http://www.website.com/?header=2

The I show the image B. I'm already receiving the 'header' value in my html by expression language variable. The problem is that I set the image url in a CSS file. How can I pass this variable to the CSS file to load the correct image?

PS: I know I can apply the style in the HTML file, but I want to extract all of my styles in the CSS file.

like image 922
Guto Marrara Marzagao Avatar asked May 01 '26 08:05

Guto Marrara Marzagao


2 Answers

That's not possible unless you use something like LESS.

What you could do is make separate CSS files, use the querystring to determine your needs with Java Web and load the one you need depending on the situation.

like image 150
DarkAjax Avatar answered May 03 '26 20:05

DarkAjax


include 2 different classes for the different background header images in your css, then apply the different class in coding.

.header1 {
background-image: url(background1.jpg);
}

.header2 {
background-image: url(background2.jpg);
}
like image 31
Robert Owen Avatar answered May 03 '26 20:05

Robert Owen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!