zoukankan      html  css  js  c++  java
  • CSS 边框的宽度

    边框的宽度

    您可以通过 border-width 属性为边框指定宽度。

    为边框指定宽度有两种方法:可以指定长度值,比如 2px 或 0.1em;或者使用 3 个关键字之一,它们分别是 thin 、medium(默认值) 和 thick。

    注释:CSS 没有定义 3 个关键字的具体宽度,所以一个用户代理可能把 thin 、medium 和 thick 分别设置为等于 5px、3px 和 2px,而另一个用户代理则分别设置为 3px、2px 和 1px。

    所以,我们可以这样设置边框的宽度:

    p {border-style: solid; border- 5px;}

    或者:

    p {border-style: solid; border- thick;}

    定义单边宽度 怎么理解

    您可以按照 top-right-bottom-left 的顺序设置元素的各边边框:

    p {border-style: solid; border- 15px 5px 15px 5px;}

    上面的例子也可以简写为(这样写法称为值复制):

    p {border-style: solid; border- 15px 5px;}

    您也可以通过下列属性分别设置边框各边的宽度:

    • border-top-width
    • border-right-width
    • border-bottom-width
    • border-left-width

    因此,下面的规则与上面的例子是等价的:

    p {
      border-style: solid;
      border-top- 15px;
      border-right- 5px;
      border-bottom- 15px;
      border-left- 5px;
      }

    没有边框

    在前面的例子中,您已经看到,如果希望显示某种边框,就必须设置边框样式,比如 solid 或 outset。

    那么如果把 border-style 设置为 none 会出现什么情况:

    p {border-style: none; border- 50px;}

    尽管边框的宽度是 50px,但是边框样式设置为 none。在这种情况下,不仅边框的样式没有了,其宽度也会变成 0。边框消失了,为什么呢?

    这是因为如果边框样式为 none,即边框根本不存在,那么边框就不可能有宽度,因此边框宽度自动设置为 0,而不论您原先定义的是什么。

    记住这一点非常重要。事实上,忘记声明边框样式是一个常犯的错误。根据以下规则,所有 h1 元素都不会有任何边框,更不用说 20 像素宽了:

    h1 {border- 20px;}

    由于 border-style 的默认值是 none,如果没有声明样式,就相当于 border-style: none。因此,如果您希望边框出现,就必须声明一个边框样式。

  • 相关阅读:
    最大子数组问题(分治策略实现)
    Solving the Detached Many-to-Many Problem with the Entity Framework
    Working With Entity Framework Detached Objects
    Attaching detached POCO to EF DbContext
    如何获取qq空间最近访问人列表
    Health Monitoring in ASP.NET 2.0
    problem with displaying the markers on Google maps
    WebMatrix Database.Open… Close() and Dispose()
    Accessing and Updating Data in ASP.NET: Retrieving XML Data with XmlDataSource Control
    Create web setup project that has crystal reports and sql script run manually on client system
  • 原文地址:https://www.cnblogs.com/asds/p/6217867.html
Copyright © 2011-2022 走看看