【问题标题】:Css button doesn't respond when hovered over将鼠标悬停在 Css 按钮上时没有响应
【发布时间】:2015-02-09 00:26:33
【问题描述】:

所以我让按钮工作,直到我添加了一个名为“dark-blueright”的新块 div 并将其定位在“light-blue”下。

/*
▒█▀▀▀█ ▀▀█▀▀ ▒█░░▒█ ▒█░░░ ▒█▀▀▀   ▒█▀▀█ ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀▀ ▀▀█▀▀ 
░▀▀▀▄▄ ░▒█░░ ▒█▄▄▄█ ▒█░░░ ▒█▀▀▀   ▒█▄▄▀ ▒█▀▀▀ ░▀▀▀▄▄ ▒█▀▀▀ ░▒█░░ 
▒█▄▄▄█ ░▒█░░ ░░▒█░░ ▒█▄▄█ ▒█▄▄▄   ▒█░▒█ ▒█▄▄▄ ▒█▄▄▄█ ▒█▄▄▄ ░▒█░░ 

*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

/*
▒█▀▀▀█ ▀▀█▀▀ ▒█░░▒█ ▒█░░░ ▒█▀▀▀   ▒█▀▀▀█ ▒█░▒█ ▒█▀▀▀ ▒█▀▀▀ ▀▀█▀▀ 
░▀▀▀▄▄ ░▒█░░ ▒█▄▄▄█ ▒█░░░ ▒█▀▀▀   ░▀▀▀▄▄ ▒█▀▀█ ▒█▀▀▀ ▒█▀▀▀ ░▒█░░ 
▒█▄▄▄█ ░▒█░░ ░░▒█░░ ▒█▄▄█ ▒█▄▄▄   ▒█▄▄▄█ ▒█░▒█ ▒█▄▄▄ ▒█▄▄▄ ░▒█░░ 
*/

