css 形状

CSS is based off a box model. If you have an image that is a circle that you want to wrap text around, it will wrap around the images’ bounding box.

CSS基于盒模型。 如果您要环绕的图像是一个圆,则它将环绕图像的边界框。

外型 (Shape-outside)

A new CSS property called shape-outside lets you wrap text that conforms to the shape of your image.

一个名为shape-outside的新CSS属性使您可以包装符合图像形状的文本。

什么是外形 (What is shape-outside)

Shape-outside is a new CSS property that changes the shape of items that are wrapped. Instead of being limited to a rectangular bounding box around the image, shape-outside allows us to shape content to fit the image.

Shape-outside是一个新CSS属性,可更改包装物品的形状。 不仅限于图像周围的矩形边界框,还可以通过形状外部使内容的形状适合图像。

Here is how MDN describes shape-outside:

这是MDN描述外部形状的方式:

The shape-outside CSS property uses shape values to define the float area for a float and will cause inline content to wrap around the shape instead of the float’s bounding box.

shape-outside CSS属性使用形状值来定义浮动对象的浮动区域,并将导致内联内容环绕形状而不是浮动对象的边界框。

The most important take away from that description is this new property applies to images that uses a float. The CSS shape-outside property controls how text wraps around any floated image. The text that is wrapped can take the shape of a circle, ellipse, rectangle or polygon.

该描述最重要的一点是,此新属性适用于使用浮点数的图像。 CSS shape-outside属性控制文本如何环绕任何浮动图像。 换行的文本可以采用圆形,椭圆形,矩形或多边形的形状。

使用形状外 (Using shape-outside)

The shape-outside property takes a “basic shape” and applies a shape function to it. The shape function is used to change the shape of the float area of the shape. The CSS shape-outside property provides functionality to create these shape functions:

外部形状属性采用“基本形状”并对其应用形状函数。 形状函数用于更改形状的浮动区域的形状。 CSS shape-outside属性提供创建以下形状函数的功能:

  • circle圈
  • ellipse椭圆
  • polygon多边形
  • rectangle长方形
  • url网址

The image can be positioned with these values. The values are appended to the end:

可以使用这些值来定位图像。 这些值将附加到末尾:

  • margin-box边距框
  • padding-box填充盒
  • border-box边框

The image must have intrinsic dimensions. You must set the height and width of the element. This will be used by the shape function to create a coordinate system that is used when wrapping text around the image.

图像必须具有固有尺寸。 您必须设置元素的高度和宽度。 形状函数将使用它来创建坐标系,该坐标系在将文字环绕图像时使用。

圈 (Circle)

Circle() is one of the functional values provided with shape-outside. The full notation for circle() is circle(r at cx cy) where r is the radius of the circle and cx and cy are the coordinates for the center of the circle. If you omit them, the center of the image will be used as the default values.

Circle()是shape-outside提供的功能值之一。 circle()的完整符号为circle( r在cx cy处) ,其中r是圆的半径,而cx和cy是圆心的坐标。 如果省略它们,则图像的中心将用作默认值。

Here is an example of using shape-outside on a circle:

这是在圆上使用形状外部的示例:

