MyBlogHelp– A Blog for Digital Marketing, Affiliate Marketing, Organic Lead Generation.
  • Home
  • About
  • Contact
  • Privacy
  • Sitemap
  • BLOG
  • AFFILIATE MARKETING
    • LeadsArk
  • MORE
    • MAKE MONEY
      • ONLINE BUSINESS
      • ADSENSE
      • AFFILIATE MARKETING
    • BLOGGING
      • SEO
      • BlogSpot
      • WORPRESS
      • GOOGLE
      • COMPUTER TIPS
    • WEB DESIGN
      • HTML
      • CSS
      • BOOTSTRAP
      • JAVASCRIPT
      • JQUERY
    • WEB DESIGN
      • HTML
      • CSS
      • BOOTSTRAP
      • JAVASCRIPT
      • JQUERY
    • WEB DEVELOPMENT
      • PHP
      • WORDPRESS
  • DOWNLOADS
    • Blogger Template
    • Wordpress Theme
    • PDF

Monday, April 8, 2019

How to use css display property? CSS Tutorial 12

 MyBlogHelp     April 08, 2019     css     1 comment   

How-to-use-css-display-property

 

  CSS DisplayProperty

  1. Introduction to CSS display properties
  2. Value of CSS display property
  3. Example of CSS display property

Introduction to CSS Display Property

CSS provides you display property to control the display of HTML elements. Depending on the different values of this property, you can control the display of elements in many ways.

When you create a large web application, sometimes you need to control the display of some elements. There can have several reasons for this. For example, you want to show the same element that belongs to the content or to that particular page.

If you want to display elements that are not related to the content of a particular webpage then this will create a bad user experience. Whatever the reason, but all the web developers need to control the display of elements for good user experience.

Values of CSS Display Property

Some values of CSS display property have been given below.
  • inline
  • block
  • inline-block
  • list-item
  • table
  • none
  • initial
  • inherit
The general syntax of the display property has been given below.

                  display: value;

The default value of this property is inline.

Example of CSS display property

Now you can learn about each value of the display property with a simple example.

inline value of CSS display property

This is the default property of CSS display property. Elements from this "inline" value are displayed in the same line as an inline element. An example of this inline value of the display property has been given below.

<!DOCTYPE html>
<html>
<head>
   <style>
        div {
            display: inline;
            color: blue;
            }
    </style>
</head>
<body>
      <div> This is first div element. </div>
      <div> This is second div element. </div>
      <img src = "image1.jpg" width = "50px" height = "50px"> </img>
      <img src = "image2.jpg" width = "50px" height = "50px"> </img>
</body>
</html>

The above script will generate the below output.


CSS-display-inline-example

block value of CSS display property

When the value “block” of the CSS display property is defined, the elements are shown differently as block elements.

For example, when you create many links, all the links are shown in the same line. But if you want to show these links in different lines, you can do this by defining the display property with block value. By doing this, all links will be shown in different lines as block elements. An example of this display block value has been given below.


<!DOCTYPE html>
<html>
<head>
   <style>
           a {
            display: block;
            }
   </style>
</head>
<body>
     <a href=""> This is the First Link </a>
     <a href=""> This is the Second Link </a>
     <a href=""> This is the Third Link </a>
</body>
</html>

The above script will generate the below output.


CSS-display-block-example

inline-block value of CSS display property

Elements with this inline-block value show in the same line as inline elements but they are the block container.

For example, whenever a div element is created, the line break automatically adds to it before and after. But through this value, you can show many divs in the same line by override this behaviour. An example of this inline-block value has been given below.


<!DOCTYPE html>
<html>
<head>
   <style>
          div {
              display: inline-block;
              }
   </style>
</head>
<body>
       <div> This is Div1. </div>
       <div> This is Div2. </div>
       <div> This is Div3. </div>
       <div> This is Div4. </div>
</body>
</html>

The above script will show the below output.


CSS-display-inline-block-example

list-item value of CSS display property

From this value, the element is shown as the item of a list. For example, if you want to show span elements as a list on the web page, then list item value of the display property can be used. An example of this list-item has been given below.


<!DOCTYPE html>
<html>
<head>
   <style>
         span {
               color: blue;
               display: list-item;
               }
   </style>
