+ 8

How to write conditional statement in CSS?

My Question is that How to write conditional statement in CSS? if anyone can answer it.

2nd May 2017, 6:09 AM
Aijaz Ahmed
Aijaz Ahmed - avatar
6 ответов
+ 10
CSS doesn't support conditional statements (at least, the native IF/ELSE are not available in CSS) Remember CSS means Cascading Style Sheet so as a style sheet it should be thought only as a way of formatting the html, using style rules that tells the browser how the various styles are to be applied to the HTML tags to display the document. IF/ELSE are logical expressions and as such, the logic should be handled by a scripting language like Javascript, which will dynamically apply attributes based on conditions. However, although they're not worded as such, selectors and media queries can help you check something before running certain code. For instance, with media queries, you'd say: "If the screen is 500px or wider, change the color of the body's text to royalblue", for example: @media screen and (min-width: 500px) { body { color: royalblue; { } I must add though, that you might as well try using SASS which is CSS plus nested rules, variables, mixins, and more, all in a concise, readable syntax.
8th May 2017, 8:03 PM
Pao
Pao - avatar
+ 8
it's ok.
2nd May 2017, 6:22 AM
Aijaz Ahmed
Aijaz Ahmed - avatar
+ 7
it's ok.
2nd May 2017, 6:22 AM
Aijaz Ahmed
Aijaz Ahmed - avatar
+ 6
I want gate your ideas from your experience? thanks for you suggestion
2nd May 2017, 6:14 AM
Aijaz Ahmed
Aijaz Ahmed - avatar
+ 5
I think you are talking about media queries. More information can be found here https://www.w3schools.com/css/css_rwd_mediaqueries.asp Happy coding...
2nd May 2017, 6:12 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 4
Well I have not done many web projects but only one when designing a web page in a team, the thing that I learned is try to use a single naming convention in your javascript code and naming your html file. And also proper indentation should be there as it increases the readability of your code. And most importantly use DRY (Don't repeat yourself) rule.
2nd May 2017, 6:19 AM
Rishabh Agrawal
Rishabh Agrawal - avatar