开发手册 欢迎您!
软件开发者资料库

CSS - 边距

CSS边距 - 面向初学者和高级开发人员的CSS教程使用示例,通过简单而简单的步骤学习层叠样式表。 CSS2和CSS3属性的完整参考手册。

margin 属性定义HTML元素周围的空间.可以使用负值来重叠内容.

子元素不会继承margin属性的值.请记住,相邻的垂直边距(顶部和底部边距)将相互折叠,使得块之间的距离不是边距的总和,而是仅两个边距中的较大者或者如果两者都是一个边距的相同尺寸等于.

我们有以下属性来设置元素边距.

  • 边距指定一个简写属性,用于在一个声明中设置边距属性.

  • margin-bottom 指定元素的下边距.

  • margin-top 指定元素的上边距.

  • margin-left 指定元素的左边距.

  • margin-right 指定元素的右边距.

现在,我们将看到如何将这些属性与示例一起使用.

保证金属性

保证金属性允许您设置所有专业人员在一个声明中涉及四个边际.以下是围绕段落设置边距的语法;

这是一个示例 :

                           all four margins will be 15px      

                     top and bottom margin will be 10px, left and right margin will be 2%          of the total width of the document.      

                     top margin will be 10px, left and right margin will be 2% of the          total width of the document, bottom margin will be -10px      

                     top margin will be 10px, right margin will be 2% of the total          width of the document, bottom margin will be -10px, left margin          will be set by the browser      

   

The margin-bottom Property

margin-bottom属性允许您设置元素的下边距。 它可以有一个长度值,%或auto。

这是一个例子:

                        This is a paragraph with a specified bottom margin      

                     This is another paragraph with a specified bottom margin in percent      

   

The margin-top Property

margin-top属性允许您设置元素的上边距。 它可以有一个长度值,%或auto。

这是一个例子: 

                        This is a paragraph with a specified top margin      

                     This is another paragraph with a specified top margin in percent      

   

The margin-left Property

margin-left属性允许您设置元素的左边距。 它可以有一个长度值,%或auto。

这是一个例子:

 

                        This is a paragraph with a specified left margin      

                     This is another paragraph with a specified top margin in percent      

   

The margin-right Property

margin-right属性允许您设置元素的右边距。 它可以有一个长度值,%或auto。

这是一个例子:

                           This is a paragraph with a specified right margin      

               This is another paragraph with a specified right margin in percent