html div左边得圆角,html – div倾斜的侧面和圆角

该博客介绍了如何使用CSS创建具有倾斜边和圆角的响应式形状。通过使用相对定位的容器、伪元素和变换属性,可以在不同浏览器中实现优雅的回退,即使在不支持CSS3的浏览器中也能呈现为带有圆角的标准按钮。此外,形状的背景可以是多种颜色或图像,且能响应鼠标悬停事件改变尺寸。示例代码展示了如何实现这种形状,并突出了其在页面布局和响应性设计上的灵活性。
摘要由CSDN通过智能技术生成

Note: I am adding a separate answer because though the answers that I linked in comment seem to give a solution, this one is a bit more complex due to the presence of border also along with the border-radius.

可以使用以下部件创建形状:

>一个相对定位的主要容器元件.

>两个伪元素,大约是父元素宽度的一半.一个元素倾斜以产生倾斜的左侧而另一个元素不倾斜.

>偏斜的伪元素位于左侧,而普通元素位于容器元素的右侧.

>偏斜的伪元素只有顶部,左边和底部边框.省略右边框,因为它将位于形状的中间.对于未倾斜的伪元素,出于同样的原因避免使用左边界.

>偏斜伪元素的左边界比其他边界更厚一些,因为偏斜使边框看起来比实际更薄.

我还在片段中添加了悬停效果,以展示形状的响应特性.

.outer {

position: relative;

height: 75px;

width: 300px;

text-align: center;

line-height: 75px;

color: white;

text-transform: uppercase;

}

.outer:before,

.outer:after {

position: absolute;

content: '';

top: 0px;

height: 100%;

width: 55%;

background: purple;

border: 2px solid white;

border-left-width: 3px;

z-index: -1;

}

.outer:before {

left: 0px;

border-radius: 20px;

border-right: none;

transform: skew(20deg);

transform-origin: top left;

}

.outer:after {

right: 0px;

border-top-right-radius: 20px;

border-bottom-right-radius: 20px;

border-left: none;

}

/* Just for demo of responsive nature */

.outer{

transition: all 1s;

}

.outer:hover{

height: 100px;

width: 400px;

line-height: 100px;

}

body{

background: lightblue;

}

Call me back

优点:

>这种方法的一大优势是它提供了优雅的后备.也就是说,在非CSS3兼容的浏览器中,它看起来像带有圆角的普通按钮(并且没有倾斜的侧面).

>页面(或容器元素)背景不必是纯色.

>形状本身可以具有非纯色(即图像或渐变)作为背景.它需要一些额外的调整,但方法本身将保持不变.

在下面的代码片段中,我给每个组件添加了不同的颜色,以直观地说明如何实现形状:

.outer {

position: relative;

height: 75px;

width: 300px;

text-align: center;

line-height: 75px;

color: white;

text-transform: uppercase;

}

.outer:before,

.outer:after {

position: absolute;

content: '';

top: 0px;

height: 100%;

width: 55%;

background: purple;

border: 2px solid white;

border-left-width: 3px;

z-index: -1;

}

.outer:before {

left: 0px;

border-radius: 20px;

border-right: none;

transform: skew(20deg);

transform-origin: top left;

background: seagreen;

border-color: red;

}

.outer:after {

right: 0px;

border-top-right-radius: 20px;

border-bottom-right-radius: 20px;

border-left: none;

background: yellowgreen;

border-color: maroon;

}

/* Just for demo of responsive nature */

.outer{

transition: all 1s;

}

.outer:hover{

height: 100px;

width: 400px;

line-height: 100px;

}

body{

background: lightblue;

}

Call me back

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值