This content originally appeared on DEV Community and was authored by Garvit Motwani
CSS plays a major part in the field of web development and can be easy and at a point, it can also be advanced and tough, throughout CSS's history, numerous tricks have been discovered by the developer community. Today I will tell you a few of them.
So let's get started!
Reset
This one is pretty simple, it basically means to reset the whole document's default styling which is given by the browser itself. Most developers make a reset when they want nothing to get in their project's way or maybe for some specific project that needs one! Every developer has their own preference for using which reset as I use:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
Some developers use:
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
The above reset is meyerweb.com and for more, you can just search reset CSS on google to find your own preference.
Capitalization
This is a common trick but it is sometimes not taught in the CSS tutorials or course, so many developers still don't know this trick. It basically capitalizes the first letter of every word in a particular tag. Look at this for example:
As you can see I have not capitalized any letter manually in the HTML, instead, I wrote text-transform: capitalize;
and it did it dynamically.
Centering
Centering is easy but, in my case, I usually don't remember the code to center text or content. So I use some short code snippets for that which I stored in my notes ?.
You can use text-align: center;
to center the text
To vertically center text in a div
, you can use margin: auto;
, but to give you a proper example you should take a look at this:
and then you can also add `text-align: center to center it both, horizontally and vertically.
To center an image, you should first of all turn it into a block
element and do a margin: auto
.
Drop Caps
Remember that 1st big letter in every chapter of your literature book or the start of a novel or a book. You can do that by using this snippet:
Prevent Highlighting
If you don't want the user to select or highlight anything on your website to prevent copying content, or maybe for some personal or any reasons, you can just use this:
⚡️ Giveaway ⚡️
We are giving away any course you need on Udemy. Any price any course.
Steps to enter the giveaway
--> React to this post
--> Subscribe to our Newsletter <-- Very important
--> Follow me on Twitter <-- x2 Chances of winning
The winner will be announced on May 1, Via Twitter
Thank you very much for reading this article.
Comment any tricks & tips you know!
PLEASE LIKE, SHARE, AND COMMENT
You Should also check
Projects ideas to become a javascript master ? Resource compilation ? + Giveaway⚡
DevLorenzo ・ Apr 10 ・ 7 min read
by my friend @devlorenzo
Subscribe to our newsletter to receive our weekly recap directly on your email!
Join us on Discord to participate in hackathons with us / participate in our giveaways!
Happy Coding.
This content originally appeared on DEV Community and was authored by Garvit Motwani
Garvit Motwani | Sciencx (2021-04-20T00:35:14+00:00) 5 CSS Tricks & Tips That You Should Know ? + Giveaway. Retrieved from https://www.scien.cx/2021/04/20/5-css-tricks-tips-that-you-should-know-%f0%9f%9a%80-giveaway/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.