Home Web Front-end HTML Tutorial 后端程序员前端之路06布局模型,颜色值,长度值_html/css_WEB-ITnose

后端程序员前端之路06布局模型,颜色值,长度值_html/css_WEB-ITnose

Jun 24, 2016 am 11:22 AM

目录

  • 布局模型
  • 流动模型(Flow)
  • 浮动模型 (Float)
  • 层模型(Layer)
  • 颜色值
  • 长度值
  •  一、布局模型

           网页布局模型:个人理解,就是对html中各个元素进行一个排列。而排列的方法可以分为三种:流动模型、浮动模型、层模型。

    二、流动模型

          这是网页默认情况的布局模式。

          特征:

    1. 块状元素都会在所处的包含元素内自上而下按顺序垂直延伸分布,因为在默认状态下,块状元素的宽度都为100%。(独占一行)
    2. 内联元素都会在所处的包含元素内从左到右水平分布显示。(跟其他行内元素处于同一行)

    三、浮动模型

          用来解决块级元素的霸道特征,比如想让两个块级元素处于同一行,就可以使用浮动模型;

          具体表现形式:可以用css的float属性,来控制元素浮动。

    四、层模型

           类似photoshop中的图层编辑功能一样,让每个html元素能够在网页中精确定位。

          具体操作:用css的position属性来支持层模型。

          层模型有三种形式:

          1、绝对定位(position: absolute)

                将元素从文档流中拖出来,然后使用left、right、top、bottom属性相对于其最接近的一个具有定位属性父包含块进行定位。

                如果不存在这样的包含块,则相对于body元素,即相对于浏览器窗口。             

           2、相对定位(position:relative)

                相对于之前的位置进行偏移。移动的方向和幅度由left、right、top、bottom属性确定,偏移前的位置保留不动。 

           3、固定定位(position: fixed)

                和absolute类似,不过他是相对于视图本身(屏幕内的网页窗口)。由于视图本身是固定的,它不会随浏览器窗口的滚动条滚动而变化,

                除非你在屏幕中移动浏览器窗口的屏幕位置,或改变浏览器窗口的显示大小

                因此固定定位的元素会始终位于浏览器窗口内视图的某个位置,不会受文档流动影响。

           4、absolute和relative的组合使用

                回顾上面 absolute的关键点:1、参照物:它的父元素   2、并且参照物必须是定位元素。

                relative的关键点:1、参照物:自己本身

                所以如果需要将子元素相对父元素绝对定位时,就可以利用relative将父元素变为定位元素,子元素使用absolute,就可以进行绝对定位了。

     五、颜色值

          在网页中的颜色设置是非常重要,有字体颜色(color)、背景颜色(background-color)、边框颜色(border)等,设置颜色的方法也有很多种:

          1、英文命令颜色

              比如:p{color:red;} 将颜色设置为红色。   

          2、RGB颜色          

               这个与 photoshop中的RGB颜色是一致的,由R(red)、G(green)、B(blue) 三种颜色的比例来配色。

     p{color:rgb(133,45,200);}
    Copy after login

    每一项的值可以是 0~255 之间的整数,也可以是 0%~100% 的百分数。如:

     p{color:rgb(20%,33%,25%);}
    Copy after login

    3、十六进制颜色

    这种颜色设置方法是现在比较普遍使用的方法,其原理其实也是RGB设置,但是其每一项的值由 0-255 变成了十六进制00-ff。

    Copy after login
    Copy after login

         p{color:#00ffff;}
    Copy after login

    Copy after login
    Copy after login
    <strong>六、长度值</strong><br /> 目前比较常用到px(像素)、em、% 百分比,要注意其实这三种单位都是相对单位。  <br /> 1、像素<br />       像素指的是显示器上的小点(CSS规范中假设“90像素=1英寸”)。实际情况是浏览器会使用显示器的实际像素值有关,在目前大多数的设计者都倾向于使用像素(px)作为单位。<br />    2、em<br />      就是本元素给定字体的 font-size 值,如果元素的 font-size 为 14px ,那么 1em = 14px;如果 font-size 为 18px,那么 1em = 18px。如下代码:
    Copy after login

    p{font-size:12px;text-indent:2em;}
    Copy after login

    上面代码就是可以实现段落首行缩进 24px(也就是两个字体大小的距离)。

    特殊情况:当给 font-size 设置单位为 em 时,此时计算的标准以 它的父元素的 font-size 为基础。

    3、百分比

    p{font-size:12px;line-height:130%}
    Copy after login

    设置行高(行间距)为字体的130%(12 * 1.3 = 15.6px)。

    <br /><br /><br /><br />
    Copy after login
    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

    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)
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    4 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)

    Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

    The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

    How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

    The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

    How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

    This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

    What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

    Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

    What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

    The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

    What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

    The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

    How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

    This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

    What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

    The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

    See all articles