Table of Contents
border-image简介
为什么图片可以作为边框?
border-image-source
border-image-slice
border-image-width
border-image-repeat
border-image-outset
后续
Home Web Front-end HTML Tutorial 详解css3之border-image_html/css_WEB-ITnose

详解css3之border-image_html/css_WEB-ITnose

Jun 21, 2016 am 09:03 AM

border-image简介

css3中新增了一个属性border-image,这个属性允许开发者使用图片来定义边框,扩充了 CSS2 中仅有的几个预定义边框样式(border-style)。
border-image 是一个简写属性,分别设定了以下几个属性。

  • border-image-source

  • border-image-slice

  • border-image-width

  • border-image-outset

  • border-image-repeat

  • 为什么图片可以作为边框?

    在开始学习border-image之前我有一个疑问,图片是怎么应用到容器的边框上的?

    看下图

    简单的说就是把图片的中间部分去掉,从而形成一个类似边框的框架。

    那么如何使用被划分出来的八格素材来生成一个边框呢?

    左上右上左下右下的四格素材分别作为边框的四个角,而上下左右的四格素材分别经过不同形式的扩展,形成边框的四条边。上图很好的说明了图片形成边框的处理形式。

    border-image-source

    border-image-source属性用来指定边框所需素材的路径,语法可以参照backgound-image。
    需要注意的是,如果只设置了border-image-source属性而其他属性使用缺省值,则边框素材不会被划分九宫格,而是将整个素材按照边框宽度缩放至合适尺寸后安放在边框四角

    <!doctype html><html><head><meta charset="utf-8"><title>边框图片</title><style>#border_image {    width:100px;    height:100px;    border:15px solid #ccc;    border-image:url("http://img.mukewang.com/52e21fea000127e802100210.jpg");    background:#ccc;    }</style></head><body><div id="border_image"></div></body></html>
    Copy after login

    如下图

    border-image-slice

    border-image-slice属性用来设置边框素材的切割尺寸,如下图,依次是上横切割线,右竖切割线,下横切割线,左竖切割线。数值分别代表从上、右、下、左边缘向素材中心延伸的像素/百分比数
    注意:切割的数值只接受像素和百分比两个单位,并且像素单位必须省略,即只接收数值或者百分比的形式。例如,border-image-slice: 10 10 30 10代表图片素材按照下图的样式被切割:

    border-image-width

    border-image-width用来设置边框素材的宽度,当同时设置了border-image-width和border-width属性时,那么边框的实际宽度由border-width属性决定。此时,如果border-image-width属性小于border-width属性,边框图片会沿边框的外侧分布而内侧留空形成 padding 的效果;如果border-image-width属性大于border-width属性,边框图片会仍会沿边框的外侧分布而内测溢出,如下图

    border-image-repeat

    border-image-repeat属性用来设置上下左右四边(即2、4、5、7四个素材块)的重复形式,分别有stretch repeat round space四个取值

  • stretch:指定用拉伸方式来填充边框背景图。

  • repeat:指定用平铺方式来填充边框背景图。当图片碰到边界时,如果超过则被截断。

  • round:指定用平铺方式来填充边框背景图。图片会根据边框的尺寸动态调整图片的大小直至正好可以铺满整个边框。

  • space:指定用平铺方式来填充边框背景图。图片会根据边框的尺寸动态调整图片的之间的间距直至正好可以铺满整个边框。

  • border-image-outset

    border-image-outset属性会产生使 border-image 相对于原始位置向外侧推移的效果,设置border-image-outset属性会使 border-image 溢出,但不会影响整个盒模型的尺寸,因此在设置此属性时要特别注意防止元素间的相互干扰。

    如下图

    后续

    border-image是css3属性所以存在兼容性问题,需要在属性前面设置-webkit

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    Java Tutorial
    1663
    14
    PHP Tutorial
    1264
    29
    C# Tutorial
    1237
    24
    Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

    WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

    The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

    HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

    HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

    HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

    HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

    The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

    The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

    The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

    The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

    The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

    HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

    The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

    HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

    HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

    See all articles