Half circle with CSS (border, outline only)

前端 未结 4 705
抹茶落季
抹茶落季 2020-12-01 03:28

I\'m trying to create a circle with CSS, which looks exactly like on the following picture:

\"enter

4条回答
  •  情深已故
    2020-12-01 04:07

    You could use border-top-left-radius and border-top-right-radius properties to round the corners on the box according to the box's height (and added borders).

    Then add a border to top/right/left sides of the box to achieve the effect.

    Here you go:

    .half-circle {
        width: 200px;
        height: 100px; /* as the half of the width */
        background-color: gold;
        border-top-left-radius: 110px;  /* 100px of height + 10px of border */
        border-top-right-radius: 110px; /* 100px of height + 10px of border */
        border: 10px solid gray;
        border-bottom: 0;
    }
    

    WORKING DEMO.

    Alternatively, you could add box-sizing: border-box to the box in order to calculate the width/height of the box including borders and padding.

    .half-circle {
        width: 200px;
        height: 100px; /* as the half of the width */
        border-top-left-radius: 100px;
        border-top-right-radius: 100px;
        border: 10px solid gray;
        border-bottom: 0;
    
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    

    UPDATED DEMO. (Demo without background color)

提交回复
热议问题