@font-face {
	font-family: headingf;
	src: url(header-font.ttf);	
}
@font-face {
	font-family: mainf;
	src: url(main-font.ttf);	
}
@font-face {
	font-family: iconf;
	src: url(icon.ttf);	
}
.background_colour {
	background-color: #c6cdd1;
	height: 1700px;
	position: relative;
    left: 0px;
    top: 0px;
	z-index: -2;
}
.iconsf {
	font-family: iconf;
	font-size: 40px;
	text-indent: 40px;
	float: left;
}
.light-blue {
	width: 1000px;
	height: 500px;
	position: relative;
	background-color: #68cef3;
}
.dark-blueright {
	width: 1000px;
	height: 1000px;
	background-color: #00aae7;
	position: absolute;
    left: 0px;
    top: 0px;
	z-index: -1;
	
}
.header-text {
	font-family: headingf;
	font-size: 170px;
	position: inherit;
	text-align: center;
	top: 80px;
	color: #ffffff;
	letter-spacing: 10px 
}
.welcome-text {
	font-family: mainf;
	font-size: 70px;
	position: inherit;
	text-align: center;
	top: 60px;
	color: #ffffff;
	letter-spacing: 10px 
}
.button-style1 {
	position: relative;
	top: 220px;
	left: 400px;
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #00a9e7), color-stop(1, #00a9e7) );
	background:-moz-linear-gradient( center top, #00a9e7 5%, #00a9e7 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00a9e7', endColorstr='#00a9e7');
	background-color:#00a9e7;
	-webkit-border-top-left-radius:0px;
	-moz-border-radius-topleft:0px;
	border-top-left-radius:0px;
	-webkit-border-top-right-radius:0px;
	-moz-border-radius-topright:0px;
	border-top-right-radius:0px;
	-webkit-border-bottom-right-radius:0px;
	-moz-border-radius-bottomright:0px;
	border-bottom-right-radius:0px;
	-webkit-border-bottom-left-radius:0px;
	-moz-border-radius-bottomleft:0px;
	border-bottom-left-radius:0px;
	text-indent:-20px;
	border:1px solid #ffffff;
	display:inline-block;
	color:#ffffff;
	font-family:mainf;
	font-size:15px;
	font-weight:bold;
	font-style:normal;
	height:80px;
	line-height:80px;
	width:200px;
	text-decoration:none;
	text-align:center;
}
.button-style1:hover {
	opacity: 0.6;
}
.button-style1:active {
	opacity: 1;
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
	<div class="background_colour">
	<div class="dark-blueright">
	</div>
		<div class="light-blue">
			<div class="header-text">
			Oh. Hello
			</div>
			<div class="welcome-text">
			welcome
			</div>
			<a href="#" class="button-style1"><span class="iconsf">r</span>Goto art</a>
		</div> 
	</div>
</body>
</html>
	

我希望按钮在悬停时改变不透明度,它确实做到了。但是我在 css 中的定位技术很糟糕,无法找到帮助研究。

【问题讨论】:

  • 那么问题是什么?
  • 不清楚你在问什么。悬停时的不透明度问题还是定位问题?此外,您的问题中的代码似乎比与该问题相关的代码要多得多。将其减少到 minimal example 确实会有所帮助
  • 问题是,如何使按钮悬停功能起作用。它与“dark-blueright”的定位不同

标签: html css positioning opacity overlapping


【解决方案1】:

您在类 .background_colour 上的 z-index 有误,我已更正了该问题,现在悬停效果正在发挥作用。

/*
▒█▀▀▀█ ▀▀█▀▀ ▒█░░▒█ ▒█░░░ ▒█▀▀▀   ▒█▀▀█ ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀▀ ▀▀█▀▀ 
░▀▀▀▄▄ ░▒█░░ ▒█▄▄▄█ ▒█░░░ ▒█▀▀▀   ▒█▄▄▀ ▒█▀▀▀ ░▀▀▀▄▄ ▒█▀▀▀ ░▒█░░ 
▒█▄▄▄█ ░▒█░░ ░░▒█░░ ▒█▄▄█ ▒█▄▄▄   ▒█░▒█ ▒█▄▄▄ ▒█▄▄▄█ ▒█▄▄▄ ░▒█░░ 

*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

/*
▒█▀▀▀█ ▀▀█▀▀ ▒█░░▒█ ▒█░░░ ▒█▀▀▀   ▒█▀▀▀█ ▒█░▒█ ▒█▀▀▀ ▒█▀▀▀ ▀▀█▀▀ 
░▀▀▀▄▄ ░▒█░░ ▒█▄▄▄█ ▒█░░░ ▒█▀▀▀   ░▀▀▀▄▄ ▒█▀▀█ ▒█▀▀▀ ▒█▀▀▀ ░▒█░░ 
▒█▄▄▄█ ░▒█░░ ░░▒█░░ ▒█▄▄█ ▒█▄▄▄   ▒█▄▄▄█ ▒█░▒█ ▒█▄▄▄ ▒█▄▄▄ ░▒█░░ 
*/

@font-face {
	font-family: headingf;
	src: url(header-font.ttf);	
}
@font-face {
	font-family: mainf;
	src: url(main-font.ttf);	
}
@font-face {
	font-family: iconf;
	src: url(icon.ttf);	
}
.background_colour {
	background-color: #c6cdd1;
	height: 1700px;
	position: relative;
    left: 0px;
    top: 0px;
	z-index: 0;
}
.iconsf {
	font-family: iconf;
	font-size: 40px;
	text-indent: 40px;
	float: left;
}
.light-blue {
	width: 1000px;
	height: 500px;
	position: relative;
	background-color: #68cef3;
}
.dark-blueright {
	width: 1000px;
	height: 1000px;
	background-color: #00aae7;
	position: absolute;
    left: 0px;
    top: 0px;
	z-index: -1;
	
}
.header-text {
	font-family: headingf;
	font-size: 170px;
	position: inherit;
	text-align: center;
	top: 80px;
	color: #ffffff;
	letter-spacing: 10px 
}
.welcome-text {
	font-family: mainf;
	font-size: 70px;
	position: inherit;
	text-align: center;
	top: 60px;
	color: #ffffff;
	letter-spacing: 10px 
}
.button-style1 {
	position: relative;
	top: 220px;
	left: 400px;
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #00a9e7), color-stop(1, #00a9e7) );
	background:-moz-linear-gradient( center top, #00a9e7 5%, #00a9e7 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00a9e7', endColorstr='#00a9e7');
	background-color:#00a9e7;
	-webkit-border-top-left-radius:0px;
	-moz-border-radius-topleft:0px;
	border-top-left-radius:0px;
	-webkit-border-top-right-radius:0px;
	-moz-border-radius-topright:0px;
	border-top-right-radius:0px;
	-webkit-border-bottom-right-radius:0px;
	-moz-border-radius-bottomright:0px;
	border-bottom-right-radius:0px;
	-webkit-border-bottom-left-radius:0px;
	-moz-border-radius-bottomleft:0px;
	border-bottom-left-radius:0px;
	text-indent:-20px;
	border:1px solid #ffffff;
	display:inline-block;
	color:#ffffff;
	font-family:mainf;
	font-size:15px;
	font-weight:bold;
	font-style:normal;
	height:80px;
	line-height:80px;
	width:200px;
	text-decoration:none;
	text-align:center;
}
.button-style1:hover {
	opacity: 0.6;
}
.button-style1:active {
	opacity: 1;
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
	<div class="background_colour">
	<div class="dark-blueright">
	</div>
		<div class="light-blue">
			<div class="header-text">
			Oh. Hello
			</div>
			<div class="welcome-text">
			welcome
			</div>
			<a href="#" class="button-style1"><span class="iconsf">r</span>Goto art</a>
		</div> 
	</div>
</body>
</html>
	

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多