Home Web Front-end HTML Tutorial 第 31 章 项目实战-PC 端固定布局[3]

第 31 章 项目实战-PC 端固定布局[3]

May 30, 2016 pm 04:59 PM

学习要点:

1.搜索区

2.插入大图

3.搜索框

主讲教师:李炎恢

 

本章主要开始使用学习用 HTML5 和 CSS3 来构建 Web 页面,第一个项目采用 PC 端固定布局来实现。

一.搜索区

本节课,我们接着 header 头部往下,来设计一块搜索区。这个区域,可以是广告大图,也可以是用户注册,也可以是一个搜索条,都是一个大幅背景,内嵌一个表单。具体造型如下:

从表面上来分析,就是插入一张背景大图,然后居中一个搜索条。但是,我们要求最小在 1280 分辨率、最大在 1920 分辨率能保持最佳的观看效果。而对于超过 1920 分辨率还要保持大图的位置合理。

二.插入大图

首先,为了满足最小的 1280 分辨率,大图本身的宽度必须大于 1280。而主流分辨率一般小于 1920,所以图片宽度设置为 1920 即可满足几乎所有用户。注:超过 1920 分辨率,即 2k+以上的分辨率一般不适合浏览网页了,会眼瞎。

我们从网上搜索一张风景图,原图的分辨率为:1920 x 1200。我们截取了中间一段变成:1920 x 600。那么被插入的背景区块应该怎么设置长度呢?

//创建一个搜索区域

<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="search"</span><span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>
Copy after login

//可以直接设置宽度为 1920 吗?

<span style="color: #800000;">#search </span>{<span style="color: #ff0000;">
    width</span>:<span style="color: #0000ff;"> 1920px</span>;<span style="color: #ff0000;">
    height</span>:<span style="color: #0000ff;"> 600px</span>;
}
Copy after login

如果使用 1920 的宽度,势必在底部产生滚动条,非常的难看。那不采用 1920 的宽度,整张大图无法全面显示。那么我们的设计理念是,1280 分辨率显示大图中部区域的图片内容,而浏览器不断增大,就显示的内容越多。超过 1920 分辨率,让图片居中,两边空白即可。

//使用 100%,并插入背景图片

<span style="color: #800000;">#search </span>{<span style="color: #ff0000;">
    width</span>:<span style="color: #0000ff;"> 100%</span>;<span style="color: #ff0000;">
    height</span>:<span style="color: #0000ff;"> 600px</span>;<span style="color: #ff0000;">
    background</span>:<span style="color: #0000ff;"> url(../img/search.jpg)</span>;
}
Copy after login

当我们故意缩小分辨率时,小于 1280 时,底部会出现滚动条。当我们拉动滚动条时,发现右侧出现的大量空白。这时由于之前采用了 100%自适应导致的,那我们强行设置这里虽然是 100%。但如果小于 1280 分辨率,就必须固定在 1280 即可。

//不能小于 1280 分辨率

<span style="color: #800000;">#header </span>{<span style="color: #ff0000;">
    min-width</span>:<span style="color: #0000ff;"> 1263px</span>;
}<span style="color: #800000;">

#search </span>{<span style="color: #ff0000;">
    min-width</span>:<span style="color: #0000ff;"> 1263px</span>;
}
Copy after login

对于大于 1920 的分辨率,我们将背景图片居中显示即可,两边留白。当然,还有一种方式,是专门设计这张大图的过渡渐变,两边快要接近纯色是,添加背景过渡。

//大于 1920 分辨率时 

<span style="color: #800000;">#search </span>{<span style="color: #ff0000;">
    background</span>:<span style="color: #0000ff;"> url(../img/search.jpg) no-repeat center</span>;
}
Copy after login

三.搜索框

我们希望在大图中间安插一个搜索框,先安插一个半透明的区块。

//创建一个区块

<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="search"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="center"</span><span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="search"</span><span style="color: #ff0000;"> placeholder</span><span style="color: #0000ff;">="请输入旅游景点或城市"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">button </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="button"</span><span style="color: #0000ff;">></span>搜索<span style="color: #0000ff;"></span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span></span></span></span>
Copy after login

