CSS 下拉菜单、提示工具、图片廊、计数器

一、CSS 下拉菜单:

CSS下拉菜单用于创建一个鼠标移动上去后显示下拉菜单的效果。示例:

<style>

.dropdown {

  position: relative;

  display: inline-block;

}

.dropdown-content {

  display: none;

  position: absolute;

  background-color: #f9f9f9;

  min-width: 160px;

  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);

  padding: 12px 16px;

}

.dropdown:hover .dropdown-content {

  display: block;

}

</style>

<div class="dropdown">

  <span>鼠标移动到我这!</span>

  <div class="dropdown-content">

    <p>唐诗</p>

    <p>宋词</p>

  </div>

</div>

可以使用任何的HTML元素来打开下拉菜单。使用容器元素(如<div>)来创建下来菜单的内容,并放在任何想放的位置上。使用<div>元素来包裹这些元素,并使用CSS来设置下拉内容的样式。.dropdowm类使用position:relative,将设置下拉菜单的内容放置在下拉按钮右下角位置;.dropdowm-content类中是实际的下拉菜单,默认是隐藏的,在鼠标移动到指定元素后会显示。

<style>

.dropbtn {

    background-color: BLUE;

    color: white;

    padding: 16px;

    font-size: 16px;

    border: none;

    cursor: pointer;

}

.dropdown {

    position: relative;

    display: inline-block;

}

.dropdown-content {

    display: none;

    position: absolute;

    background-color: #f9f9f9;

    min-width: 160px;

    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);

}

.dropdown-content a {

    color: black;

    padding: 12px 16px;

    text-decoration: none;

    display: block;

}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {

    display: block;

}

.dropdown:hover .dropbtn {

    background-color: #3e8e41;

}

</style>

<div class="dropdown">

  <button class="dropbtn">下拉菜单</button>

  <div class="dropdown-content">

    <a href="http://www.runoob.com">唐诗</a>

    <a href="http://www.runoob.com">宋词</a>

  </div>

</div>

二、CSS 提示工具:

提示工具(tooltip)在鼠标移动到指定元素后触发。示例:

<style>

.tooltip {

    position: relative;

    display: inline-block;

    border-bottom: 1px dotted black;

}

.tooltip .tooltiptext {

    visibility: hidden;

    width: 120px;

    background-color: black;

    color: #fff;

    text-align: center;

    border-radius: 6px;

    padding: 5px 0;

    /* 定位 */

    position: absolute;

    z-index: 1;

}

.tooltip:hover .tooltiptext {

    visibility: visible;

}

</style>

<body style="text-align:center;">

<div class="tooltip">鼠标移动到这

  <span class="tooltiptext">提示文本</span>

</div>

</body>

HTML使用容器类元素(如<div>)添加“tooltip”类,在鼠标移动到<div>上时显示提示信息。提示文本放在内联元素上(如<span>)并使用class = “tooltiptext”。CSS tooltip类使用position:relative,提示文本需要设置定位值position:absolute。tooltiptext类用于实际的提示文本。默认是隐藏的,在鼠标移动到元素显示。border-radius属性用于为提示框添加圆角。hover选择器用于在鼠标移动到指定元素<div>上时显示的提示。

定位提示工具:

<style>

.tooltip {

    position: relative;

    display: inline-block;

    border-bottom: 1px dotted black;

}

.tooltip .tooltiptext {

    visibility: hidden;

    width: 120px;

    background-color: black;

    color: #fff;

    text-align: center;

    border-radius: 6px;

    padding: 5px 0;

    

    /* 定位 */

    position: absolute;

    z-index: 1;

    top: -5px;

    left: 105%;

}

.tooltip:hover .tooltiptext {

    visibility: visible;

}

</style>

添加箭头:

<style>

.tooltip {

    position: relative;

    display: inline-block;

    border-bottom: 1px dotted black;

}

.tooltip .tooltiptext {

    visibility: hidden;

    width: 120px;

    background-color: black;

    color: #fff;

    text-align: center;

    border-radius: 6px;

    padding: 5px 0;

    position: absolute;

    z-index: 1;

    bottom: 150%;

    left: 50%;

    margin-left: -60px;

}

.tooltip .tooltiptext::after {

    content: "";

    position: absolute;

    top: 100%;

    left: 50%;

    margin-left: -5px;

    border-width: 5px;

    border-style: solid;

    border-color: black transparent transparent transparent;

}

.tooltip:hover .tooltiptext {

    visibility: visible;

}

</style>

<style>

