2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
1. Use border to draw a trapezoid (the content needs to be absolutely positioned)
HTML:
- //左边斜边
- <div class="t">
- <div class="f"></div>
- </div>
- //右边斜边
- <div class="t2">
- <div class="f"></div>
- </div>
CSS:
- .t{
- position: relative;
- width: 277.5px;
- height: 35px;
- border-right: 19px solid transparent;
- border-bottom: 35px solid #4B75FF;
- }
-
- .f{
- position: absolute;
- bottom: 0;
- }
- .t2{
- position: relative;
- width: 277.5px;
- height: 35px;
- border-left: 19px solid transparent;
- border-top: 35px solid #4B75FF;
- }
result:
2. Use clip-path to draw a trapezoid
HTML:
- <div class="card-info_s3-bottom_cc_left">
- </div>
CSS:
- .card-info_s3-bottom_cc_left{
- display: flex;
- flex-direction: row;
- justify-content: flex-start;
- align-items: center;
- font-size: 13px;
- color: #ffffff;
- width: 277.5px;
- height: 35px;
- padding-left: 26px;
- clip-path:polygon(0 0,258.5px 0px,277.5px 35px,0px 35px);
- background-color: #4B75FF;
- border-bottom-left-radius: 12px;
- border-top-right-radius: 30px;
- }
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.