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

相关文章

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

CSS Anchor Positioning重新定义锚点定位的时代来临(最新推荐)

《CSSAnchorPositioning重新定义锚点定位的时代来临(最新推荐)》CSSAnchorPositioning是一项仍在草案中的新特性,由Chrome125开始提供原生支持需... 目录 css Anchor Positioning:重新定义「锚定定位」的时代来了! 什么是 Anchor Pos

CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比

《CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比》CSS中的position属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布... css 中的 position 属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布局和层叠关

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.

全面解析HTML5中Checkbox标签

《全面解析HTML5中Checkbox标签》Checkbox是HTML5中非常重要的表单元素之一,通过合理使用其属性和样式自定义方法,可以为用户提供丰富多样的交互体验,这篇文章给大家介绍HTML5中C... 在html5中,Checkbox(复选框)是一种常用的表单元素,允许用户在一组选项中选择多个项目。本

HTML5 搜索框Search Box详解

《HTML5搜索框SearchBox详解》HTML5的搜索框是一个强大的工具,能够有效提升用户体验,通过结合自动补全功能和适当的样式,可以创建出既美观又实用的搜索界面,这篇文章给大家介绍HTML5... html5 搜索框(Search Box)详解搜索框是一个用于输入查询内容的控件,通常用于网站或应用程

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

java中long的一些常见用法

《java中long的一些常见用法》在Java中,long是一种基本数据类型,用于表示长整型数值,接下来通过本文给大家介绍java中long的一些常见用法,感兴趣的朋友一起看看吧... 在Java中,long是一种基本数据类型,用于表示长整型数值。它的取值范围比int更大,从-922337203685477