"#LockerButton:hover{background-color:rgba(195,195,195,0.4)}"没有效果
时间: 2023-07-19 10:29:37 浏览: 57
如果你在 QSS 样式表中设置了 `:hover` 伪类,但是没有生效,可能有以下几个原因:
1. 没有正确设置样式表
请确保你正确设置了样式表。在 Qt 中,可以通过使用 `setStyleSheet` 函数将样式表应用到控件上。例如:
```cpp
LockerButton->setStyleSheet("#LockerButton:hover{background-color:rgba(195,195,195,0.4)}");
```
在上面的代码中,`LockerButton` 是一个指向 `QAbstractButton` 控件的指针,`setStyleSheet` 函数被用来设置 `:hover` 伪类的样式。
2. 控件没有悬停
`:hover` 伪类只有在控件处于悬停状态时才会生效。请确保你的控件支持悬停。对于 `QAbstractButton` 控件,例如 `QPushButton`,默认情况下支持悬停。
3. 样式表选择器不正确
请确保你的样式表选择器与控件的对象名称相匹配。在上面的例子中,控件的对象名称应该为 `LockerButton`。如果你的控件对象名称不同,请使用正确的名称来设置样式表选择器。
4. 样式表属性不正确
请确保你的样式表属性正确设置。在上面的例子中,`background-color` 属性被设置为 `rgba(195,195,195,0.4)`。请确保这个属性能够正确设置到你的控件上。
相关问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>键盘打字</title> <style> /* 基本界面样式 */ *{ /*margin: 0;*/ padding: 0; box-sizing: border-box; list-style: none; /*outline: 1px dashed purple;*/ } body{ display: flex; height: 100vh; justify-content: center;/* 水平居中*/ align-items: center; background-color: #000;/* 随内容撑开且垂直居中 */ } .keyboard{ outline-width: 3px; /*background-color: red;*/ } ul.row{ display: flex;/* 弹性布局 */ /* /*height: 300px; */ } ul.row li{ outline-width: 2px; width: 3em;/*em是根据当前字体大小*/ height: 3em; text-align: center; line-height: 3em; border-radius: .4em; color: rgba(0, 0, 0, 0.7); letter-spacing: 1px; margin: 0.4em; } /*设置宽度*/ #tab{ width: 5em; } #caps{ width: 6em; } #leftShift{ width: 8em; } #enter{ width: 6em; } #rightShift{ width: 8em; } #back{ width: 5em; } /*设置颜色*/ .little{ background-color: crimson; /*深红色的*/ border: 2px solid crimson; } .little.selected{ background-color: transparent; color: crimson; } .ring{ background-color: coral; /*珊瑚红*/ border:2px solid coral; } .ring.selected{ background-color: transparent; color: coral; } .middle{ background-color:darkorange; /*深橙色*/ border: 2px solid darkorange; } .middle.selected{ background-color: transparent; color: darkorange; } .forefinger1st{ background-color: gold; border: 2px solid gold; } .forefinger1st.selected{ background-color: transparent; color: gold; } .forefinger2nd{ background-color: khaki;
好的,您的代码大概是一个键盘打字的 HTML 页面,并且您想要了解如何选中某些 css 样式。
如果您想选中某些 css 样式,您可以使用以下方式:
1. 通过元素标签名选中样式:
```css
ul {
/* 选中所有 <ul> 元素 */
}
```
2. 通过 class 名称选中样式:
```css
.keyboard {
/* 选中 class 名称为 keyboard 的元素 */
}
```
3. 通过 id 名称选中样式:
```css
#caps {
/* 选中 id 名称为 caps 的元素 */
}
```
4. 通过属性选择器选中样式:
```css
li[type="button"] {
/* 选中所有 type 属性值为 button 的 <li> 元素 */
}
```
5. 通过伪类选择器选中样式:
```css
li:hover {
/* 当鼠标悬停在 <li> 元素上时选中 */
}
```
以上是一些常见的选中 css 样式的方式,您可以根据您的具体需求来选择不同的方式。希望可以帮到您!
请帮助我把每一行代码写上注释:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- <link href="./1321.css" type="text/css"/> --> <title>导航栏</title> <style> *{ margin: 0; padding: 0; box-sizing:border-box; font-family:"Poppins",sans-serif; } .cantainer{ width:100%; height:100vh; background-color: #e092a1; background-size: 100% 100%; display:flex; align-items: center; justify-content: center; } nav{ background: #fff; border-radius: 50px; padding: 10px; box-shadow: 0 25px 20ox -20px rgba(0 , 0, 0, 0.4); } nav ul li{ list-style: none; display: inline-block; padding: 13px 35px; margin: 10px; font-size: 18px; font-weight: 500; color: #777; cursor: pointer; position: relative; z-index: 2; transform: color 0.5s; } nav ul li::after{ content:''; background:#f44566; width: 100%; height: 100%; border-radius: 30px; position: absolute; top: 100%; left: 50%; transform: translate(-50% ,-50%); z-index: -1; opacity: 0; transition:top 0.5s,opacity 0.5s; } nav ul li:hover{ color: #fff; } nav ul li:hover:after{ top:50%; opacity: 1; } a{ text-decoration: none; color: #706363; text-decoration: none; } .enen{ width: 10%; height: 10%; } </style> </head> <body> <div class="cantainer"> <nav> <ul> <li ><a href="">1</a></li> <li ><a href="">2</a></li> <li ><a href="">3</a></li> <li ><a href="">4</a></li> <li ><a href="">5</a></li> <li ><a href="" >6</a></li> </ul> </nav> </div> </body> </html>
```
<!-- 这是注释内容,不会被浏览器解析 -->
<!DOCTYPE html> <!-- 声明文档类型为 HTML -->
<html lang="en"> <!-- 标记开始位置,指定语言为英语 -->
<head> <!-- 标记文档头部开始位置 -->
<meta charset="UTF-8"> <!-- 指定字符集为 UTF-8 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- 指定使用最新的 IE 浏览器模式 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 设置视口宽度与初始缩放比例 -->
<!-- <link href="./1321.css" type="text/css"/> --> <!-- 注释掉的链接标签 -->
<title>导航栏</title> <!-- 设置文档标题 -->
<style> <!-- 开始定义 CSS 样式 -->
*{ <!-- 设置所有元素的 margin 与 padding 属性为 0,盒子模型为 border-box,字体为 Poppins -->
margin: 0;
padding: 0;
box-sizing:border-box;
font-family:"Poppins",sans-serif;
}
.cantainer{ <!-- 容器样式设置,宽度为 100%,高度为 100vh,背景色为 #e092a1,背景图为 100% 宽度 100% 高度 -->
width:100%;
height:100vh;
background-color: #e092a1;
background-size: 100% 100%;
display:flex;
align-items: center;
justify-content: center;
}
nav{ <!-- 导航栏样式设置,背景色为 #fff,圆角为 50px,内边距为 10px,阴影为 0 25px 20ox -20px rgba(0 , 0, 0, 0.4) -->
background: #fff;
border-radius: 50px;
padding: 10px;
box-shadow: 0 25px 20ox -20px rgba(0 , 0, 0, 0.4);
}
nav ul li{ <!-- 导航栏中的列表项样式设置,去除默认列表样式,设置为行内块元素,内边距为 13px 35px,外边距为 10px,字体大小为 18px,字体重量为 500,颜色为 #777,鼠标指针样式为手型,定位方式为相对定位,层级为 2,设置颜色变化过渡效果 -->
list-style: none;
display: inline-block;
padding: 13px 35px;
margin: 10px;
font-size: 18px;
font-weight: 500;
color: #777;
cursor: pointer;
position: relative;
z-index: 2;
transform: color 0.5s;
}
nav ul li::after{ <!-- 导航栏中的列表项悬停后的样式设置,设置伪元素 after,背景色为 #f44566,宽度与高度为 100%,圆角为 30px,定位方式为绝对定位,距离顶部为 100%,距离左侧为 50%,通过 translate 偏移自身宽高的一半,层级为 -1,不透明度为 0,设置 top 与 opacity 变化过渡效果 -->
content:'';
background:#f44566;
width: 100%;
height: 100%;
border-radius: 30px;
position: absolute;
top: 100%;
left: 50%;
transform: translate(-50% ,-50%);
z-index: -1;
opacity: 0;
transition:top 0.5s,opacity 0.5s;
}
nav ul li:hover{ <!-- 导航栏中的列表项悬停后的样式设置,字体颜色为白色 -->
color: #fff;
}
nav ul li:hover:after{ <!-- 导航栏中的列表项悬停后的样式设置,after 伪元素距离顶部为 50%,不透明度为 1 -->
top:50%;
opacity: 1;
}
a{ <!-- 设置链接样式,文本装饰为无,颜色为 #706363 -->
text-decoration: none;
color: #706363;
text-decoration: none;
}
.enen{ <!-- 定义一个类名为 enen 的样式,宽度与高度均为 10% -->
width: 10%;
height: 10%;
}
</style> <!-- CSS 样式定义结束 -->
</head> <!-- 标记文档头部结束位置 -->
<body> <!-- 标记文档主体开始位置 -->
<div class="cantainer"> <!-- 容器标签开始位置 -->
<nav> <!-- 导航栏标签开始位置 -->
<ul> <!-- 列表标签开始位置 -->
<li ><a href="">1</a></li> <!-- 列表项 1,链接地址为空,文本为 1 -->
<li ><a href="">2</a></li> <!-- 列表项 2,链接地址为空,文本为 2 -->
<li ><a href="">3</a></li> <!-- 列表项 3,链接地址为空,文本为 3 -->
<li ><a href="">4</a></li> <!-- 列表项 4,链接地址为空,文本为 4 -->
<li ><a href="">5</a></li> <!-- 列表项 5,链接地址为空,文本为 5 -->
<li ><a href="" >6</a></li> <!-- 列表项 6,链接地址为空,文本为 6 -->
</ul> <!-- 列表标签结束位置 -->
</nav> <!-- 导航栏标签结束位置 -->
</div> <!-- 容器标签结束位置 -->
</body> <!-- 标记文档主体结束位置 -->
</html> <!-- 标记结束位置 -->
```