css气泡框

html:

 <div className={styles.rechargeAmount}>

         <span className={styles.popover}>

                            <span />

                            8折优惠

            </span>

            充值金额:

     </div>

css:

.rechargeAmount {

        position: relative;

        .popover {

            position: absolute;

            top: -25px;

            width: 60px;

            height: 22px;

            color: #ffae00;

            font-weight: bold;

            font-size: 12px;

            line-height: 22px;

            letter-spacing: 1px;

            text-align: center;

            background: #fff0cf;

            border-radius: 4px;

            span {

                position: absolute;

                bottom: -10px;

                left: 25px;

                display: block;

                font-size: 0;

                line-height: 0;

                border-color: #fff0cf transparent transparent;

                border-style: solid dashed dashed;

                border-width: 5px;

            }

        }

    }

效果:

 

要实现一个带有三角形箭头的气泡,可以使用 CSS 的 ::before 和 ::after 伪元素,同时利用 CSS 的 border 属性和 transform 属性进行样式的定制。 下面是一个简单的示例代码,可以作为参考: ```html <div class="bubble"> <p>这是一个带有三角形箭头的气泡。</p> </div> ``` ```css .bubble { position: relative; background-color: #f1f1f1; border-radius: 10px; padding: 10px; margin: 50px; text-align: center; } .bubble::before, .bubble::after { content: ""; position: absolute; border-style: solid; border-width: 10px; width: 0; height: 0; } .bubble::before { top: -20px; left: 50%; border-color: transparent transparent #f1f1f1 transparent; transform: translateX(-50%); } .bubble::after { top: -18px; left: 50%; border-color: transparent transparent #fff transparent; transform: translateX(-50%); } ``` 在上面的代码中,我们首先定义了一个 .bubble 类作为气泡的基础样式,包括了背景色、圆角、内边距和外边距等属性。 接着,我们使用 ::before 和 ::after 伪元素分别创建了一个三角形箭头和一个白色的三角形箭头,通过设置它们的 position 属性为 absolute,使它们位于气泡的上方。 为了实现三角形形状,我们设置了 border-style 为 solid,border-width 为 10px,同时将宽度和高度设置为 0,这样就创建了一个边宽度为 10px 的三角形。 最后,我们通过设置 border-color 和 transform 属性,对三角形箭头的样式进行了定制,使其与气泡相匹配。 以上是一个简单的示例代码,可以根据实际需要进行进一步的样式调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值