- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS Data Type - <position>
CSS datatype <position> represents a positioning behavior of an HTML element within its containing element. It is used to set a location relative to an element box or another element.
<position> is used with background-position for background images, object-position, mask-position, offset-position, offset-anchor, and transform-origin.
Following diagram depicts all the positions of an element:
One or two keywords and optional offsets are used to specify the <position> data type in CSS.
The terms center, top, right, bottom, and left are accessible. These keywords match the center lines or outside boundaries of the box of an element.
The middle term can indicate either the midpoint between the top and bottom edges or the midpoint between the left and right sides, depending on the context.
The <position> data type allows for the expression of offsets as either absolute <length> values or relative <percentage> values.
Negative values cause the element to move in the opposite direction from positive values, which causes it to move to the right or bottom. The x-coordinate is determined if only one offset is given; the value for the other axis defaults to the center.
Syntax
<position> = [ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right ] && [ top | center | bottom ] | [ left | center | right | >length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ]
CSS <position> - Valid Positions
center
left
center top
right 5.5%
bottom 15vmin right -3px
15% 25%
4rem 22px
CSS <position> - Invalid Positions
left right
bottom top
10px 15px 20px 15px
CSS <position> - Relative Position
The following example demonstrates the use of <position> data type in the CSS property background-position, where the values passed are relative i.e. center and left. The linear gradient is placed at the center-left of the page.
<html> <head> <style> body { height: 200px; background-color: #222; background-image: radial-gradient(circle at center, red, green 3em); background-size: 15em 10em, 30% 70%, 100px 70px; background-position: center left; background-repeat: no-repeat no-repeat; } </style> </head> <body> </body> </html>
CSS <position> - Absolute Position
The following example demonstrates the use of <position> data type in the CSS property position, along with other properties such as top, left, right, and bottom, where the values passed are relative and absolute.
<html> <head> <style> .container { position: relative; border: 2px solid #ef2c2c; } .center { position: absolute; top: 45%; width: 100%; text-align: center; } .top-left { position: absolute; top: 12px; left: 30px; } .top-right { position: absolute; top: 12px; right: 30px; } .bottom-left { position: absolute; bottom: 12px; left: 30px; } .bottom-right { position: absolute; bottom: 12px; right: 30px; } img { width: 100%; opacity: 0.3; } </style> </head> <body> <div class="container"> <img src="images/red-flower.jpg" alt="abc" width="1000px" height="350px"> <h3 class="center">Text at Centered</h3> <h3 class="top-left">Text at Top Left</h3> <h3 class="top-right">Text at Top Right</h3> <h3 class="bottom-left">Text at Bottom Left</h3> <h3 class="bottom-right">Text at Bottom Right</h3> </div> </body> </html>
CSS <position> - Fixed Position
The following example demonstrates the use of <position> data type in the CSS property position where the value passed is fixed.
<html> <head> <style> .position_container { width: 400px; height: 200px; background-color: #f2c3ee; overflow: auto; padding: 5px; } .fixed-position { position: fixed; top: 15px; left: 60px; padding: 5px; background-color: #bbedbb; text-align: center; } </style> </head> <body> <div class="position_container"> <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p class="fixed-position">Tutorialspoint CSS Position Fixed</p> <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </div> </body> </html>