学习要点:
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>; }

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc


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

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
