Coding Schools


 
Python | C Sharp | Azure AI | HTML | JavaScript | CSS | SQL Server
How to add CSS in HTML
Types of CSS Files
Flex in CSS
Media Query in CSS
CSS - background attribute
CSS - border
css - border-image
CSS align attributes
CSS color attribute
CSS cursor attribute
CSS display attribute
CSS font attributes
CSS height and max-height
CSS width and max-width
CSS padding attributes
CSS margin attributes
CSS mask attributes
CSS overflow attributes
CSS opacity attribute
CSS text decoration attributes
CSS visibility attribute
CSS word attributes
CSS z-index attribute

CSS display attribute



The display property in CSS is used to control the layout behavior of an element. It specifies how an element should be displayed in the document. Here are the most common values for the display property:

Common display Values

  • block: The element is displayed as a block element (like a <div>) and takes up the full width available.

    css
    .block {
        display: block;
    }
    
  • inline: The element is displayed as an inline element (like a <span>) and only takes up as much width as necessary.

    css
    .inline {
        display: inline;
    }
    
  • inline-block: The element is displayed as an inline element, but it behaves like a block element (allowing width and height to be set).

    css
    .inline-block {
        display: inline-block;
    }
    
  • none: The element is not displayed at all (it is hidden from the layout).

    css
    .none {
        display: none;
    }
    
  • flex: The element becomes a flex container, enabling the use of the Flexbox layout model.

    css
    .flex {
        display: flex;
    }
    
  • grid: The element becomes a grid container, enabling the use of the Grid layout model.

    css
    .grid {
        display: grid;
    }
    

Example

Here is an example of how these values might be used in CSS:

css
/* Block element */
.block {
    display: block;
}

/* Inline element */
.inline {
    display: inline;
}

/* Inline-block element */
.inline-block {
    display: inline-block;
}

/* Flex container */
.flex {
    display: flex;
}

/* Grid container */
.grid {
    display: grid;
}

Each value of the display property is used for different layout scenarios, depending on how you want your elements to behave. Let me know if you need any more details or examples!




All rights reserved | Privacy Policy | Sitemap