1
I need to modify some CSS styles according to a condition in PHP, so I gave a search, and so I saw it is necessary to include a header in the CSS file and change the file .css
for .php
, or create an htacess file (but where? where?)... but I think because they are old, these articles are outdated with some (or all, or no :D) versions of PHP, CSS, Apache or Bootstrap that I’m using, or else more likely, that it’s just me doing something really wrong.
The case is that I assembled these panels with nav-tabs
bootstrap:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="row">
<div class="col-md-4">
<div class="panel panel-success">
<div class="panel-heading" align="center">
<label class="btn" id="cdom">
<i class="glyphicon glyphicon-ok">
</i> Título</label></div>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#sectionA">Resumo</a></li>
<li><a data-toggle="tab" href="#sectionB">Entenda</a></li>
</ul>
<div class="tab-content">
<div id="sectionA" class="tab-pane fade in active">
Seção A
</div>
<div id="sectionB" class="tab-pane fade">
<h5>Section B</h5>
</div>
</div>
</div>
</div> <div class="col-md-8></div>
</div>
</div>
<div class="col-md-2"></div>
</div>
And I’ve managed to change the color of panel-header
escaping the HTML, according to one condition.
<div class="panel <?php if ($var1 > 60000){echo 'panel-success';}else {echo 'panel-danger';}?> bs-example" align="center">
But now I need to also change the CSS of nav-tab
, according to the same condition. I have tried to do span
, but it didn’t work. And I’ve changed the name of the CSS file, it includes the header
and called the .php
where the variable is, but it still didn’t work.
The current CSS style.php
:
<?php header('Content-type:text/css');
include "../saida.php";
?>
.nav-tabs > li.active > a,
.nav-tabs > li.active > a:hover,
.nav-tabs > li.active > a:focus {
color: #020202;
cursor: default;
background-color: <?php if ($var1 > 60000){echo '#0e7363';}else {echo '#f2dede';}?> ;
border-bottom-color: transparent;
}
But he still doesn’t change the color according to the condition.
The question
How to include PHP script in CSS file, without having to change to .php
, that is, using the htacess
or the equivalent, and how to include PHP within the CSS (the form I am doing is correct?)?
It is not easier just to change the return of php with different css classes according to the situation?
– Eduardo Silva
Yes, it can be with class, according to the condition of php, but anyway I also wanted to learn how to use php within CSS. Thanks.
– gustavox
As far as I know, there is no way you can apply a php file without the extension .php. What I think is feasible is to apply the css style in your index.php. Or do as @Eduardosilva said
– Andrei Coelho
@EduardoSilva http://answall.com/questions/65154/como-criar-classes-css-contendo-outras-classes-do-bootstrap
– gustavox
I was able to solve with classes according to @Eduardosilva’s answer in this question, but I still have the doubt about the right way and even the security of including PHP in a CSS file. According to a comment in this question no Soen "Echoing unsanitized input Leaves the door open for Injection Attacks via malcrafted Urls.". I edited the question (including the title) to include the security issue.
– gustavox