Writing an extension for a plugin I have the opportunity to change all the attributes of an HTML element using PHP.
$attributes["style"] .= 'padding-left:10px;'; array_push($attributes["class"], "long-container"); array_push($attributes["class"], "super smooth"); $attributes["data-whatever"] = "great";
Now I want to give the user the opportunity to enter the width / height ratio of the div dynamically (the decision on how to do this is described in the @Web_Designer answer here: Maintain the aspect ratio of the div with CSS ).
Inside the function, where I can change the output of a third-party plugin, I wrote the following code to calculate the height-to-width ratio according to the input. Since the height of my boxes is:
if( !empty( $args['stretchy-desktop'] ) ) { $sd = array_map('trim',explode(":",$args['stretchy-desktop'])); if(count($sd)==2) { $sd[0] = floatval(str_replace(",",".",$sd[0])); $sd[1] = floatval(str_replace(",",".",$sd[1])); if($sd[0]>0 && $sd[1]>0) { $padding = ($sd[1] / $sd[0])*100; array_push($attributes['class'], 'stretchy-desktop'); $attributes['style'] .= 'padding-bottom:'.$padding.'%;'; } } }
Good? However, now the user wants to enter a different weight ratio for mobile devices, as well as another dynamic minimum height for mobile devices, and I'm stuck.
1) It is impossible to give @media inline queries right now, otherwise my solution would be like this ( Is it possible to set CSS @media inline rules? ):
$attributes['style'] .= '@media (min-width:540px) {padding-bottom:'.$padding.'%;}@media (max-width:539px) {padding-bottom:'.$padding_mobile.';}';
2) It is not possible to use HTML attribute values ββin CSS right now ( CSS values ββusing HTML5 data attribute ), otherwise my solution would look like this:
$attributes['data-desktoppadding'] = $padding; $attributes['data-mobilepadding'] = $padding_mobile;
In CSS:
@media (min-width:540px) { .long-container { padding-bottom: attr(data-desktoppadding); } } @media (max-width:539px) { .long-container { padding-bottom: attr(data-mobilepadding); } }
3) Since the values ββare dynamic numbers, I cannot define a CSS class for all possible existing floats.
Of course, I could use JavaScript, but we all know the significant flaws (including the ugly page loading).
Can you come up with any CSS solution for this dilemma?