.tooltip {

    position: relative;

    display: inline-block;

    border-bottom: 1px dotted black;

}

.tooltip .tooltiptext {

    visibility: hidden;

    width: 120px;

    background-color: black;

    color: #fff;

    text-align: center;

    border-radius: 6px;

    padding: 5px 0;

    position: absolute;

    z-index: 1;

    top: 150%;

    left: 50%;

    margin-left: -60px;

}

.tooltip .tooltiptext::after {

    content: "";

    position: absolute;

    bottom: 100%;

    left: 50%;

    margin-left: -5px;

    border-width: 5px;

    border-style: solid;

    border-color: transparent transparent black transparent;

}

.tooltip:hover .tooltiptext {

    visibility: visible;

}

</style>

<style>

.tooltip {

    position: relative;

    display: inline-block;

    border-bottom: 1px dotted black;

}

.tooltip .tooltiptext {

    visibility: hidden;

    width: 120px;

    background-color: black;

    color: #fff;

    text-align: center;

    border-radius: 6px;

    padding: 5px 0;

    position: absolute;

    z-index: 1;

    top: -5px;

    right: 110%;

}

.tooltip .tooltiptext::after {

    content: "";

    position: absolute;

    top: 50%;

    left: 100%;

    margin-top: -5px;

    border-width: 5px;

    border-style: solid;

    border-color: transparent transparent transparent black;

}

.tooltip:hover .tooltiptext {

    visibility: visible;

}

</style>

淡入效果:可以使用 CSS3 transition 属性及 opacity 属性来实现提示工具的淡入效果。示例:

<style>

.tooltip {

    position: relative;

    display: inline-block;

    border-bottom: 1px dotted black;

}

.tooltip .tooltiptext {

    visibility: hidden;

    width: 120px;

    background-color: black;

    color: #fff;

    text-align: center;

    border-radius: 6px;

    padding: 5px 0;

    position: absolute;

    z-index: 1;

    bottom: 100%;

    left: 50%;

    margin-left: -60px;

    

    /* 淡入 - 1秒内从 0% 到 100% 显示: */

    opacity: 0;

    transition: opacity 1s;

}

.tooltip:hover .tooltiptext {

    visibility: visible;

    opacity: 1;

}

</style>

三、CSS图片廊:

CSS创建图片廊示例:

<style>

div.img {

    margin: 5px;

    border: 1px solid #ccc;

    float: left;

    width: 180px;

}

div.img:hover {

    border: 1px solid #777;

}

div.img img {

    width: 100%;

    height: auto;

}

div.desc {

    padding: 15px;

    text-align: center;

}

</style>

</head>

<body>

<div class="responsive">

  <div class="img">

    <a target="_blank" href="http://static.runoob.com/images/demo/demo1.jpg">

      <img src="http://static.runoob.com/images/demo/demo1.jpg" alt="图片文本描述" width="300" height="200">

    </a>

    <div class="desc">这里添加图片文本描述</div>

  </div>

</div>

<div class="responsive">

  <div class="img">

    <a target="_blank" href="http://static.runoob.com/images/demo/demo2.jpg">

      <img src="http://static.runoob.com/images/demo/demo2.jpg" alt="图片文本描述" width="300" height="200">

    </a>

    <div class="desc">这里添加图片文本描述</div>

  </div>

</div>

<div class="responsive">

  <div class="img">

    <a target="_blank" href="http://static.runoob.com/images/demo/demo3.jpg">

      <img src="http://static.runoob.com/images/demo/demo3.jpg" alt="图片文本描述" width="300" height="200">

    </a>

    <div class="desc">这里添加图片文本描述</div>

  </div>

</div>

<div class="responsive">

  <div class="img">

    <a target="_blank" href="http://static.runoob.com/images/demo/demo4.jpg">

      <img src="http://static.runoob.com/images/demo/demo4.jpg" alt="图片文本描述" width="300" height="200">

    </a>

    <div class="desc">这里添加图片文本描述</div>

  </div>

</div>

</body>

四、CSS 图像透明/不透明:

CSS Opacity属性是W3C的CSS3建议的一部分。创建一个透明的图像:

img

{

opacity:0.4; filter:alpha(opacity=40);

 }

五、CSS 图像拼合技术:

图像拼合就是单个图像的集合。示例:

<style>

img.home {

    width: 46px;

    height: 44px;

    background: url(/images/img_navsprites.gif) 0 0;

}

img.next {

    width: 43px;

    height: 44px;

    background: url(/images/img_navsprites.gif) -91px 0;

}

