+ 10

Is this valid in CSS?

Is this line of code a valid way to set the margin? I mean is it ok to give this property a negative value? /* margin: -21.5px -10px 10px -10px; */

13th Jun 2019, 10:56 PM
1234554
14 Réponses
+ 6
It's very okay to have negative margins, just as long as you're aware that negative margins could lead to elements overlapping
13th Jun 2019, 11:24 PM
Dlite
Dlite - avatar
+ 8
Yes!
15th Jun 2019, 1:02 PM
CodeFu
CodeFu - avatar
+ 8
Yeah
22nd Jun 2019, 12:05 PM
Suraj Web
Suraj Web - avatar
+ 7
D'Lite Thanks.
13th Jun 2019, 11:26 PM
1234554
+ 6
If you're ever wondering about code validity, you can always run your code through a validation service. Here's an example: https://jigsaw.w3.org/css-validator/validator.html.en#validate_by_input You can write (almost) anything between /* and */, so you will want to take those off before running the code through the validator. In this case, since you have a standalone rule, you will also want to include it in a ruleset (so apply it to a class or id or other selector) for the sake of the validator. I hope this helps. 🤷🏻‍♂️
15th Jun 2019, 11:10 AM
Janning⭐
Janning⭐ - avatar
+ 6
Thanks everybody for answering.
16th Jun 2019, 1:22 PM
1234554
+ 5
No
15th Jun 2019, 6:47 AM
Bharat Bhushan
Bharat Bhushan - avatar
+ 5
PS Half pixels are valid in CSS. https://stackoverflow.com/questions/9080633/can-a-css-pixel-be-a-fraction How the browser chooses to render it varies.
15th Jun 2019, 11:20 AM
Janning⭐
Janning⭐ - avatar
+ 4
Yes but it would not work till you remove /* */
19th Jun 2019, 1:56 AM
Soumyajeet Routray
Soumyajeet Routray - avatar
+ 3
Yeah. negative would make it go the opposite way. Like... if you have margin-top: 50px -> would move it down 50pixels. if you put it negative: margin-top: -50px, it will make it go up 50pixels. opposite of down (50) = up(-50).
14th Jun 2019, 12:52 AM
Ginfio
Ginfio - avatar
+ 3
No it's not, "21.5" isn't correct because you can't use "half a pixel". But everything else is ok.
14th Jun 2019, 8:13 PM
haydenki
haydenki - avatar
+ 3
Yes
15th Jun 2019, 3:32 AM
Adarsh Soni
Adarsh Soni - avatar
+ 2
pathetic_millenial u can't use half pixel? is that really = true?
15th Jun 2019, 5:16 AM
Ginfio
Ginfio - avatar
0
Yes
22nd Jul 2019, 10:06 PM
Opara Victor Ndubuisi
Opara Victor Ndubuisi - avatar