自己动手丰衣足食之气泡框和常见css图形(三角)

2023-10-06 23:30

本文主要是介绍自己动手丰衣足食之气泡框和常见css图形(三角),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


点击打开链接

原文地址:http://www.cnblogs.com/keepfool/p/5616326.html


参考链接:http://www.cnblogs.com/sdjiegeng/p/5836239.html

<!doctype html>
<html lang="en"><head><meta charset="UTF-8" /><title>Document</title><style type="text/css">div {float: left;margin: 10px;}div.main0 {width: 0;height: 0;border-bottom: 100px solid red;border-left: 50px solid transparent;border-right: 50px solid transparent;}div.main1 {width: 200px;/*width和height相等时就是园*/height: 100px;background: red;border-radius: 50%;}div.main2 {width: 100px;/*width和height相等时就是园*/height: 100px;background: red;border-radius: 100px/50px;}div.main3 {width: 0;height: 0;border-top: 100px solid red;border-left: 50px solid transparent;border-right: 50px solid transparent;}div.main4 {width: 0;height: 0;border-top: 50px solid transparent;border-left: 100px solid red;border-bottom: 50px solid transparent;}div.main5 {width: 0;height: 0;border-top: 50px solid transparent;border-right: 100px solid red;border-bottom: 50px solid transparent;}div.main6 {width: 80px;height: 80px;background: red;transform: rotate(-45deg);margin-left: 20px;}div.main7 {height: 0;width: 100px;border-bottom: 100px solid red;border-left: 50px solid transparent;border-right: 50px solid transparent;}div.main8 {width: 160px;height: 100px;background: red;transform: skew(30deg);}</style></head><body><div class="main0"></div><div class="main1"></div><div class="main2"></div><div class="main3"></div><div class="main4"></div><div class="main5"></div><div class="main6"></div><div class="main7"></div><div class="main8"></div></body></html>



<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title></title><style>/* [01.基础样式] */* {font-family: simhei, sans-serif;box-sizing: border-box;}html {font-size: 62.5%;}body {background-color: black;}div {margin: 20px auto;}/* [02.旗帜样式 ]*/.flag {width: 0;height: 0;border: 2rem solid #FF6600;border-top-width: 4rem;border-bottom-color: transparent;border-bottom-width: 2rem;}/* [03.向右的双实心箭头样式] */.rds-arrow-wrapper {position: relative;width: 20em;text-align: center;}.rds-arrow,.rds-arrow:after {display: inline-block;position: relative;width: 0;height: 0;border-top: 1rem solid transparent;border-left: 2rem solid #fff;border-bottom: 1rem solid transparent;border-right: 2rem solid transparent;}.rds-arrow {margin-left: 1rem;}.rds-arrow:after {content: "";position: absolute;left: 100%;top: -1rem;bottom: 0;}/* [04.气泡样式] */.bubble {position: relative;background-color: #33AAEE;width: 10rem;height: 3rem;font-size: 2rem;line-height: 3rem;color: #FFF;text-align: center;}.bubble:before {position: absolute;content: "";right: 100%;top: 1rem;width: 0;height: 0;border-top: 0.6rem solid transparent;border-right: 0.6rem solid #33AAEE;border-bottom: 0.6rem solid transparent;border-left: 0.6rem solid transparent;}.bubble .text {display: inline-block;}/* [05.丝带样式] *//* 丝带主体长方形 */.ribbon {position: relative;width: 10rem;height: 3rem;padding: 0.7rem 0;font-size: 1.6rem !important;color: #fff;text-align: center;background: #ff0066;}/* 丝带左右两侧的耳朵 */.ribbon:before,.ribbon:after {content: "";position: absolute;display: block;bottom: -0.6rem;border: 1.5rem solid #ff0066;z-index: -1;}.ribbon:before {left: -2.4rem;border-right-width: 1.5rem;border-left-color: transparent;box-shadow: 1px 1px 0 rgba(176, 102, 166, 0.8);}.ribbon:after {right: -2.4rem;border-left-width: 1.5rem;border-right-color: transparent;box-shadow: 0 1px 0 rgba(176, 102, 166, 0.8);}/* 丝带阴影 */.ribbon .ribbon-content:before,.ribbon .ribbon-content:after {content: "";position: absolute;display: block;border-style: solid;border-color: #bf004c transparent transparent transparent;bottom: -0.6rem;}.ribbon .ribbon-content:before {left: 0;border-width: 0.6rem 0 0 0.6rem;}.ribbon .ribbon-content:after {right: 0;border-width: 0.6rem 0.6rem 0 0;}</style></head><body><div class="flag"></div><div class="rds-arrow-wrapper"><span class="rds-arrow"></span></div><div class="bubble"><span class="text">立即查看</span></div><div class="ribbon"><span class="ribbon-content">金卡会员</span></div></body></html>





气泡框(或者提示框)是网页中一种很常见的元素,大多用来展示提示信息,如下图所示:

拆分来看,形如这种气泡框无外乎就是一个矩形框+一个指示方向的三角形小箭头,要制作出这样的气泡框,如果解决了三角形小箭头就容易了。一种方法就是制作这样一个三角形箭头的图片,然后定位在矩形框上。但这种解决办法在后期更改气泡框会很不方便,可能每修改一次气泡框都要重新制作一个三角形小图标。如果我们能够直接用HTML和CSS代码实现这样一个三角形小箭头一切都迎刃而解了。

首先我们来看一下border这个属性,当我们把一个div的border-color设为不同值的时候,可以看到四边都成了一个梯形。

1
# test{ width : 50px height : 50px border-width : 50px border-style : solid border-color : #09F  #990  #933  #0C9 ;}

 

如果我们继续把这个div的width和height都设为0,可以看到四边都成了一个三角形。

1
# test{ width : 0 height : 0 border-width : 75px border-style : solid border-color : #09F  #990  #933  #0C9 ;}

 

在主流浏览器中检测一下,发现IE6中存在一个小问题,上下边能形成三角形,左右两边仍然还是梯形

通过实验发现当把div的font-size和line-height都设为0的时候,div的四边在IE6下都能形成完美的三角形:

1
#test{  width : 0 height : 0 border-width : 75px border-style : solid border-color : #09F  #990  #933  #0C9 font-size : 0 line-height : 0 ;}

很显然我们只需要其中的一个三角形,那么只需要将其他三边的color设置为透明或者跟页面背景一样的颜色,就能模拟出一个三角来,推荐将其他三边颜色设置为透明,即color的值为transparent,如果其他三边颜色跟页面背景一样,虽然视觉上只能看到一个三角,但背景颜色一旦改变,其他三边颜色也要随之改变。

1
#test{  width : 0 height : 0 border-width : 75px border-style : solid border-color : #09F  transparent  transparent font-size : 0 line-height : 0 ;}

 问题又来了,IE6下transparent无效!其他三边被设置成默认的黑色了。

但通过实验发现把border-style设置为dashed后,IE6下其他三边就能透明了!

1
#test{  width : 0 height : 0 border-width : 75px border-style : solid  dashed  dashed border-color : #09F  transparent  transparent font-size : 0 line-height : 0 ;}

 到这一步我们已经成功的模拟出了一个小三角,下一步我们把这个小三角同矩形框结合起来。先设置一个矩形框,然后把小三角定位到矩形框上。先来写出HTML结构:

1
2
3
4
< div  class="tag">
       < em ></ em >   
       CSS气泡框实现
</ div >

CSS样式:

1
2
.tag{  width : 300px height : 100px border : 5px  solid  #09F position : relative ;}
.tag em{ display : block border-width : 20px position : absolute

这篇关于自己动手丰衣足食之气泡框和常见css图形(三角)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/154570

相关文章

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

SpringBoot实现图形验证码的示例代码

《SpringBoot实现图形验证码的示例代码》验证码的实现方式有很多,可以由前端实现,也可以由后端进行实现,也有很多的插件和工具包可以使用,在这里,我们使用Hutool提供的小工具实现,本文介绍Sp... 目录项目创建前端代码实现约定前后端交互接口需求分析接口定义Hutool工具实现服务器端代码引入依赖获

SpringBoot项目整合Netty启动失败的常见错误总结

《SpringBoot项目整合Netty启动失败的常见错误总结》本文总结了SpringBoot集成Netty时常见的8类问题及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录一、端口冲突问题1. Tomcat与Netty端口冲突二、主线程被阻塞问题1. Netty启动阻

SpringBoot+Vue3整合SSE实现实时消息推送功能

《SpringBoot+Vue3整合SSE实现实时消息推送功能》在日常开发中,我们经常需要实现实时消息推送的功能,这篇文章将基于SpringBoot和Vue3来简单实现一个入门级的例子,下面小编就和大... 目录前言先大概介绍下SSE后端实现(SpringBoot)前端实现(vue3)1. 数据类型定义2.

SpringBoot整合Kafka启动失败的常见错误问题总结(推荐)

《SpringBoot整合Kafka启动失败的常见错误问题总结(推荐)》本文总结了SpringBoot项目整合Kafka启动失败的常见错误,包括Kafka服务器连接问题、序列化配置错误、依赖配置问题、... 目录一、Kafka服务器连接问题1. Kafka服务器无法连接2. 开发环境与生产环境网络不通二、序

在C#中调用Windows防火墙界面的常见方式

《在C#中调用Windows防火墙界面的常见方式》在C#中调用Windows防火墙界面(基础设置或高级安全设置),可以使用进程启动(Process.Start)或Win32API来实现,所以本文给大家... 目录引言1. 直接启动防火墙界面(1) 打开基本防火墙设置(firewall.cpl)(2) 打开高

使用Python在PDF中绘制多种图形的操作示例

《使用Python在PDF中绘制多种图形的操作示例》在进行PDF自动化处理时,人们往往首先想到的是文本生成、图片嵌入或表格绘制等常规需求,然而在许多实际业务场景中,能够在PDF中灵活绘制图形同样至关重... 目录1. 环境准备2. 创建 PDF 文档与页面3. 在 PDF 中绘制不同类型的图形python

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

MySQL中如何求平均值常见实例(AVG函数详解)

《MySQL中如何求平均值常见实例(AVG函数详解)》MySQLavg()是一个聚合函数,用于返回各种记录中表达式的平均值,:本文主要介绍MySQL中用AVG函数如何求平均值的相关资料,文中通过代... 目录前言一、基本语法二、示例讲解1. 计算全表平均分2. 计算某门课程的平均分(例如:Math)三、结合