.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>

I want to set half background like thisenter image description here

在我的代码中,我想使用 colored颜色 代码添加一半的背景.我已经try 按照代码进行操作,但我不知道如何正确设置!

推荐答案

我希望这就是你的发现

div {
  width: 100vw;
  height: 100vh;
  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: #000;
  border-top-left-radius: 80px 40px;
}
<div></div>

Html相关问答推荐

创建带有弯曲边框的水平时间线

未知高度正在应用于前标记

如何设置弹性盒子容器的具体大小?

如何在排序上重用参数?

如何在垂直堆叠的表格中调整人造列的大小?

每个元素的CSS网格高度相等,以保持响应性

OnChange函数未在下拉列表中使用一个选项触发

如何使用css在响应图像后面添加形状?

Swift 以编程方式在 YouTube 嵌入视频中进入全屏

如何从通过 find-each 方法(在 Rails 应用程序中)生成的列表创建下拉菜单?

如何修剪 flex: 1 内的垂直文本?

如何从 div 内的属性中提取 href 和文本

如何在CSS伪类函数中使用复合 Select 器:host-context()

Tailwind:父母动态适应子元素的身高

如何在 Flex 对齐内容框下显示隐藏按钮和文本

在带有换行文本的工具提示中显示溢出文本

屏幕缩小时背景图像裁剪高度

如何在Bootstrap卡片底部添加波浪形状

两部分问题 - 是什么导致了这个空白?

弹出窗口溢出溢出:自动,我不明白为什么