.circle {    height: 200px;    width: 200px;    border-radius: 50%;    background-color: #7db9e8;    margin: 0 25px 5px 0;    float: left;    -webkit-shape-outside: circle();    shape-outside: circle();}

椭圆 (Ellipse)

Ellipse is a variation of the circle where the item is elongated on either the horizontal or vertical axis. The full notation for ellipse() is ellipse(rx ry at cx cy) where rx and ry are the radii for the ellipse and cx and cy are the coordinates for the center of the ellipse.

椭圆是圆的一种变化形式,其中商品在水平或垂直轴上都被拉长。 ellipse()的完整符号为ellipse( 在cx cy处为rx ry ) ,其中rx和ry是椭圆的半径,而cx和cy是椭圆中心的坐标。

Here is an example of using shape-outside on the ellipse:

这是在椭圆上使用形状外部的示例:

.ellipse {    width: 100px;    height: 200px;    border-radius: 50%;    background-color: #7db9e8;    margin: 0 25px 5px 0;    float: left;    -webkit-shape-outside: ellipse(50px 100px at 50% 50%);    shape-outside: ellipse(50px 100px at 50% 50%);}

多边形 (Polygon)

The polygon function provides an unlimited range of shapes. The full notation for polygon() is polygon(x1 y1, x2 y2, …) where each pair specifies the x y coordinates for a vertex of the polygon. To use the polygon() function you must specify a minimum of 3 pairs of vertex.

多边形功能可提供无限范围的形状。 polygon()的完整表示法是polygon(x1 y1,x2 y2,…) 其中每对指定多边形顶点的xy坐标。 要使用polygon()函数,您必须至少指定3对顶点。

Polygon is used with a clip-path. The clip-path CSS property creates a clipping region that defines what part of an element should be displayed. Anything inside the region is displayed, while those outside are hidden.

多边形与剪切路径一起使用。 clip-path CSS属性创建一个裁剪区域,该区域定义应显示元素的哪一部分。 将显示区域内的所有内容,而隐藏外部的内容。

Here is an example of using shape-outside to create two triangle shapes and the text flows between them:

这是一个使用shape-outside创建两个三角形的示例,文本在它们之间流动:

.leftTriangle {    width: 150px;    height: 300px;    background-color: #7db9e8;    margin: 0 25px 5px 0;    float: left;    -webkit-clip-path: polygon(0% 0%, 100% 0%, 50% 100%);    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);    -webkit-shape-outside: polygon(0% 0%, 100% 0%, 50% 100%);    shape-outside: polygon(0% 0%, 100% 0%, 50% 100%);}.rightTriangle {    width: 150px;    height: 300px;    background-color: #7db9e8;    margin: 0 0 5px 25px;    float: right;    -webkit-clip-path: polygon(0% 0%, 100% 0%, 50% 100%);    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);    -webkit-shape-outside: polygon(0% 0%, 100% 0%, 50% 100%);    shape-outside: polygon(0% 0%, 100% 0%, 50% 100%);}

浏览器支持 (Browser Support)

The CSS shape-outside is supported primarily by Chrome, Opera and Safari.

Chrome,Opera和Safari主要支持CSS形状外功能。

获取代码 (Get the Code)

The code for all of the examples can be found in my github repo here.

所有示例的代码都可以在我的github仓库中找到 。

更多文章 (More Articles)

Thanks for reading my article. If you like it, please click on clap icon below so that others will find the article. Here are some more of my articles that you might be interested in:

感谢您阅读我的文章。 如果喜欢,请单击下面的拍手图标,以便其他人可以找到该文章。 以下是您可能感兴趣的其他一些文章:

Here are 5 Layouts That You Can Make With FlexBoxBreadth First Search in JavaScriptInstantiation Patterns in JavaScript

这是您可以使用FlexBox 广度优先搜索的 5种布局 在JavaScript中的 实例化模式

翻译自: https://www.freecodecamp.org/news/mastering-css-series-shape-outside-44d626270b25/

css 形状

css 形状_在CSS形状之外思考相关推荐

  1. css网格_一个CSS网格可以全部统治

    css网格 The case for using one CSS grid for your entire website 在整个网站上使用一个CSS网格的情况 CSS网格与Flexbox (CSS ...

  2. 2019 css 框架_宣布CSS 2019调查状态

    2019 css 框架 by Sacha Greif 由Sacha Greif 宣布#StateOfCSS 2019调查 (Announcing the #StateOfCSS 2019 Survey ...

  3. css网格_使用CSS网格构建的澳大利亚初创企业的周期表

    css网格 by Shooting Unicorns 通过射击独角兽 使用CSS网格构建的澳大利亚初创企业的周期表 (The Periodic Table of Australian Startups ...

  4. javafx css样式_使用CSS设置JavaFX饼图样式

    javafx css样式 渲染图表时, JavaFX默认提供某些颜色. 但是,在某些情况下,您想自定义这些颜色. 在此博客文章中,我将使用一个示例来更改JavaFX饼图的颜色,该示例打算在今天下午在2 ...

  5. css文本字体形状_使用CSS更改文本字体

    css文本字体形状 In the last module, we discussed text formatting. By now, you already know how to work wit ...

  6. css特殊边框形状_了解CSS边框角形状

    我们已经看到了一些已广泛实施的CSS3新功能,例如Rounded Corner, Box Shadow和Text Shadow,仅举几例. 仍然有一些试验性的功能,例如我们将在本文中讨论的内容: Bo ...

  7. css 蒙版_简单CSS蒙版:创建图像小插图

    css 蒙版 Vignetting is the technique of fading of an image at its edges, often seen in wedding photogr ...

  8. 水平时间轴css代码_使用CSS和JavaScript构建水平时间线

    水平时间轴css代码 在上一篇文章中 ,我向您展示了如何从头开始构建响应式垂直时间轴. 今天,我将介绍创建相关的水平时间线的过程. 与往常一样,要初步了解我们将要构建的内容,请查看相关的CodePen ...

  9. css初始化_利用CSS变量实现炫酷的悬浮效果

    这个动画是将鼠标移动到订阅按钮上移动光标会显示相应的彩色渐变.这个想法很简单,但是它能使这个按钮脱颖而出,人们一下子就注意到它了,增加了点击的概率. 怎样才能达到这个效果,使我们的网站脱颖而出呢?其实 ...

最新文章

  1. Hadoop集群安装-CDH5(5台服务器集群)
  2. android端 socket长连接 架构
  3. OS存储器管理(一)
  4. oracle 登录非系统用户,非Oracle用户使用操作系统验证登陆(/ as sysdba)
  5. C 简单瞎搞题(牛客练习赛22)(bitset优化dp)
  6. 查看mysql是否启用安全审计_如何查看oracle是否开启了审计功能?
  7. Intel 64/x86_64/x86/IA-32处理器的指令指针(IP/EIP/RIP)
  8. itextpdf添加表格元素_itext生成pdf文件-表格
  9. 开放源码的.NET 反编译工具 .NET IL调试工具 学习微软中间语言(MSIL)的绝佳工具 Dotnet IL Editor 推荐...
  10. java电话本怎么做_Java写的电话号码本自动化生成器,程序片段
  11. 大数据——Python数据爬取
  12. Android快速转战Kotlin教程
  13. 全国电话区号->地址映射表
  14. 【学习笔记】大数据可视化简介
  15. safari html5 自动全屏,IOS10全屏safari Javascript
  16. 应用服务器和数据库服务器有什么区别?
  17. nothing的含义介绍和 Optional ByVal的用法
  18. 微服务 分布式配置中心Apollo详解
  19. Arduino - 315/433MHz RF无线收发模块
  20. stm32 TIM3_CH1 PB4复用输出PWM 完整配置源码

热门文章

  1. IDEA快捷键及基本使用方法
  2. android专题-数据库Room
  3. mac 怎么查找大于200m的文件_U盘无法拷贝大于4GB的文件怎么办?
  4. 小程序打开文档标题乱码处理
  5. 3D Touch介绍: 一个数字压力器App和Quick Actions
  6. 「小程序JAVA实战」小程序的视频展示页面初始化(63)
  7. Python3 与 C# 并发编程之~ Net篇
  8. vue从创建到完整的饿了么(5)v-for,v-bind与计算属性
  9. 普华永道重磅报告:决定未来的八大核心科技
  10. ASP.NET中的母版页