How to make a content property in css use php
Tags: php,html,css,arrays
Problem :
So I take from an array some informations for a barlike chart I made. Here is the CSS:
<style>
.outer,
.inner,
.target {
height: 14px;
margin-bottom: 5px;
}
.outer {
background-color: #cccccc;
width: 80%;
margin: 20px auto;
position: relative;
font-size: 10px;
line-height: 14px;
font-family: sans-serif;
}
.inner {
background-color: green;
position: absolute;
z-index: 1;
text-align: right;
border-right: 2px solid black;
}
.inner:after {
content: '$avg_width';
display: inline-block;
left: 10px;
position: relative;
height: 100%;
top: -14px;
}
.target {
background-color: transparent;
width: 19px;
position: absolute;
z-index: 2;
color: black;
text-align: right;
border-right: 2px dotted black;
}
.target:after {
content: 'Target: $target_width';
display: inline-block;
left: 28px;
position: relative;
height: 100%;
top: 14px;
}
.solid_line {
color: black;
float: right;
width: 3px;
border-right: 3px solid black;
height: 16px;
}
</style>
Here is the php:
<?php
$target = number_format((float)$data->data[2][32][3], 2, '.', '');
$array = [];
$sum = 0;
$path = $data->data[2];
$bar_width = '200px';
foreach($path as $key => $item){
if($key > 1 && isset($item[5])){
$array[] = (int)$item[5];
$sum += (int)$item[5];
}
}
$avg = ($sum / count($array));
$base = max($target, $avg);
$target_width = $bar_width / 100 * ($target / $base * 100);
$avg_width = $bar_width / 100 * ($avg / $base * 100);
$percent = $avg / $target;
?>
And here is the HTML:
<div class="outer">
<div class="target">
</div>
<div class="inner">
</div>
</div>
As you can see I try to make use of the content property in css and to use php within it, but for some reason it does not display the results.
Solution :
That's because you're accessing PHP variable directly in CSS. HTML/CSS are executed client side where as PHP executes on client side.
So you need to echo the PHP variable inside your on page CSS. Like this:
.inner:after {
content: '<?php echo $avg_width ?>';
Above echo
code will execute on server side and give value to client side CSS to render the element properly.
Make sure You're using it on ON PAGE/INLINE CSS, this won't work on external .CSS files.
CSS Howto..
It should be pretty easy in jQuery. if(n == 1){ $('your_image_element').css('background-image','url(your_first_img_path)') ; }else if(n ==2){ // second image... } ...
For example: hr { border:none; border-top:1px dotted #f00; color:#fff; background-color:#fff; height:1px; width:50%; } See also Styling <hr> with CSS....
The ul.socialaccount_providers has a inexplicit padding-left = 40px; Just throwing in .socialaccount_providers {padding-left:0;} fixes it....
Note that months are zero indexed so January is 0, February 1 and so on so December is 11. Pretty easy to fix, just add 1 to the month number...
You're just missing a /div - I notice you have a div inside a div, remember you need to close both. I use Netbeans for html and it will tell...
I ended up applying the class name "mf" to the section and using the generic "textarea" element to style all textareas on the site using this: .mf { textarea {...
Working jsFiddle here. Use :nth-child(4n+3), :nth-child(4n+4) CSS: li:nth-child(4n+4), li:nth-child(4n+3) { color:red; } HTML: <ul> <li>No</li> <li>No</li> <li>YES</li> <li>YES</li> <li>No</li> <li>No</li> <li>YES</li>...
You could probably just use 2 divs. The top on is all white except the part what the logo is, that part should be empty (a png). You put the...
If your backgrounds are that simple and loopable, you could create the black one with the wave (loopable in x-dimension) and then use multiple backgrounds. background: url(black.png) left top repeat-x,...
You can create your own custom class and give the fonts property an "!important" tag, and apply that class to the menu too. This way only font property will be...
Add this to your CSS file. It should remove the extra margin. .panel-group .panel + .panel { margin-top: 0; } Additionally you could also add a class to your panels...
You might not see it initially, but if you click on the Node in Chrome Developer Tools "Elements"-Panel and select Copy -> Copy XPath, you will have the Path copied...
You can define multiple targets for the .my-class rule, then specify further rules just for .my-another-class: .my-class, .my-another-class { font-size: 12px; } .my-another-class { border: 0; } You can even...
Switch the order of your divs and then float them left: <div class="demo-container"> <div id="placeholder" class="demo-placeholder"></div> <div id="legend-container"></div> </div> CSS: .demo-placeholder { width: 80%; height: 80%; font-size: 14px; line-height: 1.2em;...
You can't do this with the <select> element. You can't have endless nested subcategory like you suggest, only one, with <optgroup>. Styling will also be difficult as the ability to...
Simply set the font-size for the :before psuedo. Demo Fiddle p { counter-increment: myIndex; } p:before { content:counter(myIndex); font-size:30px; } ...
float in the input box to the left, and float button to the right. Then add margins until they're lined up correctly.
It depends on how you are doing a/b testing. The method I would use is as follows, with the basic assumption you are using two different files, something like register-a.html...
Define a instance variable in controller for which css to load. lets say we will use stylefile variable in controller like this: @stylefile = "page1.css" Now write following code where...
A few things: Don't use generic class names like div. There's already an element element called div. If you want to target it based on nesting, do so using CSS....
Have a look at "liquid layouts" it can describe what you're talking about. You're probably looking for this one. In your example, try setting your display to inline. However, you...
One simple way of doing it is as follows: Wrap your text in an inline element, for example, <span>: <ul> <li><span>first</span></li> <li><span>second</span></li> <li><span>third</span></li> </ul> And apply the following CSS: ul...
The new ui-grid has a special property for the cellClass: $scope.gridOptions = { enableSorting: true, data:'myData', columnDefs: [ { field: 'sv_name', displayName: 'Nombre'}, {field: 'sv_code', displayName: 'Placa'}, { field: 'count',...
Well, you have two basic choices: Remove the extraneous files from your application.js and application.css. or <%= stylesheet_link_tag 'user_details', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'jquery', 'data-turbolinks-track' =>...
The best approach I have found so far is to export your variables as @value's using the postcss-modules-values plugin colors.css @value blue: #0c77f8; @value red: #ff0000; @value white: #fff; button.css...
Set the float property for each div to be matched, for example left to each, give each of them enough width so that the parent contains them. DEMO...
You can use JS or jQuery for this. Simply calculate the difference between the width of the .center <div> and the widow width, and then divide that by two to...
If you absolutely must use input, try this: background-image: url(...); background-repeat: no-repeat; background-position: <left|right>; padding-<left|right>: <width of image>px; It's usually a little easier to use a button with an img...
<ons-list-item> sets a property min-height, which you need to overwrite. So something like that should work: <ons-list-item style="height:20px; min-height: 20px" > ...
Usually GET-parameter for css and js is added in order to be able to update the cached file. But if you want it different text css depending on GET-parameters, then...