css-box

setting width,height,boeder,padding and margin of boxes

width

height

Box heights don’t observe percentage lengths; box height always adopts the height of the box content, unless a specific absolute height is set (e.g. pixels or ems.) This is more convenient than the height of every box on your page defaulting to 100% of the viewport height.

Advanced box manipulation

overflow

When you set the size of a box with absolute values (e.g. a fixed pixel width/height), the content may not fit within the allowed size, in which case the content overflows the box. To control what happens in such cases, we can use the overflow property. It takes several possible values, but the most common are:

  • auto: If there is too much content, the overflowing content is hidden and scroll bars are shown to let the user scroll to see all the content.
  • hidden: If there is too much content, the overflowing content is hidden.
  • visible: If there is too much content, the overflowing content is shown outside of the box (this is usually the default behavior.)

background-clip

Box backgrounds are made up of colors and images, stacked on top of each other (background-color, background-image.)

  • border-box:display the border padding and content
  • padding-box:display the padding and content
  • content-box:display the content only

Outline

Last but not least, the outline of a box is something that looks like a border but which is not part of the box model. It behaves like the border but is drawn on top of the box without changing the size of the box (to be specific, the outline is drawn outside the border box, inside the margin area.)

Types of CSS boxes

  • inline
  • block
  • inline-block

猜你喜欢

转载自blog.csdn.net/tinpo_123/article/details/83758831
今日推荐