</head>
<body>
   <span> LIST-ITEM ONE </span> <span> LIST-ITEM TWO </span> <span> LIST-ITEM THREE </span>
</body>
</html>

The above script generates the given output below.


CSS-display-list-item-example

table value of CSS display property

This value shows the element like a table. An example of a CSS display table value has been given below.


<!DOCTYPE html>
<html>
<head>
   <style>
         span {
             display: table;
              }
   </style>
</head>
<body>
      <span> ONE </span> <span> TWO </span> <span> THREE </span>
</body>
</html>

The above script will generate the below output.

CSS-display-table-example

none value of CSS display property

This value does not display element. This does not make any difference to the rest of the webpage designing. For example, if you want to hide all the divs on the web page, then such can be done by CSS display none value.
An example of this has been given below.


<!DOCTYPE html>
<html>
<head>
    <style>
          div {
               display: none;
               }
     </style>
</head>
<body>
      <div> This will not div div. </div>
</body>
</html>

The initial value of CSS display 

This display initial value sets the default value of display property. An example of this has been given below.


<!DOCTYPE html>
<html>
<head>
     <style>
        div {
            display: initial;
            }
     </style>
</head>
<body>
     <div> FIRST ITEM </div> <img src = "image.jpg" width="100px" height="40px"> </img>
</body>
</html>

The above script will generate the below output.

CSS-display-initial-example

The inherit value of CSS display

When you set the "inherit" value of display property, the value of this property is taken from the parent element. An example of this has been given below.


<!DOCTYPE html>
<html>
<head>
 <style>
        div {
               display: list-item;
               }
         span {
               display: inherit;
               }
 </style>
</head>
<body>
     <div>
         <span> FIRST ITEM </span> <span> SECOND ITEM </span> <span> THIRD ITEM </span>
     </div>
</body>
</html>

The above script will generate the below output.


CSS-display-inherit-example



        <<-- PREVIOUS                                                                  NEXT -->>



  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

1 comment:

  1. AnonymousJune 16, 2019 at 9:00 PM

    Hello there, just became alert to your blog through Google, and found that it's truly informative.
    I?m going to watch out for brussels. I?ll be grateful if you continue
    this in future. A lot of people will be benefited from your writing.
    Cheers!

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Thank you for reading this post. Please do not enter any spam link in the comment box.

Followers

Blog Archive

  • ►  2020 (4)
    • ►  October (1)
    • ►  September (1)
    • ►  August (2)
  • ▼  2019 (52)
    • ►  December (1)
    • ►  November (2)
    • ►  October (1)
    • ►  August (1)
    • ►  July (1)
    • ►  May (11)
    • ▼  April (10)
      • How to use css box-shadow property? CSS Tutorial 19
      • How to use css z-index property? CSS Tutorial 18
      • How to use css outline property? CSS Tutorial 17
      • How to use css attribute selector? CSS Tutorial 16
      • How to use the css float property? CSS Tutorial 15
      • How to use the css visibility property? CSS Tutori...
      • How to use css cursor property? CSS Tutorial 13
      • How to use css display property? CSS Tutorial 12
      • How to use css position property? CSS Tutorial 11
      • How to use css overflow property? CSS Tutorial 10
    • ►  March (6)
    • ►  February (3)
    • ►  January (16)
  • ►  2018 (54)
    • ►  December (27)
    • ►  November (5)
    • ►  May (5)
    • ►  April (4)
    • ►  February (3)
    • ►  January (10)
  • ►  2017 (17)
    • ►  December (9)
    • ►  November (8)

Popular Posts

  • How to use the main tag in html5?
  • How to use keygen tag in html5?
  • How to use html5 mark tag to highlight text?
  • How to start Online Business without money from home?
  • What is a search engine?

Contact Us

Name

Email *

Message *

About MyBlogHelp

Most of the posts, we share on this blog related to Affiliate Marketing, Organic Lead Generation, Digital Marketing, Social Media Marketing, Make Money Online, SEO, and web design.

Featured Post

LeadArk - Affiliate Marketing | Qualified Organic Lead Generation | LeadsArk Review

Copyright © MyBlogHelp– A Blog for Digital Marketing, Affiliate Marketing, Organic Lead Generation.
Design by Md. Abdussamad | MyBlogHelp.com