热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

javascript冷门吗_不写JavaScript,教你只用纯HTML做出几个实用网页效果

在我们以往看到的页面效果中,很多是需要JS搭配使用的,那如果不写JS你知道如何实现吗?在本文中,将介绍如何使用纯HTML打造
3e25011b7a52c08d7796ee0ae2f43425.png

在我们以往看到的页面效果中,很多是需要JS搭配使用的,那如果不写JS你知道如何实现吗?

在本文中,将介绍如何使用纯HTML打造属于自己的实用网页效果。

1. 折叠手风琴

使用Details和Summary标签可以创建没有Javascript代码的可折叠手风琴。

效果:

498d493821cafb6c68f3f4d6fc992fb1.gif

HTML


Languages Used

This page was written in HTML and CSS. The CSS was compiled from SASS. Regardless, this could all be done in plain HTML and CSS



How it Works

Using the sibling and checked selectors, we can determine the styling of sibling elements based on the checked state of the checkbox input element.


CSS

* {font-size: 1rem;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
details {border: 1px solid #aaa;border-radius: 4px;padding: .5em .5em 0;
}summary {font-weight: bold;margin: -.5em -.5em 0;padding: .5em;
}details[open] {padding: .5em;
}details[open] summary {border-bottom: 1px solid #aaa;margin-bottom: .5em;
}

浏览器支持:

3667f8832d561e45208c58b736c99fb3.png

2. 进度条

该Meter和Progress 的元素标签的基础上,你可以调整属性呈现在屏幕上的进度条。进步有两个属性:maxvalue校准进度条,而Meter标签提供了更多的定制属性。

效果:

70c0e92e7ebbe285f7f66e54cb63d193.png

HTML:

at 50/100


70%

CSS:

body {margin: 50px;
}label {padding-right: 10px;font-size: 1rem;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

浏览器支持:

4bcd7fbfa1659951ae8584e3748121c2.png

3. 更多输入类型

在定义输入元素时,您要知道现代浏览器已经允许您指定足够多的输入类型了。除了你应该已经知道text,email,password,number这些类型外,还有下面的这些。

  • date 将显示本机日期选择器
  • datetime-local 更丰富的日期和时间选择器
  • month 友好的月份选择器
  • tel会让你输入一个电话号码。在移动浏览器上打开它,弹出的键盘将发生变化,同样的email也是如此。
  • search 将输入文本框设置为友好的搜索样式。

效果:

3324d38f28071181f0b5913f675e7f55.gif

HTML:






CSS:

input, label {display:block; margin: 5px;}
input {margin-bottom:18px;}

各种新输入类型的MDN文档非常广泛且信息量很大。此外,检查移动输入类型以了解用户在移动浏览器上时这些输入元素的键盘行为。

4. 视频和音频

videoaudio元素虽然现在已经成为HTML规范的一部分,但是你一样会惊讶于你可以使用video标签在屏幕上渲染出一个体面的视频播放器。

视频标记中值得注意的一些属性包括:

  • poster 下载视频时要显示封面的URL
  • preload 是否在页面加载时预加载整个视频
  • autoplay 视频是否应该在页面加载后自动播放

浏览器支持:

62bb0a65bff3f5c918e0f8df60a0bd16.png

5. 校对文本

当你想显示历史编辑及校对的情况时,blockquote,delins元素标签可以派上用场了。

示例:

7ef26c3b4f2494c5914618f150e46541.png

HTML:

There is nothing no code either good or bad, but thinking running it makes it so.

CSS:

del {text-decoration: line-through;background-color: #fbb;color: #555;
}ins {text-decoration: none;background-color: #d4fcbc;
}blockquote {padding-left: 15px;line-height: 30px;border-left: 3px solid #d7d7db;font-size: 1rem;background: #eee;width: 200px;
}

6.更统一的引号

由于中英文引号的不同,使用标记可以让您很好的解决这个问题,它可使你的内容在大多数浏览器上更一致地呈现引号。

b0c88b3137f946a64e9296cb0ad9daca.png

HTML:

Don Corleone said I'm gonna make him an offer he can't refuse. Okay? I want you to leave it all to me. Go on, go back to the party.


Don Corleone said "I'm gonna make him an offer he can't refuse. Okay? I want you to leave it all to me. Go on, go back to the party."

CSS:

body {margin: 50px;
}q {font-style: italic;color: #000000bf;
}

7. 键盘标签

标签应该是一个少为人知的冷门标签,但这个能使用更好的方式来说明组合键的样式。

0c8485906a2dcaa3886fee3a6b548583.png

HTML:

I know that CTRL+C and CTRL+V a are like the most used key combinations

CSS:

body {margin: 50px;
}kbd {display: inline-block;margin: 0 .1em;padding: .1em .6em;font-size: 11px;line-height: 1.4;color: #242729;text-shadow: 0 1px 0 #FFF;background-color: #e1e3e5;border: 1px solid #adb3b9;border-radius: 3px;box-shadow: 0 1px 0 rgba(12,13,14,0.2), 0 0 0 2px #FFF inset;white-space: nowrap;
}

8.使用HTML共享代码

使用figcaption pre code标签,您可以使用纯HTML和CSS呈现出不错的代码片段。

ad3eda6317153e3555735038001359cc.png

HTML:

Defining a css color property for a class called 'golden'
.golden {color: golden;}

CSS:

pre {background-color: #ffbdbd;
}

这篇文章也只是抛砖引玉,如果您有更多私藏的使用技巧,不妨也贴出来分享给大家。同时欢迎访问葡萄城的原博客与我交流。

不用JS,教你只用纯HTML做出几个实用网页效果 - 葡萄城技术团队 - 博客园​www.cnblogs.com
6a2e27a191f0d38a351c376e48e7d048.gif

另外,如果您不仅仅限于以上的效率,希望有更完整的动态功能。如:您希望在您的页面中加入Excel功能,不妨尝试纯前端表格控件SpreadJS,相信它能为您的应用增色不少。

原文出处:https://blog.bitsrc.io/pure-html-widgets-for-your-web-application-c9015563af7a



推荐阅读
author-avatar
mobiledu2502890207
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有