//将区块半透明且居中

<span style="color: #800000;">#search .center </span>{<span style="color: #ff0000;">
    width</span>:<span style="color: #0000ff;"> 600px</span>;<span style="color: #ff0000;">
    height</span>:<span style="color: #0000ff;"> 60px</span>;<span style="color: #ff0000;">
    position</span>:<span style="color: #0000ff;"> absolute</span>;<span style="color: #ff0000;">
    top</span>:<span style="color: #0000ff;"> 50%</span>;<span style="color: #ff0000;">
    left</span>:<span style="color: #0000ff;"> 50%</span>;<span style="color: #ff0000;">
    margin</span>:<span style="color: #0000ff;"> -30px 0 0 -300px</span>;<span style="color: #ff0000;">
    border-radius</span>:<span style="color: #0000ff;"> 10px</span>;<span style="color: #ff0000;">
    opacity</span>:<span style="color: #0000ff;"> 0.6</span>;
}
Copy after login

//父元素设置相对点

<span style="color: #800000;">#search </span>{<span style="color: #ff0000;">
    position</span>:<span style="color: #0000ff;"> relative</span>;
}
Copy after login

//搜索框和按钮样式

<span style="color: #800000;">#search .search </span>{<span style="color: #ff0000;">
    width</span>:<span style="color: #0000ff;"> 446px</span>;<span style="color: #ff0000;">
    height</span>:<span style="color: #0000ff;"> 54px</span>;<span style="color: #ff0000;">
    position</span>:<span style="color: #0000ff;"> absolute</span>;<span style="color: #ff0000;">
    top</span>:<span style="color: #0000ff;"> 50%</span>;<span style="color: #ff0000;">
    left</span>:<span style="color: #0000ff;"> 50%</span>;<span style="color: #ff0000;">
    margin</span>:<span style="color: #0000ff;"> -27px 0 0 -296px</span>;<span style="color: #ff0000;">
    border-radius</span>:<span style="color: #0000ff;"> 10px</span>;<span style="color: #ff0000;">
    border</span>:<span style="color: #0000ff;"> 1px solid #666</span>;<span style="color: #ff0000;">
    font-size</span>:<span style="color: #0000ff;"> 24px</span>;<span style="color: #ff0000;">
    color</span>:<span style="color: #0000ff;"> #666</span>;<span style="color: #ff0000;">
    outline</span>:<span style="color: #0000ff;"> none</span>;<span style="color: #ff0000;">
    padding</span>:<span style="color: #0000ff;"> 0 10px</span>;
}<span style="color: #800000;">

#search .button </span>{<span style="color: #ff0000;">
    width</span>:<span style="color: #0000ff;"> 120px</span>;<span style="color: #ff0000;">
    height</span>:<span style="color: #0000ff;"> 54px</span>;<span style="color: #ff0000;">
    position</span>:<span style="color: #0000ff;"> absolute</span>;<span style="color: #ff0000;">
    top</span>:<span style="color: #0000ff;"> 50%</span>;<span style="color: #ff0000;">
    left</span>:<span style="color: #0000ff;"> 50%</span>;<span style="color: #ff0000;">
    cursor</span>:<span style="color: #0000ff;"> pointer</span>;<span style="color: #ff0000;">
    margin</span>:<span style="color: #0000ff;"> -27px 0 0 175px</span>;<span style="color: #ff0000;">
    font-size</span>:<span style="color: #0000ff;"> 22px</span>;<span style="color: #ff0000;">
    border-radius</span>:<span style="color: #0000ff;"> 10px</span>;<span style="color: #ff0000;">
    border</span>:<span style="color: #0000ff;"> none</span>;<span style="color: #ff0000;">
    color</span>:<span style="color: #0000ff;"> #666</span>;<span style="color: #ff0000;">
    font-weight</span>:<span style="color: #0000ff;"> bold</span>;<span style="color: #ff0000;">
    outline</span>:<span style="color: #0000ff;"> none</span>;
}
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

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
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
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.

The Role of HTML: Structuring Web Content The Role of HTML: Structuring Web Content Apr 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.

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