Home Web Front-end HTML Tutorial CSS中对图片(background)的一些设置心得总结_html/css_WEB-ITnose

CSS中对图片(background)的一些设置心得总结_html/css_WEB-ITnose

Jun 24, 2016 am 11:28 AM

  写网页的时候很多情况需要对图片进行操作,如何在不进行专业的美工裁切操作的情况下而让自己的素材度达到最大的满意度呢,这是一个问题,对于懒得开ps切图的我,通常会直接在网络上download一张图片,直接拖到html里,这就需要对图片的css样式进行一些调整,鉴于我总是记不住一些样式属性而无法让图片按我的想法摆放,不得已每次都要百度一下,几次下来,让我很是恼火,于是专门整理了一些css中关于图片的一些属性设置,置于此,以供下次望及时查看(废话真多):

  css2中关于background的属性有:

  •  background-color: 指定填充背景的颜色,不引图片只需要一个纯色背景时用,这种情况下也可直接时用
  •  

          background:#eee;
    Copy after login

  • background-image: 引用图片作为背景,如

      backgroud-image:url("img/bg.jpg");
    Copy after login

  • background-position: 指定元素背景图片的位置,这个很多人都不习惯用,但还是蛮有用处的,实际中图片的左上角正对应元素的左上角,当你的打算使用像素来定位的时候,可以使用:

    background-position: 0 0;//第一个数字代表x轴水平位置,第二个数字代表y轴垂直位置background-position: 0 100px;
    Copy after login

  •   当你的元素尺寸不适用像素设置的时候,还可以使用其他数值,如
    Copy after login

       background-position: top right; // 图片的top对应元素的top 图片的right对应元素的right   background-position:  100% 50%; //使用元素的百分比数值设置图片位置,道理同上
    Copy after login

  • background-repeat: 决定是否重复背景图片,取值有以下几种:

     background-repeat: repeat;       //图片可重复 background-repeat: no-repeat ; //图片不可重复 background-repeat: repeat-x;    //图片在x轴上可以重复 background-repeat: repeat-y;    //图片在y轴上可以重复 background-repeat: inherit;       //遵从父元素的设置 
    Copy after login

  • background-attachment: 决定背景图是否随页面滚动,取值有:

    background-attachment: scroll; //默认值;表示背景紧贴元素background-attachment: fixed;  //背景不随元素滚动,当页面向下时,背景待在最初相对于浏览器的位置background-attachment: inherit;//遵循父元素的设定
    Copy after login

  •   当希望设置background的多个属性时,可以分别设置每一个,也可以合并为一行,写在一个属性里:

      background: transparent url(image.jpg) 50% 0 scroll repeat-y;
    Copy after login

    css3中对于background添加了很多属性:

  • background-color,设置图片的大小尺寸,取值有好几个:

      background-size: contain;     //缩小图片以适应元素的尺寸(图片宽高比不变)  background-size: cover;       //扩展图片以填满元素(图片宽高比不变)  background-size: 50% 100%;    //自定义调整图片大小 
    Copy after login

  • background-clip,背景修剪,可以很好的控制背景的显示位置:取值有:

     background-clip: border-box;   //背景显示在边框内 background-clip: padding-box;  //背景显示在padding内(不是边框内) background-clip: content-box;  //只在内容内显示背景(不在padding中,也不在边框中)<br />
    Copy after login

      还有两个属性为,background-break和background-origin,我对这两个属性并没有使用过,看了看网上的讲解觉得没啥大用处,这里就不写下来误人子弟了。

    css中关于背景的知识点还是很博大精深的,以后有新的理解,再往这儿添。

    注:文章参考》》》》http://blog.csdn.net/adenfeng/article/details/8199362

     

  • 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)

    Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

    HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

    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.

    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.

    What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

    AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

    Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

    GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

    How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

    The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

    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.

    How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

    To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

    See all articles