How to give border to any element using css without adding border-width to the whole width of element?

前端 未结 11 1900
礼貌的吻别
礼貌的吻别 2020-12-02 10:19

How to give border to any element using css without adding border-width to the whole width of element?

Like in Photoshop we can give stroke- Inside , center and out

11条回答
  •  生来不讨喜
    2020-12-02 10:55

    As abenson said, you can use an outline but one gotcha is that Opera might draw a "non-rectangular shape". Another option that seems to work is to use negative margins, such as this css:

    div {
      float:left;
      width: 50%;
      border:1px solid black;
      margin: -1px;
    
    }
    

    With this html:

    
      
    A block
    Another block

    One other less clean option is to add extra markup to the html. For example, you set the width of an outer element and add the border to the inner one. The CSS:

    .outer { width: 50%; float: left;}
    .inner { border: 1px solid black; }
    

    And the html:

    
      
    A block
    Another block

提交回复
热议问题