This article summarizes several rules and practices for reconstructing HTML to improve Web application design from three perspectives: good structure, effectiveness, and layout, combined with past project development experience. Part of the reference is from "Reconstructing HTML to Improve Web Application Design".
Refactoring. What is refactoring? Why refactor.
Refactoring is a process of making small changes without changing the behavior of the program. It is a process of gradually improving the code. Removing bad code that has accumulated over time to create code that is clearer and easier to maintain, debug, and add new features cannot just happen late in the coding process, or even when you realize your code is no longer viable. When it is necessary to rewrite, it should be gradually accumulated and modified from the beginning of development. In the past, due to the randomness of daily coding, problems accumulated and gradually spread, and in the end we had to start over. If time cannot withstand the need to reinvent the wheel, you have no choice. The only option is to refactor.
No matter what you do, don’t neglect improvement because of the pursuit of perfection. If you have enough time to do a little refactoring, then do a little. You can do more in the future when you have time. Although the overall reconstruction design is eye-catching and unforgettable, without daily accumulation, how can we achieve huge achievements? Your goal should be to have new changes to your code every day. After a few months of persistence, I believe we can all have clear code with pride.
Well-formed
The first task in converting markup to conform to modern standards is to achieve well-formation. Well-structured ensures the uniqueness of the DOM's operable document tree structure, thus becoming the basis for reliable cross-browser JavaScript code. For a chaotic page, any reliable automated processing or testing is very difficult to guarantee. Secondly, the display effect of the browser page is even more unpredictable. For scrambled pages, different browsers use different methods to supplement the correct fragments and correct errors. Therefore, when it comes to reconstructing HTML, the most important thing is undoubtedly to make the page well-structured.
To be well-formed, most websites must do at least or all of the following:
In view of the mistakes that were easily made in the past due to personal programming habits and randomness, thinking from a well-structured perspective, there are a few points that need special attention when building HTML in the future.
Several key points to better achieve good structure:
失败经历: 为了实现导航效果,一开始没有考虑内容语义,无意中将导航主项和相关联的菜单分开,在利用css中的相对定位,设定top和left属性,将相关菜单移动到相关的主项下。这样会导致一个严重的问题。一旦将不同页面放置在不同的分辨率的屏幕上,菜单就会错位。就是说,针对不同分辨率的屏幕,还要设计不同的top和left属性。
<div class = "nav"> <div class="nav01">菜单一</div><div class="nav02">菜单二</div><div class="nav03">菜单三</div></div><div class = "menu"> <div class="menu01">子菜单一</div><div class="menu02">子菜单二</div><div class="menu03">子菜单三</div></div> Copy after login 优化设计过的导航HTML结构,组合主菜单和子菜单:
<nav> <ul class="clear"> <li class="first"><a href="#">菜单一</a></li> <li> <span class="Darrow"></span> <a href="#">菜单二</a> <dl> <dt><span class="arrow"></span></dt> <dd><a href="#">子菜单一</a></dd><dd><a href="#">子菜单二</a></dd><dd><a href="#">子菜单三子菜单三</a></dd> </dl> </li> <li> <span class="Darrow"></span> <a href="#">菜单三</a> <dl> <dt><span class="arrow"></span></dt> <dd><a href="#">子菜单一</a></dd><dd><a href="#">子菜单二</a></dd><dd><a href="#">子菜单三子菜单三</a></dd> </dl> </li> </ul></nav> Copy after login
|
The purpose of writing HTML is not for a certain structure or page appearance, but for how to better present the content. Therefore, before writing HTML, be sure to think about which semantic elements should be used for this content. .
Proper HTML is great for handling cross-browser issues. After you get the web design, before you start building the web application, you must stop thinking about how the page looks and start thinking about what the page means.
2. Replace table layout
CSS-based pages are smaller and simpler than table-based pages.
a) Easier to write and edit, faster to download,
b) Save bandwidth by switching to CSS. At the same time, the external css files can be cached and reused, without having to download them again every time the page is downloaded.
Instead of abusing the table element used to present tabular data and using table layout, you can consider the frequently used column layout:
1) Two columns, left There is a fixed-width sidebar on the side, and a flexible-width content column on the right
2) Three columns, a fixed-width sidebar on the left and right, and content in the middle.
| <🎜>
3,内容与样式分离
当然我们的页面也需要漂亮的外观,以帮助我们在竞争中脱颖而出。这可以通过在独立的CSS样式中放置有关表现的信息来实现。CSS用来描述网页的外观,而浏览器可以自由选择不同的样式表或是修改过的样式表。实际上,你可以为不同的浏览器随意发送不同的样式表,也可以为它们独特的能力量身定制。这是响应式设计的基本实现方法。 “响应式网页不仅仅是响应不同类型的设备,而且需要响应不同的用户需求。响应式的初衷是为了让信息更好的传递交流,让所有人无障碍的获取信息,同时这也是 Web 的初衷。” 出于方便或者是自身的编码习惯,在修改某种被更改的需求的样式代码时候,我们很容易在html代码中直接镶嵌样式代码。这样的做法除了更快的完成你暂时的任务之外没有任何好处。
4,使用CSS定位替代框架
网站使用框架的理由实际上就两种: (1)为所有页面引入相同的静态内容,而不用单独编辑每个页面。例如导航,网页头部尾部。也就是说,单独的非框架页面可能比相应的框架页面更耗带宽,因为框架内容每次都要给客户端重新发送内容。 (2)显示多栏外观。例如Java API,包含包和类的列表,主体内容 然而,过多使用框架将降低可用性: (1)难以标记数千或返回指定页面 (2)难以保存和打印页面 (3)过多的滚动条占据屏幕的宝贵空间 在每一个页面上都有导航和其他相同或几乎相同的内容,对网站来说是非常普遍的,使用CSS取代框架,关键在于设立对应每个框架的div,每个div内容是对应框架里的文档内容。然而,这样做的问题在于,它违反了DRY原则(Don't Repeat Youself,别重复你自己),对于相同的内同,虽然有时候只是很小的变化,但还是需要不断在这一页那一页重复出现。重复内容通常也是代码的坏味道。框架在静态页面上避免恶劣不必要的重复,我提倡清晰,可维护的代码,在不损害用户界面的前提下,我更远一选择难看的代码而不是难看的用户界面。日常中原始的HTML是重复的,但不是我们必须编辑的,很多时候我们可以通过后台自动生成重复内容。
5,正确标记列表 正确标记列表能够提升可访问性,通常我们子啊列表中实现跳转和导航。 大部分浏览器给列表以及列表中的项目都制定特定的外观,通常表现为缩进和项目符号,可能不是你所需要的外观,因此很容易在搭建html的时候忽略它们的存在,放弃使用正确列表标记,而使用语义较差的标签,实现同样的效果。根据需求,你能够通过CSS可以容易地修复这些特定的外观。下面整理了开发中常用的CSS样式修改规则:
/*删除项目符号*/ ul{ list-style-type:none; }/*载入外部图片自定义项目符号*/ ul li { list-style-image : url(images/str.gif);}/*去掉缩进的规则*/ ul{ margin-left : 0px; padding-left :0px;}/*把项目排成一行*/ ul,li{ display: inline; margin:0px; padding: 0px;}/*在列表项之间插入逗号*/ ul li:after{ content : ",";}/*制定项目的宽度,超出时显示省略号*/ div.titleholder { font-size: 8pt; width: 100px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;} Copy after login 然而,lu应用与列表上,blockquote应用在应用上。blockquote与ul相比,整理文本缩进更强大,更准确。
6,为图片添加width和height属性 width和height属性能让浏览器更快地样式化页面并展现给用户。但注意,这样做,对页面的显示速度有提升,但对下载速度并没有帮助。 出于一般项目开发触觉,改变图片的尺寸意味着要修改HTML,否则图片会奇怪地变大变小。如果需要经常改变图片,比如设计页面是,最好是在最后的阶段插入确定的宽度和高度。
Related labels:
source:php.cn
Previous article:CSS floating float_html/css_WEB-ITnose
Next article:If you have html5, why should you learn xhtml, xml_html/css_WEB-ITnose
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
Latest Articles by Author
Latest Issues
How to display the mobile version of Google Chrome
Hello teacher, how can I change Google Chrome into a mobile version?
From 2024-04-23 00:22:19
0
11
2344
There is no output in the parent window
document.onclick = function(){ window.opener.document.write('I am the output of the child ...
From 2024-04-18 23:52:34
0
1
1853
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|