search
HomeWeb Front-endHTML TutorialRelated usage of css_position_html/css_WEB-ITnose

Introduction

position is used to fix the position and is a particularly important attribute

The value can be:

  • static: Default value, ignore top, bottom, left , right or z-index statement
  • relative: relative to the positioning of the parent area and the previous subset area, use top, bottom, left, right to set, you can use Z-index
  • absobute: Positioning relative to the position [upper left corner] of the parent area, set with top, bottom, left, right, you can use z-index
  • fixed: relative to the browser For positioning, ignoring other positions such as the parent position, you can use Z-index
  • inherit: inherit the attributes of the parent position
  • specifically

     1 <style type="text/css"> 2 div 3 { 4 position:100px 100px; 5 width:100px; 6 height:100px; 7 border:5px solid black; 8 } 9 div.pos_left10 {11 position:relative;12 left:-20px;13 border:5px solid green;14 }15 div.pos_right16 {17 position:relative;18 left:20px;19 border:5px solid green;20 }21 div.pos_ab22 {23 position:absolute;24 left:30px;25 top:50px;26 border:5px solid blue;27 }28 div.main29 {30 position:absolute;31 left:100px;32 top:50px;33 width:200px;34 height:300px;35 border:5px solid red;36 }37 div.pos_fix38 {39 position:fixed;40 left:10px;41 top:0px;42 clip:rect(0px 50px 200px 0px);43 }44 </style>45 </head>46 47 <body>48 <div class="main">49     <div>1.normal</div>50     <div class="pos_left">2.re-left:-20px</div>51     <div class="pos_right">3.re-left:20px</div>52     <div class="pos_ab">4.ab-(left:30px,top:50px)</div>53     <div class="pos_right">5.re-left:20px</div>54     <div class="pos_fix">6.fix-(left:30px,top:50px)</div>55 </div>


    Among them:

  • [2], [3], [5] are relative
  • When setting position: relative

    , refer to the parent middle-top The upper left corner of the content area of ​​a child element is positioned using the original point combined with the TRBL attribute. If there is no parent, the upper left corner of the BODY is used as the original point

    ?? It must be noted that the upper left corner relative to the previous child element is not the upper left corner shown in the 2 to 3 picture. In other words, if [2] is static, the upper left corner will not be TRBL transformed.

    ??That is, even if the relative element is TRBL transformed, the interval it occupies is still the original interval, so it will cover other elements.

    More obvious display:

    Change [2] in the picture:

    position: relative;
    left:-20px;
    top:-50px;

    Then:

    An area in the figure that contains the blank areas above and below [2] and [3] is [ 2】Really occupied space

  • [4] is absolute
  • . When setting position: relative

    , refer to the upper left corner of the parent The corner is positioned as the original point combined with the TRBL attribute. If there is no parent, the upper left corner of the browser is the original point

    At the same time, we can see from the relative attribute [5]?? [5] is relative to the space of [3]

    ?? Absolute is equivalent to directly covered without possessing real space

  • [4] is the absolute
  • When setting the position: related The upper left corner is the original point

    In addition
  • relative, absolute, and fixed are only valid when setting the TRBL attributes (TOP, RIGHT, BOTTOM, LEFT), otherwise normal HTML layout rules will be followed, and the previous object is presented immediately afterwards.
  • Absolute is generally not used when the page is displayed in the center, because when zooming, absolute will use the upper left corner of the browser as the vertex. Of course, it can also be fixed in a parent area and fixed width to solve the problem
  • clip:rect(0px 50px 200px 0px); used in [6] can crop the area
  • z-index, the number of layers can be set, and elements with high values ​​will always be at low values. Above the element [Only valid when the position attribute value is absolute, relative or fixed]
  • Statement
    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
    HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 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 DesignThe Future of HTML: Evolution and Trends in Web DesignApr 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 OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 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: 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.

    HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 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.

    From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

    HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

    Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

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

    The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

    The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

    See all articles

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    Will R.E.P.O. Have Crossplay?
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor

    SecLists

    SecLists

    SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    SAP NetWeaver Server Adapter for Eclipse

    SAP NetWeaver Server Adapter for Eclipse

    Integrate Eclipse with SAP NetWeaver application server.

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools