自己动手丰衣足食之气泡框和常见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

相关文章

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

C++中初始化二维数组的几种常见方法

《C++中初始化二维数组的几种常见方法》本文详细介绍了在C++中初始化二维数组的不同方式,包括静态初始化、循环、全部为零、部分初始化、std::array和std::vector,以及std::vec... 目录1. 静态初始化2. 使用循环初始化3. 全部初始化为零4. 部分初始化5. 使用 std::a

前端下载文件时如何后端返回的文件流一些常见方法

《前端下载文件时如何后端返回的文件流一些常见方法》:本文主要介绍前端下载文件时如何后端返回的文件流一些常见方法,包括使用Blob和URL.createObjectURL创建下载链接,以及处理带有C... 目录1. 使用 Blob 和 URL.createObjectURL 创建下载链接例子:使用 Blob

Vuex Actions多参数传递的解决方案

《VuexActions多参数传递的解决方案》在Vuex中,actions的设计默认只支持单个参数传递,这有时会限制我们的使用场景,下面我将详细介绍几种处理多参数传递的解决方案,从基础到高级,... 目录一、对象封装法(推荐)二、参数解构法三、柯里化函数法四、Payload 工厂函数五、TypeScript

C++ vector的常见用法超详细讲解

《C++vector的常见用法超详细讲解》:本文主要介绍C++vector的常见用法,包括C++中vector容器的定义、初始化方法、访问元素、常用函数及其时间复杂度,通过代码介绍的非常详细,... 目录1、vector的定义2、vector常用初始化方法1、使编程用花括号直接赋值2、使用圆括号赋值3、ve

Pytest多环境切换的常见方法介绍

《Pytest多环境切换的常见方法介绍》Pytest作为自动化测试的主力框架,如何实现本地、测试、预发、生产环境的灵活切换,本文总结了通过pytest框架实现自由环境切换的几种方法,大家可以根据需要进... 目录1.pytest-base-url2.hooks函数3.yml和fixture结论你是否也遇到过

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo

C/C++错误信息处理的常见方法及函数

《C/C++错误信息处理的常见方法及函数》C/C++是两种广泛使用的编程语言,特别是在系统编程、嵌入式开发以及高性能计算领域,:本文主要介绍C/C++错误信息处理的常见方法及函数,文中通过代码介绍... 目录前言1. errno 和 perror()示例:2. strerror()示例:3. perror(