html - 使用 CSS 创建形状

标签 html css

.shape {
    width: 200px;
    height: 50px;
    background-color: green;
    border-radius: 10px 10px 0 30px;
    transform: skewX(0);
}
<div class="shape">Hello World!</div>

我们有以下两个 jpg 格式的形状。但在某些情况下背景和边框颜色需要更改为某种不同的颜色。所以想法是使用 CSS 变换属性创建这些图像(如果可能的话)。

{   width: 200px;
    height: 50px;
    background-color: green;
    border-radius: 10px 10px 0 30px;
    transform: skewX(0);
}

enter image description here

最佳答案

使用 SVG

.a {
  fill: #ef0c4d;
  stroke: #999;
  stroke-miterlimit: 10;
  stroke-width: 7px;
}

.a:hover {
  fill: green;
  stroke: blue;
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680.4 240.3">
<path class="a" d="M135,113.1s7.7,123.6,13.5,164.4c6.3,44.5,13,64,168,64h490L737.7,184.3a5.6,5.6,0,0,0-4.2-3.2L140.1,108.2A4.5,4.5,0,0,0,135,113.1Z" transform="translate(-131.4 -104.7)"/>
</svg>


使用CSS

.rect {
    width: 230px;
    height: 100px;
    overflow: hidden;
    position: relative;
}

.rect:before {
  content: " ";
    position: absolute;
    width: 200px;
    height: 50px;
    background: #dedede;
    border-bottom-left-radius: 26px;
    right: 30px;
    bottom: 0;
}

.rect:after {
  content: " ";
    position: absolute;
    width: 250px;
    height: 50px;
    background: #dedede;
    transform: rotate(10deg) skew(30deg);
    bottom: 20px;
    left: -38px;
}
<div class="rect"></div>

关于html - 使用 CSS 创建形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50465042/

相关文章:

html - 如何使按钮具有背景图像并同时透明?

css - IE 无法正确显示侧边栏过渡

css - 背景图像和渐变 - 控制图像的大小

html - CSS 位置 :fixed and IE7

html - 相邻的兄弟选择器不起作用

php - 如何在页面上添加自定义搜索框?

html - 使用 BlackBerry 4 OS 呈现电子邮件

CSS:在 IE/Safari 中包含背景大小和定位

javascript - 如何创建唯一值列表并将它们系统地存储在本地存储中

javascript - 如何使单选按钮组可折叠?