• We just launched and are currently in beta. Join us as we build and grow the community.

Display

profitnet2k

Tactical Genius
P Rep
0
0
0
Rep
0
P Vouches
0
0
0
Vouches
0
Posts
110
Likes
142
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Introduction:
This is the seventh part in my CSS Styling tutorials, in which I will be covering display.

What is Display?
Display is a property which sets the type of behaviour that will be given in relation to the position of the given elements.

Structure:
display: {type};

Example:
  1. display

    :

    inline-block

    ;

Defaults:
As a couple of default examples; an image given through an img tag in HTMl is a block element, a paragraph (p) is a block element and a span is an inline-block element.

Values:
The bigger the border radius, the more curved the border will be.

inline - Displays an element as an inline element (like )
block - Displays an element as a block element (like )
inline-block - Displays an element as an inline-level block container. The inside of this block is formatted as block-level box, and the element itself is formatted as an inline-level box
inline-table - The element is displayed as an inline-level table
list-item - Let the element behave like a [*]element
run-in - Displays an element as either block or inline, depending on context
table - Let the element behave like a

element
table-caption - Let the element behave like a element
table-column-group - Let the element behave like a element
table-header-group - Let the element behave like a element
table-footer-group - Let the element behave like a

element
table-row-group - Let the element behave like a

element
table-cell - Let the element behave like a element
table-column - Let the element behave like a

element
table-row - Let the element behave like a

element
none - The element will not be displayed at all (has no effect on layout)
inherit - The value of the display property will be inherited from the parent element

Linking CSS To a HTML Element:
To link your CSS to an HTML element (text, div, etc.) you will need to decide whether you want to use a class or id, you will also need a unique name. Once you have those, go to your element in HTML and add...

  1. class=

    'myClass'

... to the attributes of that element if you chose a class, or...

  1. id=

    'myID'

if you chose an id.

Make sure you replace 'myClass' and/or 'myID' with your unique name. Then, in the CSS you will want to encase your properties with...

  1. .myClass

    {
  2. //Properties go here
  3. }

if you chose a class, or...

  1. #myID

    {
  2. //Properties go here
  3. }

(You can remove the line beginning with // if you wish).

Here's an example...

  1. <html>
  2. <head>
  3. <style>
  4. .inline

    {
  5. background-color

    :

    #000

    ;
  6. color

    :

    #fff

    ;
  7. width

    :

    300px

    ;
  8. height

    :

    100px

    ;
  9. display

    :

    inline

    ;
  10. //Will position next to other elements
  11. }

  12. .inlineblock

    {
  13. background-color

    :

    #000

    ;
  14. color

    :

    #fff

    ;
  15. width

    :

    300px

    ;
  16. height

    :

    100px

    ;
  17. display

    :

    inline-block

    ;
  18. // Will position aligned to other elements
  19. }

  20. .block

    {
  21. background-color

    :

    #000

    ;
  22. color

    :

    #fff

    ;
  23. width

    :

    300px

    ;
  24. height

    :

    100px

    ;
  25. display

    :

    block

    ;
  26. // Will take up

    the full line
  27. }

  28. .none

    {
  29. background-color

    :

    #000

    ;
  30. color

    :

    #fff

    ;
  31. width

    :

    300px

    ;
  32. height

    :

    100px

    ;
  33. display

    :

    none

    ;
  34. // Will not

    display
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div class=

    'inline'

    >

    Inline</div>
  40. <div class=

    'inlineblock'

    >

    Inline Block</div>
  41. <div class=

    'block'

    >

    Block</div>
  42. <div class=

    'none'

    >

    None</div>
  43. </body>
  44. </html>

Book traversal links for Display

  • ‹ CSS Tutorial - Part 1 - Types
  • Up
  • Float and Clear ›

 

442,401

317,942

317,951

Top