DEV Community

Discussion on: 15 CSS3 Best practices of for beginners to pro.

Collapse
 
mariog8 profile image
Mario Golik • Edited

The article is great, well doneπŸ‘ŒπŸ˜ŽπŸ‘ I would add a tiny few more useful functions and tips from myself ...I will not describe them here, I will tell the names and I count on the human curiosity...😁

1) use CSS Custom Properties (Variables)
2) use when flex-box single columns/rows , Use Grid when multiple columns/rows.
3) min, max, clamp CSS functions
4) Calc CSS function
5) CSS counters
6) aspect-ratio(video)

And the last and i think most important (for me) Use dev-tools (firefox) when you styling in CSS .We can edit properties directly on fly and testing those.

I hope it will be useful ! See you ! Best Regards ...and Keep on Coding!πŸ˜‰πŸ–πŸ’»

Collapse
 
darkwiiplayer profile image
π’ŽWii πŸ³οΈβ€βš§οΈ

Use Grid when multiple columns/rows.

Not always; some layouts look like they should be done using display: grid, when in reality they are just a bunch of boxes that wrap over several lines. In these cases, display: flex is still the better option.

Grid becomes useful when you want finer control over the alignment of your elements, specially when you don't want to just fill the grid cells one after another.

Collapse
 
mariog8 profile image
Mario Golik

Awesome suggestion! Context is the King πŸ˜‰ Could you send or show(link) us some examples this "some layouts" ? Just to reference and knowledge obviously...πŸ’» πŸ’‘

Thread Thread
 
darkwiiplayer profile image
π’ŽWii πŸ³οΈβ€βš§οΈ

Can't think of any specific example right now, but think product cards for example, where you have 3 of them on each line and they look somewhat like a grid; but really, they can just be in a flex container with flex-flow: row wrap. Same goes for any other listing of items, like users on a social media site, etc.

Thread Thread
 
mariog8 profile image
Mario Golik

Take your time.... I am very patient and hungry for example, By the way learning from example is, in my opinion, one of the best teaching methods πŸ˜‰
Have You Great Day and do not haste 😎

Thread Thread
 
menomanabdulla profile image
menomanabdulla • Edited

dev-to-uploads.s3.amazonaws.com/up...
Like such layout, you should use grid. It's easily manageable with grid, flex will be most difficult for this one.

Most recently i will bring a series of article based on CSS Grid, stay stick and keep learning. I love your dedication.

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡ • Edited

@mariog8 here you have a full ui framework example using flex codepen.io/joelbonetr/pen/PoqzMWL

The refactor using mixins and that was uploaded to a private repo, but this example can show you how easy and handy Flex works, including cards, forms, content blocks and so on with two different approaches as test case/playground.

Thread Thread
 
mariog8 profile image
Mario Golik

thx for great example πŸ˜‰πŸ‘ It is never late to learn.

Collapse
 
menomanabdulla profile image
menomanabdulla

@darkwiiplayer cool, I am totally agreed with you. There is lots of complex layout we can still manage with flex. We can also use grid to solve the same problem, In such case I would love to use flex. Usually I use grid for more complex layout, such multiple rows, cols and also multiple alignment issues. Love your effort man. Thanks a lot.

Thread Thread
 
darkwiiplayer profile image
π’ŽWii πŸ³οΈβ€βš§οΈ

Sometimes it's even easier to use flex, because that way you can just define a desired width for your items and let them wrap wherever they want. With grid, one would have to use media-queries to define cut-off widths for 2, 3, 4, etc. columns. I'd much rather let the browser figure those things out instead of adding special cases for different resolutions 😁

Thread Thread
 
menomanabdulla profile image
menomanabdulla

Exactly, it is.

Collapse
 
menomanabdulla profile image
menomanabdulla

Great! you added some important points here, Keep doing good stuff and spread it. I appreciate your effort man.

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡
use when flex-box single columns/rows , Use Grid when multiple columns/rows.

This is opinionated, you can fine-tune a flex grid system easily if you understand how it works, it gives you more flexibility than grid can bring.

3) min, max, clamp CSS functions 4) Calc CSS function 5) CSS counters

Those are not good practices, are simply things that you can use whenever are needed.

Collapse
 
mariog8 profile image
Mario Golik

For me it's practice for You simple things ...everyone thinks differently,I respects your subjective opinion .

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

A best practice is a technique or methodology that, through experience and research, has proven to reliably lead to a desired result. In software development we use best practices as well-defined methods that contributes to a successful steps in product/project development. Thus are general statements that -desirably- are followed by each individual to achieve a solid homogeneous joint result for a given tech stack.

Reducing your functions to a single responsibility is a good practice that exerts from the clean code group. Using a given language predefined method or function cannot be a good practice because you simply will use it when needed, so if you state that using CSS min, max and clamp are good practices, you'll need -scientifically- to state all language reference as good practices and even that, they are conditioned to a conditional context.

If you need something to be 100% it's parent width, is it a good practice to use min, max or clamp to achieve this? of course not. You simply do width: 100%.

The same way you will not find statements like "in JS a good practice is to use split method" because it's only good whenever is needed and not "always" or "in any case", instead we say "Don't Repeat Yourself" or DRY principle, which enforces you to use existing code methods or functions instead re-coding them, which can be applied to any case, thus if split method exists you'll use it instead coding a custom split -as long as it fits-.

There's something I need to remember many times in this platform but again here it is: IT is a science, thus there are methodologies, patterns, best practices, tests... you can try different approaches and apply synthetic tests as benchmarks to analyse which one works better or even do A-B tests to see how user interacts with different UI versions of your software.

In conclusion if you say something is good or that is better but you can't tell why using reliable source or public benchs/tests, you are doing what is called opinionated or anti-scientific pattern.

Thread Thread
 
mariog8 profile image
Mario Golik

I respect your essay but I have a different opinion, relax man .πŸ˜…

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

You didn't get the point, did you? xD

You have no opinions in science, you can theorise, then make a test suite that covers your theory, try things down, get data as result, merge this result with each test case result and extract conclusions from that. Then your investigation will eventually be peer-reviewed to give or take credit, making it more or less reliable or true/false.

I see in your profile that you are a self taught, this probably means that there were no teacher teaching you about that in computer science research methodology, even that, you can learn about software engineering, research methodology, algebra, logic and so on as there are tones of resources extracted from college subjects online for free, it's just a bit harsh in comparison to learn how to code with a given language but this kind of things are what can make you work on a serious well-driven company with -usually- a better salary as well as being able to work on a larger number of companies or roles in the industry.
You can even become a tech lead if you take effort in this subjects (I recommend you to get an official certificate whenever you can as well, it will definitely help you grow in your career).

Finally please, don't pick this words as an offence to you but as a good advice to follow.

Thread Thread
 
mariog8 profile image
Mario Golik

Thank you very much for your valuable advice. I am glad that you gave me tips, it is important and very precious for me. If you find a moment, take a look at my portfolio page and evaluate if you can (I care about constructive criticism) It would be very nice for me ... Have You a great day. See you next time ...πŸ˜‰

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

You're welcome, I'll pin a tab with your portfolio and will take a look at it after the meetings today :D
Have a great day!

Thread Thread
 
mariog8 profile image
Mario Golik

Thanks a lot, fruitful day and successfully meetings πŸ˜‰πŸ‘

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

thanks, I sent you some private messages (chat icon near notification bell icon at the top) :D