Skip to main content

5 Essential CSS Tricks for Beginners



Welcome to TechBitu! If you're just starting out with web development, mastering CSS (Cascading Style Sheets) is crucial for creating visually appealing and responsive websites. In this guide, we'll cover five essential CSS tricks that every beginner should know. These tips will help you enhance your web design skills and create better user experiences. Let’s dive in!


### Table of Contents

1. [Centering with Flexbox](#centering-with-flexbox)

2. [Responsive Images](#responsive-images)

3. [Box Shadows](#box-shadows)

4. [Custom Fonts](#custom-fonts)

5. [Hover Effects](#hover-effects)


### 1. Centering with Flexbox

One of the most common challenges in web design is centering elements both vertically and horizontally. Flexbox makes this task straightforward and efficient.


```css

.container {

    display: flex;

    justify-content: center;

    align-items: center;

    height: 100vh;

}

```


In this example, the `justify-content: center;` centers the child elements horizontally, while `align-items: center;` centers them vertically within a container that is 100vh (viewport height).


### 2. Responsive Images

Ensuring that images scale properly on different devices is essential for a responsive design. The following CSS ensures that your images are always scaled to fit their containing element:


```css

img {

    max-width: 100%;

    height: auto;

}

```


The `max-width: 100%;` rule ensures that the image will not exceed the width of its container, while `height: auto;` maintains the aspect ratio.


### 3. Box Shadows

Adding shadows to elements can give them a sense of depth and make your design more engaging. Here’s a simple way to add a shadow effect to a box:


```css

.box {

    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

}

```


In this example, `box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);` creates a subtle shadow below the box, with a slight blur effect to enhance the visual depth.


### 4. Custom Fonts

Custom fonts can significantly improve the aesthetic of your website. Here’s how to import and use a Google Font in your CSS:


```css

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');


body {

    font-family: 'Roboto', sans-serif;

}

```


This code imports the Roboto font from Google Fonts and applies it to the body of your document. Using `@import url(...)`, you can include various font styles and weights to enhance your typography.


### 5. Hover Effects

Hover effects can make your website interactive and engaging. Here’s a simple example of changing the background and text color of a button when a user hovers over it:


```css

.button:hover {

    background-color: #555;

    color: white;

}

```


The `.button:hover` selector applies styles to the button element when hovered over. In this case, the background color changes to #555, and the text color changes to white, providing visual feedback to the user.


### Conclusion

Mastering these five CSS tricks will set you on the right path to becoming a proficient web developer. Whether you’re working on personal projects or professional websites, these techniques will help you create visually appealing and responsive designs.


Don’t forget to save and share this post with fellow developers who might find these tips useful. Happy coding!



### Links:

- [Google Fonts](https://fonts.google.com/https://fonts.google.com/)

- [CSS Tricks - A Complete Guide to Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/)



---



Comments

Popular posts from this blog

What is flutter ?

Flutter is Google’s portable UI toolkit for building beautiful, natively-compiled applications for  mobile ,  web,  and  desktop  from a single codebase. What is Flutter? Flutter is a mobile app SDK for building high-performance, high-fidelity, apps for iOS and Android, from a single codebase. The goal is to enable developers to deliver high-performance apps that feel natural on different platforms. We embrace differences in scrolling behaviors, typography, icons, and more. No mobile development experience is required to get started. Apps are written in Dart, which looks familiar if you’ve used a language like Java or JavaScript. Experience with object-oriented languages is definitely helpful, but even non-programmers have made Flutter apps! Why use Flutter? Here are some advantages of Flutter: Be highly productive It is used for  iOS app development  and  Android app development  from a single codebase. Do more with less code, even on a sing...

What Is Satellite? How Does It Work?

  How Does It Work? Table of Contents What is a Satellite? Anatomy of a satellite How does a satellite communicate? Bandwidth and Transmission Suggested Reading Satellites communicate by exchanging electromagnetic waves, either on the Earth’s surface or in space, hovering above a pole or orbiting us everyday. Communication doesn’t necessarily have to occur in the Radio spectrum. Your TV remote communicates with its set top box with infrared waves, while phones communicate with microwaves. Google Earth provides you the opportunity to visit any place on Earth, yet what do most people do? Look at their own house. In fact, Google Earth doesn’t just show you high-resolution pictures; like Scrooge on one of his ghosts, you are practically tossed there, as you can witness walking pedestrians and live traffic! But how does Google Earth achieve this feat? With satellites! What is a Satellite? The word satellite doesn’t necessarily describe a mechanical box floating through space with...

What is SQL?

  SQL is a programming language used to communicate with and manipulate databases. Structured Query Language (SQL) is a programming language used to communicate with and manipulate databases. SQL was developed in the 1970s by IBM researchers. SQL is extremely accessible across various platforms and generally user-friendly. This article is for business owners interested in hiring an SQL developer to revolutionize the way they view, analyze and make decisions from existing data. SQL (Structured Query Language) is a programming language used to communicate with and manipulate databases. To get the most of the mounds of data they collect, many businesses must become versed in SQL. Here’s everything you should know about using SQL to access and manipulate data. What is SQL? Businesses and other organizations use SQL programs to access and manipulate the information and data in their databases and create and alter new tables. To fully understand SQL, you need to know exactly what a datab...