</style>

</head>

<body>

<img class="home" src="/images/img_trans.gif"><br><br>

<img class="next" src="/images/img_trans.gif">

</body>

使用图像拼合创建一个导航列表:

<style>

#navlist{position:relative;}

#navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;}

#navlist li, #navlist a{height:44px;display:block;}

#home{left:0px;width:46px;}

#home{background:url('/images/img_navsprites.gif') 0 0;}

#prev{left:63px;width:43px;}

#prev{background:url('/images/img_navsprites.gif') -47px 0;}

#next{left:129px;width:43px;}

#next{background:url('/images/img_navsprites.gif') -91px 0;}

</style>

</head>

<body>

<ul id="navlist">

  <li id="home"><a href="/"></a></li>

  <li id="prev"><a href="/css/"></a></li>

  <li id="next"><a href="/css/"></a></li>

</ul>

</body>

六、CSS 媒体类型:

媒体类型允许指定文件如何在不同的媒体上呈现。@media规则允许在相同样式表为不同媒体设置不同的样式。示例:

<style>

@media screen

{

    p.test {font-family:verdana,sans-serif;font-size:14px;}

}

@media print

{

    p.test {font-family:times,serif;font-size:10px;}

}

@media screen,print

{

    p.test {font-weight:bold;}

}

</style>

</head>

<body>

<p class="test">唐诗三百首!!!</p>

</body>

媒体类型:

七、CSS 属性选择器:

具有特定属性的HTML元素样式不仅仅是class和id,比如:

<style>

[title]

{

color:blue;

}

</style>

<style>

[title=hi]

{

border:5px solid green;

}

</style>

<style>

[title~=hello]

{

color:blue;

}

</style>

<style>

input[type="text"]

{

width:150px;

display:block;

margin-bottom:10px;

background-color:yellow;

}

input[type="button"]

{

width:120px;

margin-left:35px;

display:block;

}

</style>

八、CSS 表单:

使用CSS来渲染HTML的表单元素:

<style>

input[type=text], select {

  width: 100%;

  padding: 12px 20px;

  margin: 8px 0;

  display: inline-block;

  border: 1px solid #ccc;

  border-radius: 4px;

  box-sizing: border-box;

}

input[type=submit] {

  width: 100%;

  background-color: #4CAF50;

  color: white;

  padding: 14px 20px;

  margin: 8px 0;

  border: none;

  border-radius: 4px;

  cursor: pointer;

}

input[type=submit]:hover {

  background-color: #45a049;

}

div {

  border-radius: 5px;

  background-color: #f2f2f2;

  padding: 20px;

}

</style>

<body>

<h3>使用 CSS 来渲染 HTML 的表单元素</h3>

<div>

  <form action="/action_page.php">

    <label for="fname">First Name</label>

    <input type="text" id="fname" name="firstname" placeholder="Your name..">

    <label for="lname">Last Name</label>

    <input type="text" id="lname" name="lastname" placeholder="Your last name..">

    <label for="country">Country</label>

    <select id="country" name="country">

      <option value="australia">Australia</option>

      <option value="canada">Canada</option>

      <option value="usa">USA</option>

    </select>

  

    <input type="submit" value="Submit">

  </form>

</div>

</body>

九、CSS计数器:

CSS计数器通过一个变量来设置,根据规则递增变量。CSS计数器使用到的属性:counter-reset - 创建或者重置计数器;counter-increment - 递增变量;content - 插入生成的内容;counter() 或 counters() 函数 - 将计数器的值添加到元素。要使用CSS计数器,得先使用counter-reset创建。示例:

<style>

body {

  counter-reset: section;

}

h2::before {

  counter-increment: section;

  content: "Section " counter(section) ": ";

}

</style>

嵌套计数器:

<style>

body {

  counter-reset: section;

}

h1 {

  counter-reset: subsection;

}

h1::before {

  counter-increment: section;

  content: "Section " counter(section) ". ";

}

h2::before {

  counter-increment: subsection;

  content: counter(section) "." counter(subsection) " ";

}

</style>

CSS计数器属性:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/166837.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

送水服务预约小程序内容该如何做

无论小区还是办公楼等场景&#xff0c;送水服务往往有较高需求&#xff0c;同时该服务属于长期稳定性的&#xff0c;因此对品牌来说&#xff0c;如何打造品牌获取更多用户及转化非常重要&#xff0c;然而在实际订水过程中&#xff0c;又会面临着一些难题&#xff1a; 1、品牌传…

