0

If I have certain styles that need to take place upon some php condition, is it valid and good practice to use the style tag inside php scripts ?

if(condition){ echo "<style> .div{display:block} </style>"; } else { echo "<style> .div{display:none} </style>"; } 

I am thinking that since the tag is not place in the head of the document, it could be a problem ? Or is this a usual way of doing this sort of thing ?

Thank you.

1
  • 1
    Sure you can, if it's good practice that's another thing. How about you have classes for each of these and apply the correct class to the div based on the condition? Commented Dec 9, 2018 at 15:28

1 Answer 1

1

The way you are doing certainly works, but it's not a good practice to mix PHP with html/css this way. The best way is to use a template class to manipulate the html.

As a beginner you may be overwhelmed with the features of most advanced template classes, so I recommend start with something simple to get the basic concept.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.