Technology Sharing

CSS Shaped Graphics

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. Use border to draw a trapezoid (the content needs to be absolutely positioned)

HTML:

  1. //左边斜边
  2. <div class="t">
  3. <div class="f"></div>
  4. </div>
  5. //右边斜边
  6. <div class="t2">
  7. <div class="f"></div>
  8. </div>

CSS:

  1. .t{
  2. position: relative;
  3. width: 277.5px;
  4. height: 35px;
  5. border-right: 19px solid transparent;
  6. border-bottom: 35px solid #4B75FF;
  7. }
  8. .f{
  9. position: absolute;
  10. bottom: 0;
  11. }
  12. .t2{
  13. position: relative;
  14. width: 277.5px;
  15. height: 35px;
  16. border-left: 19px solid transparent;
  17. border-top: 35px solid #4B75FF;
  18. }

result:

2. Use clip-path to draw a trapezoid

HTML:

  1. <div class="card-info_s3-bottom_cc_left">
  2. </div>

CSS:

  1. .card-info_s3-bottom_cc_left{
  2. display: flex;
  3. flex-direction: row;
  4. justify-content: flex-start;
  5. align-items: center;
  6. font-size: 13px;
  7. color: #ffffff;
  8. width: 277.5px;
  9. height: 35px;
  10. padding-left: 26px;
  11. clip-path:polygon(0 0,258.5px 0px,277.5px 35px,0px 35px);
  12. background-color: #4B75FF;
  13. border-bottom-left-radius: 12px;
  14. border-top-right-radius: 30px;
  15. }

result:

Extension: clip-path

The clip-path property is used to define the clipping area of ​​an element to control which parts are visible and which parts are hidden. It allows you to use different functions and parameters to create complex clipping shapes. In CSS, the clip-path property can use different functions to define the clipping area. Common functions are as follows:

1. circle(): Creates a circular clipping area. The parameters are the radius and the coordinates of the center of the circle.
2. ellipse(): Creates an elliptical cropping area. The parameters are the radius of the horizontal and vertical axes and the coordinates of the center of the circle.
3. polygon(): Creates a polygonal clipping region. The parameters are the coordinates of the vertices that make up the polygon.
4. path(): Use an SVG path to define the clipping area. The parameter is a string representation of the path.