第 31 章 项目实战-PC 端固定布局[3]
学习要点:
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>
//可以直接设置宽度为 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>; }
如果使用 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>; }
当我们故意缩小分辨率时,小于 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>; }
对于大于 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>; }
三.搜索框
我们希望在大图中间安插一个搜索框,先安插一个半透明的区块。
//创建一个区块
<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>
//将区块半透明且居中
<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>; }
//父元素设置相对点
<span style="color: #800000;">#search </span>{<span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;"> relative</span>; }
//搜索框和按钮样式
<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>; }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

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

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

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

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

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...
