Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS right Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 14 - Views
⏳ 4 mins
💬 1 Comment
CSS right Property

Photo Credit to CodeToFun

🙋 Introduction

The right property in CSS is used to position an element horizontally from the right edge of its containing block. It is commonly used in conjunction with the position property when absolute, relative, fixed, or sticky positioning is applied.

By using the right property, you can precisely control the horizontal placement of an element in a flexible and responsive manner.

💡 Syntax

The syntax for the right property is as follows:

Syntax
Copied
Copy To Clipboard
element {
  right: value;
}

🎛️ Default Value

The default value of the right property is auto, which means the element is not offset horizontally and follows the normal flow of the document.

🏠 Property Values

ValueDescription
autoThe browser calculates the right position.
lengthSpecifies a fixed right position in units like px, em, rem, etc.
percentageSpecifies the right position as a percentage of the containing block's width.
initialSets the property to its default value.
inheritInherits the property from its parent element.

📄 Example

In this example, we'll position a box 20 pixels from the right edge of its containing block.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS right Property Example</title>
  <style>
    .container {
      position: relative;
      width: 100%;
      height: 200px;
      background-color: lightgray;
    }
    .box {
      position: absolute;
      right: 20px;
      width: 100px;
      height: 100px;
      background-color: blue;
    }
  </style>
</head>
<body>
  <h1>Box Positioned with CSS right Property</h1>
  <div class="container">
    <div class="box"></div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The right property is widely supported across all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It has also been supported in older versions of Internet Explorer. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The right property is a valuable tool for web developers looking to precisely control the horizontal positioning of elements within a container.

By understanding and utilizing this property, you can create more flexible and responsive layouts. Experiment with different values and see how the right property can enhance the positioning of elements in your web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy