Thursday, September 12, 2024

css selector :nth-child(n) , :nth-child(2n), :nth-child(2n+1), :nth-child(3n+1)

 The nth-child pseudo-class in CSS selects elements based on their position in a parent element's child list. The selector you mentioned, :nth-child(3n+1), selects every third child starting from the first one.

First we will see some basic examples

css style with nth child 2n+1



:nth-child(3n+1)

  • 2n: Represents multiples of 2 (e.g., 0, 2, 4, 6, ...).
  • +1: Adds 1 to each multiple, making the sequence start from 1 and select every third element (e.g., 1, 3, 5, 7, ...).

:nth-child(3n+1)

  • 3n: Represents multiples of 3 (e.g., 0, 3, 6, 9, ...).
  • +1: Adds 1 to each multiple, making the sequence start from 1 and select every third element (e.g., 1, 4, 7, 10, ...).

css style with nth child 3n+1


Thursday, September 5, 2024

How to use css selectors, :nth-child(n)

css selector :nth-child(n)


1) :nth-child(n)

The :nth-child(n) selector matches every element that is the n-th child of its parent, regardless of the type of element.

element:nth-child(n) { 
  /* styles */ 
}
    

  • Styles the second child if it is a <p> tag


p:nth-child(2) {
  color: blue; 
}  
    

Paragraph 1

Paragraph 2

Span 1

Paragraph 3

Paragraph 4

  • Styles the fourth child if it is a <p> tag


p:nth-child(4) {
  color: red; 
}  
    

Paragraph 1

Paragraph 2

Span 1

Paragraph 3

Paragraph 4

  • Styles the third child if it is a <p> tag

p:nth-child(4) {
  color: red; 
}  
  

Paragraph 1

Paragraph 2

Span 1

Paragraph 3

Paragraph 4

  • Styles the odd-numbered child if it is a <p> tag with :nth-child(odd)
:nth-child(odd) css selector


p:nth-child(odd) {
  background-color: pink; 
}  
  

Paragraph 1

Paragraph 2

Paragraph 3

Paragraph 4

Paragraph 5

Paragraph 6

Paragraph 7

Paragraph 8

How to Style Scrollbars with CSS for a Better-Looking Website

Styled Scrollbar Example

This is a paragraph with some content. It will generate a vertical scrollbar if the content exceeds the height of its container.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Try scrolling down to see the styled scrollbar.

Example code


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Styled Scrollbar Example</title>
<style>
/* width */
::-webkit-scrollbar {
  width: 6px;
}

/* Track */
::-webkit-scrollbar-track {
  background: #b5b5b5;
}

/* Handle */
::-webkit-scrollbar-thumb {
  background: #6e84ff; /* Change the color to blue */
  border-radius: 20px;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Example additional styles */
.content {
  height: 200px;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid #ccc;
}
</style>
</head>
<body>

<div class="content">
  <h1>Styled Scrollbar Example</h1>
  <p>This is a paragraph with some content. It will generate a vertical scrollbar if the content exceeds the height of its container.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
  <p>Try scrolling down to see the styled scrollbar.</p>
</div>

</body>
</html>

    

Monday, September 2, 2024

React js vs Angular, Which one you should choose.

 

React js and Angular is the most populer js library and framework now day, but its very confusing for a developer in initial stage which one to choose.

In this blog we will try to clear which library or framework is better based on the the project complexity.

Feature React.js Angular
Performance High performance with Virtual DOM for efficient updates and rendering. Good performance but can be slower in complex apps due to real DOM manipulation.
Complexity Less complex, lightweight, and flexible with fewer built-in features. Highly complex, with a steep learning curve due to its comprehensive nature and in-depth features.
Routing Requires third-party libraries (like React Router) for routing. Built-in, robust routing module that is easy to set up and use.
API Integration Uses `fetch` or `Axios` libraries for HTTP requests; integration depends on developer preferences. Comes with a built-in HTTP client module for API integration, simplifying RESTful service calls.
Data Binding One-way (unidirectional) data binding, which makes debugging easier and enhances performance. Two-way data binding, which simplifies form handling but can impact performance in large applications.
Development Ease Easy to learn and use for developers familiar with JavaScript; offers greater flexibility with less boilerplate. More challenging due to TypeScript and extensive built-in features; provides a complete solution out of the box.

Wednesday, August 28, 2024

Six PHP 8.x useful feature for better development

 PHP, one of the most widely used server-side scripting languages, has seen significant improvements and changes from version 7 to version 8. These changes not only enhance performance but also introduce new features that simplify coding practices and make PHP more robust and modern. In this blog, we'll dive into the top changes between PHP 7 and PHP 8, highlighting their impact on developers and applications.

1. JIT Compilation

  • Definition: JIT (Just-In-Time) compilation is a feature that compiles PHP code into machine code at runtime, aiming to improve performance.
  • Performance Improvement: It is especially beneficial for computationally heavy tasks and can significantly speed up execution in such cases.
  • Notes: For most web applications, JIT might not provide a substantial performance boost.

  • 2. Named Arguments

    PHP 8 introduces named arguments, allowing developers to pass arguments to a function by specifying the parameter names. 

    • This feature improves code readability and flexibility, especially in functions with many optional parameters.
    • Named arguments make it clearer what each argument represents, reducing the chances of errors and improving the maintainability of the code.
    php 8.x named argument image

    3. Attributes (Annotations)

    PHP 8 introduces attributes (also known as annotations in other languages), which allow developers to add metadata to classes, methods, and properties. This is done through a new syntax using the #[Attribute] notation.


    #[Route('/api', methods: ['GET'])] public function getApiData() { // Method implementation }

    Attributes provide a cleaner and more powerful alternative to PHPDoc comments and can be utilized by frameworks and libraries to configure behaviors and settings.

    4. Constructor Property Promotion

    Constructor Property Promotion simplifies the syntax for creating and initializing properties in a class constructor. Instead of writing repetitive code, you can now declare and initialize properties in one line.


    class User { public function __construct( private string $name, private int $age ) {} }

    This feature reduces boilerplate code and makes class definitions more concise and readable.

    5. Match Expressions

    PHP 8 introduces the match expression, a more powerful and flexible alternative to the switch statement. It supports strict type comparisons and can return values.


    $result = match ($status) { 'success' => 'Operation was successful', 'error' => 'There was an error', default => 'Unknown status', };

    match expressions offer better readability and control compared to traditional switch statements.

    6. Nullsafe Operator

    The nullsafe operator ?-> simplifies dealing with null values by allowing method calls and property accesses to be safely chained. If the left-hand side of the operator is null, the entire expression evaluates to null


    $user = $userRepository->find($id)?->getProfile()?->getName();

    This feature helps avoid unnecessary null checks and makes the code cleaner and more concise.