html - 如何使用 css 或 SVG 创建圆形

标签 html css svg

我现在正在为客户开发网上商店,他们的设计师在纸上创建了一个外观很棒的网站。我的工作是将它翻译成 HTML/CSS 等。

enter image description here

如您所见,它还有圆 Angular 、对 Angular 线填充和对 Angular 线文本。

红色的形状表示“添加到购物车”,客户想要的是可点击的,但只有那个形状。

我“有点”设法复制了上面的图像,并且在 Chrome 中可以正常工作。但是当我在 Firefox 中尝试时,一切都搞砸了。

这是我使用的 CSS 代码:

.product-grid > div {
position:relative;
width: 215px;
height: 320px;
display: inline-block;
vertical-align: top;
margin-right: 5px;
margin-left: 5px;
margin-bottom: 6px;
margin-top: 6px;
text-align: center;
-webkit-border-top-left-radius: 30px;
-webkit-border-bottom-right-radius: 30px;
-moz-border-radius-topleft: 30px;
-moz-border-radius-bottomright: 30px;
border-top-left-radius: 30px;
border-bottom-right-radius: 30px;
-moz-box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.6);
-webkit-box-shadow:3px 3px 10px rgba(0, 0, 0, 0.6);
box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.6);
z-index:5;
overflow:hidden;
}

.product-grid .blue {
width: 0px;
height: 0px;
border-style: solid;
border-width: 75px 175px 0 0;
border-color: #009de0 transparent transparent transparent;
bottom:0px;
right:0px;

}


.product-grid .red {
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 0 75px 175px;
border-color: transparent transparent #ff0000 transparent;
float:right;
bottom:0px;
right:0px;
cursor:pointer;
z-index:2;
}


.product-grid .blue .price {
display: block;
font-weight: 800;
font-size: 18px;
color: #FFF;
margin-bottom: 4px;
-webkit-backface-visibility: hidden;    
backface-visibility: hidden;
position:relative;
margin-top:-50px;
width:100px;
transform:rotate(337deg);
-ms-transform:rotate(337deg);
-moz-transform:rotate(337deg);
-webkit-transform:rotate(337deg);
-o-transform:rotate(337deg);

}
.product-grid .red .cart {
margin-bottom: 3px;
width:100px;
color:#FFF;
transform:rotate(337deg);
-ms-transform:rotate(337deg);
-moz-transform:rotate(337deg);
-webkit-transform:rotate(337deg);
-o-transform:rotate(337deg);
margin-top: 40px;
margin-right: 15px;
-webkit-backface-visibility: hidden;    
backface-visibility: hidden;
font-size:18px;
}

添加到购物车按钮仍然是矩形的,虽然上半部分没有显示。这不是我的客户想要的。

enter image description here

你会建议做什么?使用 SVG?或者应该使用哪种跨浏览器解决方案?

也许有人可以指出正确的方向?

最佳答案

SVG

这里制作了一个模型示例。
您可以添加 SVG <A>用于链接调用等的元素
我所做的是为红色形状和蓝色形状添加路径。
主要内容是用多边形完成的。
并使用 CSS 为事物着色。

.ticket {
  height: 400px;
  -webkit-filter: drop-shadow(2px 2px 5px black);
  filter: drop-shadow(0px 5px 15px black);
}

.ticket .top {
  fill:blue;
}
.ticket .top-text, .ticket .bottom-text {
  fill: white;
}
.ticket .bottom {
  fill: red;
}
.ticket .content {
  fill:white;
}
<svg class="ticket" viewBox="0 0 100 200">
  <path style="cursor:pointer;" class="top" d="M30,0 80,0 0,40 0,30 C 0,0 0,0 30,0Z"/>
  <text style="pointer-events:none;" transform="rotate(-25) translate(0 30)" class="top-text">€30</text>
  <polygon class="content" points="0,40 80,0, 100,0 100,160 20,200 0,200"/>
  <path style="cursor:pointer;" class="bottom" d="M100,180 100,160 20,200 80,200 C 100,200 100,200 100,180Z"/>
  <text style="pointer-events:none;" transform="rotate(-27) translate(-45 200)" class="bottom-text">Betallen</text>
</svg>

关于html - 如何使用 css 或 SVG 创建圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18247815/

相关文章:

html - 高度 : 100% not working for parent div with floated inner div

PHP Pascal 三 Angular 形在表格中显示不正确

css - 了解此处使用的类名 Prop : &lt;input type ="text" class ="{email: true}"/>

html - 是否可以使用图像代替 SVG 路径的笔划?

javascript - 如何将 SVG 导出为 PNG 格式

html - 通过 HTML 将文件中的 CSS 应用到 SVG 文件

javascript - Rails 4.2 - 链接以在 302 中使用 Javascript 结果创建操作

javascript - 如果图例文本为零,如何隐藏它?

HTML5 源代码集 : Mixing x and w syntax

javascript - 单击 Box shadow Shadow - Javascript(不是 jquery)