L
L
leracoder2021-06-09 10:18:17
1C-Bitrix
leracoder, 2021-06-09 10:18:17

How to properly use PHP variables in CSS?

I'm working to enable the user to set site styles from the infoblock without getting into the code (the site's base color, text color, indents and button sizes, etc.).

Can you please tell me how to create a file with styles, in which the style values ​​will be taken from the infoblock? (this will be the main file that is included in the header)

for example:

<?
$bodyColor = .. (uploading values ​​from the infoblock)
?>

body{
color: <?=$bodyColor?>;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Borisovich, 2021-06-09
@Alexufo

1) output a file with css variables by default either in the general css code of the site or in a separate file.
2) below, output the same file with variables through some kind of Bitrix function for connecting new css, but with variables from your infoblock, or echo the style tags of your new variables to the site page.
3) your file will override the first default one.
this is only possible when using native variables
element {
--main-bg-color: brown;
}
=======
Second option: mark up your html with inline styles.

<body style="color:<?=$myColors['body_color']">
<div style="color:<?=$myColors['area2_color']">

if there are values, they will override the colors from css

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question