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...

Android developer roadmap

  A skilled Android developer can fix the problems of millions of people. With only one app. But with only  5,9 million Android developers  worldwide there is a huge demand for more.  If you want to be part of the most popular mobile platform in the world there is no better time to start. This blog will guide you through your  android developer roadmap  and help you understand the fundamentals Table of Contents How long does it take to become an Android developer? 1. Choose an IDE for android development 2. Pick a language 3. Get familiar with the anatomy of an app 4. Learn the basics of UI 5. Learn the paradigm of asynchronous programming 6. Explore the fundamentals of Android Jetpack 7. Choose where to store your data 8. Connect your app to the internet 9. Choose the right application architecture 10. Don’t forget to test your code  11. Configure your application build Conclusion How long does it take to become an Android developer? To be honest, it’...

Difference between http:// and https://.

  Http and Https Whatever work we do in our life, first of all we take care of our safety. Like we use helmet while driving for our safety, Keep our money safe by depositing money in banks, to protect mobile and laptop from virus Keep the device safe by using antivirus, in the same way when we search any information from browser or do online transaction using internet, then a secure link exists between our device and server which can protect our personal data from any hacker. Keeps it out of sight, the name of that link is https. We all use the internet every day and you must have also seen that Http or Https is written before the domain address of any website. Have you ever wondered what it all means  And why is it used? In today's post, we are going to give you information about this topic. Where we will tell you what is Http and Https and what is the difference between these two. So first of all we will know what is http? The full name of Http is Hyper Text Transfer Protoco...