P粉7040660872023-09-03 10:54:57
First some terminology: We call the width of the area covered by the top and bottom of an SVG shape the "right minimum", and the width covered in the middle the "right maximum".
The way I understand your question is that the right area a) has a constant width and b) should always show the full SVG shape. It follows that it must have a constant height and an aspect ratio of 708:1056. This makes it easy to calculate the required dimensions, most importantly the ratio between the minimum on the right and the maximum on the right is 564 : 708.
Now, I would suggest to solve your problem by moving the left image as background image to an outer container element with a width that ensures it is below the curved part, ie. e. 100% minus 564px (or fixed fraction). The left container element containing the promotional content has a width of 100% minus 708px, and the right container has a width of 708px (or a fixed fraction). (For simplicity, containers are identified by class names that match their component names)
.container {
display: flex;
flex-direction: row;
justify-items: stretch;
align-items: stretch;
height: 523px;
background-image: linear-gradient(360deg, white, red);
background-position: top right 282px;
background-size: cover;
background-repeat: no-repeat;
}
.container-left {
flex-grow: 1;
}
.container-right {
width: 354px;
background-image: url('data:image/svg+xml,<svg viewBox="0 0 708 1056" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M144.5 0H799.5V1056H144.5L23.4254 775.169C0.402533 721.768 -5.09917 662.442 7.71089 605.718L144.5 0Z" fill="%2316979A"/></svg>');
background-size: 100% 100%;
}
.child {
box-sizing: border-box;
height: 100%;
margin: 2px;
border: 2px solid blue;
}
<div class="container">
<div class="container-left">
<div class="child"></div>
</div>
<div class="container-right">
<div class="child"></div>
</div>
</div>
You can use other px size values as long as the proportion between them is maintained.
If you don't want to display the full SVG, but just want to make sure the curve on the left remains fully visible, add the following attributes to the root
preserveAspectRatio="xMinYMid slice"
When changing the aspect ratio of the right container, this will have the same effect as CSS cover
, and the viewBox
's area will always be to the left. This only works if the aspect ratio is moved to a higher height relative to the width. If the aspect ratio width is increased, the same part of the curve will be cut off at the top and bottom - but the alternative is that it's not wide enough to cover the right side.
If you go this route, keep in mind that you only know the width of the area between the largest and smallest right sides if you set a fixed height ahead of time. CSS cannot use an element's height to calculate a width value.