Table of Contents
CSS 定位 (Positioning) 实例
CSS 实例
01设置元素的形状
02如何使用滚动条来显示元素内溢出的内容
03如何隐藏溢出元素中溢出的内容
04如何设置浏览器来自动地处理溢出
05垂直排列图象
06Z-index
这是一标题
这是二标题
07使用固定值设置图像的上右下左边缘
08使用百分比设置图像的上右下左边缘
这是标题
CSS 定位 (Positioning)总结
Home Web Front-end HTML Tutorial W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose

W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose

Jun 24, 2016 am 11:29 AM

CSS 定位 (Positioning) 实例

CSS 实例

  • CSS 背景实例
  • CSS 文本实例
  • CSS 字体(font)实例
  • CSS 边框(border)实例
  • CSS 外边距 (margin) 实例
  • CSS 内边距 (padding) 实例
  • CSS 列表实例
  • CSS 表格实例
  • 轮廓(Outline)实例
  • CSS 尺寸 (Dimension) 实例
  • CSS 分类 (Classification) 实例
  • CSS 定位 (Positioning) 实例
  • CSS 伪类 (Pseudo-classes)实例
  • CSS 伪元素 (Pseudo-elements)实例
  • 01设置元素的形状

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>01设置元素的形状</title>        <style type="text/css">            img {                position:absolute;                clip: rect(0px 100px 300px 0px);            }        </style>    </head>    <body>        <img  src="/static/imghw/default1.png"  data-src="cc.jpg"  class="lazy"    style="max-width:90%" height="730px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >    </body></html>
    Copy after login

    02如何使用滚动条来显示元素内溢出的内容

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>02如何使用滚动条来显示元素内溢出的内容</title>        <style type="text/css">            div {                width: 250px;                height: 80px;                background-color: #cc9966;                overflow: scroll;            }        </style>    </head>    <body>        <p>如果元素中的内容超出了给定的宽度和高度属性,overflow 属性可以确定是否显示滚动条等行为。</p>        <div>            这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。默认值是 visible。这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。默认值是 visible。        </div>    </body></html>
    Copy after login

    03如何隐藏溢出元素中溢出的内容

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>03如何隐藏溢出元素中溢出的内容</title>        <style type="text/css">            div {                width: 250px;                height: 80px;                background-color: #cc9966;                overflow: hidden;            }        </style>    </head>    <body>        <p>如果元素中的内容超出了给定的宽度和高度属性,overflow 属性可以确定是否显示滚动条等行为。</p>        <div>            这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。默认值是 visible。这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。默认值是 visible。        </div>    </body></html>
    Copy after login

    04如何设置浏览器来自动地处理溢出

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>04如何设置浏览器来自动地处理溢出</title>        <style type="text/css">            div {                width: 250px;                height: 80px;                background-color: #cc9966;                overflow: auto;            }        </style>    </head>    <body>        <p>如果元素中的内容超出了给定的宽度和高度属性,overflow 属性可以确定是否显示滚动条等行为。</p>        <div>            这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。默认值是 visible。这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。默认值是 visible。        </div>    </body></html>
    Copy after login

    05垂直排列图象

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>05垂直排列图象</title>        <style type="text/css">            img.top {                vertical-align: text-top;            }                        img.bottom {                vertical-align: text-bottom;            }        </style>    </head>    <body>        <p>            这是一副<img  class="top lazy"  src="/static/imghw/default1.png"  data-src="55.jpg"  border="1" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >位于段落中的图像。        </p>        <p>            这是一副<img  class="bottom lazy"  src="/static/imghw/default1.png"  data-src="55.jpg"  border="1" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >位于段落中的图像。        </p>    </body></html>
    Copy after login

    06Z-index

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>06Z-index</title>        <style type="text/css">            img.x {                position: absolute;                top: 30px;                left: 0px;                z-index: -1;            }                        img.y {                position: absolute;                top: 150px;                left: 50px;                z-index: 1;            }        </style>    </head>    <body>        <h1 id="这是一标题">这是一标题</h1>        <img  class="x lazy"  src="/static/imghw/default1.png"  data-src="55.jpg"  / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <p>默认的 z-index 是 0。Z-index -1 拥有更低的优先级。</p>        <h1 id="这是二标题">这是二标题</h1>        <img  class="y lazy"  src="/static/imghw/default1.png"  data-src="55.jpg"  / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <p>默认的 z-index 是 0。Z-index 1 拥有更高的优先级。</p>    </body>    </body></html>
    Copy after login

    07使用固定值设置图像的上右下左边缘

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>07使用固定值设置图像的上右下左边缘</title>        <style type="text/css">            img.top {                position: absolute;                top: 0px;            }                        img.right {                position: absolute;                right: 0px;            }                        img.bottom {                position: absolute;                bottom: 0px;            }                        img.left {                position: absolute;                left: 100px;            }        </style>    </head>    <body>        <p>一些文本。一些文本。一些文本。一些文本。一些文本。一些文本。</p>               <img  class="top lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <img  class="right lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <img  class="bottom lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <img  class="left lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >    </body></html>
    Copy after login

    08使用百分比设置图像的上右下左边缘

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>08使用百分比设置图像的上右下左边缘</title>        <style type="text/css">            img.top {                position: absolute;                top: 5%;            }                        img.right {                position: absolute;                right: 5%;            }                        img.bottom {                position: absolute;                bottom: 5%;            }                        img.left {                position: absolute;                left: 20%;            }        </style>    </head>    <body>        <h1 id="这是标题">这是标题</h1>        <img  class="top lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <img  class="right lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <img  class="bottom lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >        <img  class="left lazy"  src="/static/imghw/default1.png"  data-src="77.jpg"  border="1"    style="max-width:90%" height="100px" / alt="W3School-CSS 定位 (Positioning) 实例_html/css_WEB-ITnose" >    </body></html>
    Copy after login

    CSS 定位 (Positioning)总结

    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 Article

    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Nordhold: Fusion System, Explained
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    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
    1666
    14
    PHP Tutorial
    1273
    29
    C# Tutorial
    1252
    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.

    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, 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.

    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.

    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.

    HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

    HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

    HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

    HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

    See all articles