轻量封装WebGPU渲染系统示例<19>- 使用GPU Compute材质多pass实现元胞自动机之生命游戏(源码)

当前示例源码github地址: https://github.com/vilyLei/voxwebgpu/blob/feature/rendering/src/voxgpu/sample/GameOfLifeMultiMaterialPass.ts 系统特性: 1. 用户态与系统态隔离。 细节请见&#xff1a;引擎系统设计思路 - 用户态与系统态隔离-CSDN博客 2. 高频调用与低频调…

ant design pro of vue怎么使用阿里iconfont

一 使用离线iconfont 首先需要生成图所有图标对应的js文件。如下图所示&#xff0c;将生成的js代码复制&#xff0c;在项目中创建一个js文件&#xff0c;将代码粘贴进去。这里我将js文件放在了src/assets/iconfont下面 然后&#xff0c;在main.js中引入文件&#xff0c;并进…

小程序订单中心path设置本次审核不通过,审核原因:小程序尚未发布,无法审核。

小程序尚未发布&#xff0c;无法审核。 先按照这篇文章把小程序审核通过&#xff0c;小程序版本审核未通过&#xff0c;需在开发者后台「版本管理—提交审核——小程序订单中心path」设置订单中心页path&#xff0c;请设置后再提交代码审核 小程序审核通过后&#xff0c;发布…

适合汽车音频系统的ADAU1977WBCPZ、ADAU1978WBCPZ、ADAU1979WBCPZ四通道 ADC,24-bit,音频

一、ADAU1977WBCPZ 集成诊断功能的四通道ADC&#xff0c;音频 24 b 192k IC&#xff0c;SPI 40LFCSP ADAU1977集成4个高性能模数转换器(ADC)&#xff0c;其直接耦合输入具有10 V rms性能。该ADC采用多位Σ-Δ架构&#xff0c;其连续时间前端能够实现低EMI性能。它可以直接连接…

【ElasticSearch系列-07】ES的开发场景和索引分片的设置及优化

ElasticSearch系列整体栏目 内容链接地址【一】ElasticSearch下载和安装https://zhenghuisheng.blog.csdn.net/article/details/129260827【二】ElasticSearch概念和基本操作https://blog.csdn.net/zhenghuishengq/article/details/134121631【三】ElasticSearch的高级查询Quer…

Leetcode_2:两数相加

题目描述&#xff1a; 给你两个 非空 的链表&#xff0c;表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的&#xff0c;并且每个节点只能存储 一位 数字。 请你将两个数相加&#xff0c;并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外&#xff…

Nginx缓存基础

1 nginx缓存的流程 客户端需要访问服务器的数据时&#xff0c;如果都直接向服务器发送请求&#xff0c;服务器接收过多的请求&#xff0c;压力会比较大&#xff0c;也比较耗时&#xff1b;而如果在nginx缓存一定的数据&#xff0c;使客户端向基于nginx的代理服务器发送请求&…

【c趣编程】输入一个整数,判断其有几位

目录 1题目要求&#xff1a; 2解题思路&#xff1a; 3代码如下所示&#xff1a; 4运行代码如下&#xff1a; 5总结&#xff1a; 1题目要求&#xff1a; 只用一个scanf输出一串数&#xff0c;不可以一个一个的输入并计数&#xff0c;那样太浪费时间了。 C语言是一门面向过…

面向对象高级

本期对应知识库&#xff1a;&#xff08;持续更新中&#xff01;&#xff09; 面向对象高级 (yuque.com) ​​​​​​​尚硅谷_宋红康_对象内存解析.pptx static 适用于公用变量 开发中&#xff0c;变量 经常把一些常量设置为静态static 例如 PI 方法 经常把工具类中的方…

NVM安装node后提示没有对应npm包(即:无法将“npm”项识别为 cmdlet、函数、脚本文件)

背景 windows11 node版本降低到v12.22.12后&#xff0c;执行&#xff1a;nvm -v npm -v npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写&#xff0c;如果 包括路径&#xff0c;请确保路径正确&#xff0c;然后再试一次。 所在位置 …

Element-Plus表单label实现两端对齐(左右对齐)

项目场景&#xff1a; 提示&#xff1a;这里简述项目相关背景&#xff1a; 在使用Element-Plus的form的时候,label只有左右,居中对齐&#xff0c;缺少两端对齐的选项 故研究一下如何实现&#xff0c;其他方法也试过&#xff0c;都没效果&#xff0c;我在别人的基础上又研究了一…