CSS Display Property – Deep dive in block | inline | inline-block
![CSS Display property](https://www.jsmount.com/wp-content/uploads/2023/11/css-display-732x519.png)
CSS Display Property
👉 Display property defines how an element will render into a page.
Let’s first see all possible values of the display property.
Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/display
/* precomposed values */
display: block;
display: inline;
display: inline-block;
display: flex;
display: inline-flex;
display: grid;
display: inline-grid;
display: flow-root;
/* box generation */
display: none;
display: contents;
/* multi-keyword syntax */
display: block flow;
display: inline flow;
display: inline flow-root;
display: block flex;
display: inline flex;
display: block grid;
display: inline grid;
display: block flow-root;
/* other values */
display: table;
display: table-row; /* all table elements have an equivalent CSS display value */
display: list-item;
/* Global values */
display: inherit;
display: initial;
display: revert;
display: revert-layer;
display: unset;
💡In this article, we will see all the details of block, inline, and inline-block values.
block property
display: block;
Line break – block creates line break before and after the element.
New Element – A new element comes to the next line.
Height – User-defined height works here.
Width – User-defined width works here.
Margin – Works in all directions.
Padding – Works in all directions.
Border – Works in all directions.
.block {
display: block;
/* height, width, padding ,margin, border */
background-color: lightblue;
/* user defined height : works */
height: 100px;
/* user defined width : works */
width: 100px;
/* padding works */
padding-top: 10px;
padding-bottom: 10px;
padding-left: 10px;
padding-right: 10px;
/* margin works */
margin-top: 10px;
margin-left: 20px;
/* border works */
border-top: 2px solid red;
border-left: 2px solid red;
}
inline property
display: inline;
Line break – inline does not create line break before and after the element.
New Element – A new element comes just next to the current element.
Height – User-defined height does not work here.
Width – User-defined width does not work here.
Margin – Works in only a Horizontal direction & does not work in the vertical direction.
Padding – Works in all directions.
Border – Works in all directions.
.inline {
display: inline;
background-color: lightgreen;
/* user defined height : does not work */
height: 100px;
/* user defined width : does not work */
width: 100px;
/* padding works */
padding-top: 30px;
padding-left: 30px;
padding-bottom: 40px;
padding-right: 10px;
/* margin works in horizontal*/
margin-left: 10px;
margin-right: 10px;
/* margin does not work in vertical direction */
margin-top: 10px;
/* border -> works*/
border-top: 2px solid red;
border-left: 2px solid red;
}
inline block property
display: inline-block;
Line break – inline-block does not create line break before and after the element.
New Element – A new element comes just next to the current element.
Height – User-defined height works here.
Width – User-defined width works here.
Margin – Works in only a Horizontal direction & does not work in the vertical direction.
Padding – Works in all directions.
Border – Works in all directions.
.inline_block {
display: inline-block;
background-color: mediumorchid;
/* user defined height : does not work */
height: 100px;
/* user defined width : does not work */
width: 100px;
/* padding works */
padding-top: 30px;
padding-left: 30px;
/* margin works in horizontal only*/
margin-left: 10px;
margin-right: 20px;
/* margin does not work in vertical direction */
margin-top: 10px;
margin-bottom: 30px;
/* border -> works*/
border-top: 2px solid red;
border-left: 2px solid red;
}
- Unlocking the Secrets of Cookie | Power Your Web Experience
- AI vs Human: Exploring the Boundaries of Intelligence
- Enhancing User Experience with JavaScript Throttle and Debounce
- JavaScript Custom Promise | Promise Polyfill
- JavaScript Promisify | Convert Callbacks to Promises
- JavaScript Promise and Callbacks | Everything You Must Know
- CSS Display Property – Deep dive in block | inline | inline-block
- Implementation of Queue using Linked List | JavaScript
- Insert node in Linked list | Algorithm | JavaScript
- Insertion Sort in data structure | Algorithm with Examples
- Selection Sort Algorithm & K’th Largest Element in Array
- Quick Sort Algorithm with example | Step-by-Step Guide
- Dependency Inversion Principle with Example | Solid Principles
- Object-Oriented Programming | Solid Principles with Examples
- ASCII Code of Characters | String Operations with ASCII Code
- Negative Binary Numbers & 2’s Complement | Easy explanation
- Factors of a Number | JavaScript Program | Optimized Way
- LeetCode – Game of Life Problem | Solution with JavaScript
- Fibonacci series using Recursion | While loop | ES6 Generator
- JavaScript Coding Interview Question & Answers
- LeetCode – Coin Change Problem | Dynamic Programming | JavaScript
- HackerRank Dictionaries and Maps Problem | Solution with JavaScript
- React Redux Unit Testing of Actions, Reducers, Middleware & Store
- Micro frontends with Module Federation in React Application
- React Interview Question & Answers – Mastering React
- Top React Interview Question & Answer | React Routing
- React Interview Questions and Answers | React hooks
- Higher Order Component with Functional Component | React JS
- Top React Interview Questions and Answers | Must Know
- Interview Question React | Basics for Freshers and Seniors
- Cyber Security Fundamental Questions & Answers You must know
- Application & Web Security Interview Questions & Answers
- Top Scrum Master and Agile Question & Answers 2022
- Trapping Rain Water Leetcode Problem Solution
- Array Representation of Binary Tree | Full Tree & Complete Binary Tree
- Graphs in Data Structure, Types & Traversal with BFS and DFS, Algorithms
- Traversing 2 D array with BFS & DFS Algorithm in JavaScript
- Time Complexity & Calculations | All You should know
- Backspace String Compare Leetcode Problem & Solution
- Angular Interview Questions & Answers 2021 – Part 3 – JS Mount
- Why Angular is a Preferred Choice for Developers? Top Features
- Angular Interview Questions & Answers You should know Part 2
- Top 30 JavaScript Interview Questions and Answers for 2021
- React JS Stripe Payment Gateway Integration with Node | Step by Step Guide
- Create Year Month & Date dropdown List using JavaScript & JQuery
- Create Custom QR Code Component using QR Code Styling in React JS
- How to create a common Helper class or util file in React JS
- React Build Routing with Fixed Header and Navigation | React Router Tutorial
- React Create Dashboard Layout with Side Menu, Header & Content Area
- Web Application Security Best Practices | Top Tips to Secure Angular App
CSS Display Property