我想在 html 中使用颜色设置半背景
I want to set half background using color in html
.bg_color {
width: 100vw; /* view width */
height: 100vh; /* view height */
padding: 1rem;
-webkit-box-sizing: border-box;
box-sizing: border-box;
/*
Create the diagonal line in the background by setting each color to take
up 50% of the space. Setting the break points to 49.9% and 50.1% will minimize
the jagged line that is created if gradient colors were to be set to 50%/50%.
*/
background-image: -webkit-gradient(linear, right bottom, left top, color-stop(49.9%, #000000), color-stop(50.1%, #1DA1F2));
background-image: -webkit-linear-gradient(bottom right, #000000 49.9%, #1DA1F2 50.1%);
background-image: -o-linear-gradient(bottom right, #000000 49.9%, #1DA1F2 50.1%);
background-image: linear-gradient(to top left, #000000 49.9%, #1DA1F2 50.1%);
}
<div class="bg_color">
<h1>Half Background</h1>
</div>
我想这样设置半背景
在我的代码中,我想使用颜色代码添加一半背景我已经尝试按照代码进行操作,但我不明白如何正确设置它!
如果您使用带有白色部分半径的白色叠加层怎么样:
div {
width: 300px;
height: 150px;
position: relative;
/* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#6b43fc+0,6b4dc2+100 */
background: #6b43fc; /* Old browsers */
background: -moz-linear-gradient(left, #6b43fc 0%, #6b4dc2 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left, #6b43fc 0%,#6b4dc2 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #6b43fc 0%,#6b4dc2 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6b43fc', endColorstr='#6b4dc2',GradientType=1 ); /* IE6-9 */
}
div::after {
position: absolute;
content: '';
top: 50%;
left: 0;
right: 0;
bottom: 0;
background: #fff;
border-top-left-radius: 80px 40px;
}
<div></div>
我无法重现准确的曲线,但您可以尝试 border-top-left-radius: H V
,其中 H 是水平半径,V 是垂直半径。
要了解更多信息,请查看此 link.
如果你真的想通过 HTML 设置它 - 它可能看起来像这样:
<div style="width: 300px; height: 300px; background-image: linear-gradient(to left, white 0%, white 100%), radial-gradient(white 60%, transparent 60%), linear-gradient(to left, red 0%, #1DA1F2 100%); background-position: 120px 193px, -30px 170px, 0; background-repeat: no-repeat"></div>
.bg_color {
width: 100vw; /* view width */
height: 100vh; /* view height */
padding: 1rem;
-webkit-box-sizing: border-box;
box-sizing: border-box;
/*
Create the diagonal line in the background by setting each color to take
up 50% of the space. Setting the break points to 49.9% and 50.1% will minimize
the jagged line that is created if gradient colors were to be set to 50%/50%.
*/
background-image: -webkit-gradient(linear, right bottom, left top, color-stop(49.9%, #000000), color-stop(50.1%, #1DA1F2));
background-image: -webkit-linear-gradient(bottom right, #000000 49.9%, #1DA1F2 50.1%);
background-image: -o-linear-gradient(bottom right, #000000 49.9%, #1DA1F2 50.1%);
background-image: linear-gradient(to top left, #000000 49.9%, #1DA1F2 50.1%);
}
<div class="bg_color">
<h1>Half Background</h1>
</div>
我想这样设置半背景
在我的代码中,我想使用颜色代码添加一半背景我已经尝试按照代码进行操作,但我不明白如何正确设置它!
如果您使用带有白色部分半径的白色叠加层怎么样:
div {
width: 300px;
height: 150px;
position: relative;
/* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#6b43fc+0,6b4dc2+100 */
background: #6b43fc; /* Old browsers */
background: -moz-linear-gradient(left, #6b43fc 0%, #6b4dc2 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left, #6b43fc 0%,#6b4dc2 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #6b43fc 0%,#6b4dc2 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6b43fc', endColorstr='#6b4dc2',GradientType=1 ); /* IE6-9 */
}
div::after {
position: absolute;
content: '';
top: 50%;
left: 0;
right: 0;
bottom: 0;
background: #fff;
border-top-left-radius: 80px 40px;
}
<div></div>
我无法重现准确的曲线,但您可以尝试 border-top-left-radius: H V
,其中 H 是水平半径,V 是垂直半径。
要了解更多信息,请查看此 link.
如果你真的想通过 HTML 设置它 - 它可能看起来像这样:
<div style="width: 300px; height: 300px; background-image: linear-gradient(to left, white 0%, white 100%), radial-gradient(white 60%, transparent 60%), linear-gradient(to left, red 0%, #1DA1F2 100%); background-position: 120px 193px, -30px 170px, 0; background-repeat: no-repeat"></div>