【发布时间】:2021-02-06 22:59:48
【问题描述】:
我正在尝试使用 CSS 和 HTML 来创建一种效果,使某人可以将鼠标悬停在我页面上的特定图像上,并且图像看起来会“亮起”,或者至少会做一些很酷的事情。在包含的 sn-p 中,我试图对 innerArticle 类中的圆形图像执行此操作。实现这一目标的有效方法是什么?
body {
display: grid;
grid-template-areas:
'header header header'
'nav article ads'
'nav footer footer';
grid-template-rows: 80px 1fr 70px;
grid-template-columns: 20% 1fr 15%;
grid-row-gap: 1px;
grid-column-gap: 1px;
height: 100vh;
margin: 0;
padding: 0;
}
a {
color: #0ad05b;
text-decoration: none;
}
a:hover {
color: #e3eaee;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.2em;
background: #21313c;
font-family: Helvetica, Arial, sans-serif;
color: #e3eaee;
font-size: 14px;
}
footer,
article,
nav,
div {
padding: 1.2em;
background: #061621;
font-family: Helvetica, Arial, sans-serif;
color: #e3eaee;
font-size: 14px;
}
textarea {
font-family: Arial, Helvetica, sans-serif;
}
#pageHeader {
grid-area: header;
}
#pageFooter {
grid-area: footer;
}
#mainArticle {
grid-area: article;
align-content: flex-start;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
}
#mainArticleShip {
grid-area: article;
align-content: flex-start;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
}
#mainNav {
grid-area: nav;
}
#siteAds {
grid-area: ads;
}
/* Form Style */
#mainArticleForm {
background: linear-gradient(50deg, rgba(6, 22, 33, 0.5), rgb(0, 0, 0)),
url(https://cruisecrunch.s3.us-east-2.amazonaws.com/bg.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: right;
}
#mainArticle {
background: linear-gradient(15deg, rgba(6, 22, 33, 0.7), rgb(0, 0, 0)),
url(https://cruisecrunch.s3.us-east-2.amazonaws.com/bg.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: right;
}
.innerArticleSignup {
background: transparent;
}
.innerArticleForm {
width: 65%;
margin: 0 auto;
background: transparent;
}
.text {
background: transparent;
}
.reviewForm {
background: transparent;
}
.innerArticleForm h1 {
color: #e3eaee;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 30px;
}
.innerArticleForm h2 {
color: #e3eaee;
text-align: center;
font-size: 18px;
}
form {
padding: 39px;
}
.form__group {
background: #000000a1;
display: flex;
justify-content: space-between;
}
.form__group label {
width: 232px;
display: inline;
text-align: left;
}
.form__group select {
padding: 6px;
float: right;
}
.form__group input {
padding: 6px;
font-size: 14px;
border-radius: 4px;
float: right;
}
.form__group textarea {
font-size: 14px;
float: right;
height: auto;
width: 100%;
color: #767676;
}
.primary {
padding: 8px 18px;
margin: 22px 0px;
font-size: 18px;
background: #0ad05b;
border: 2px solid #989898;
}
.innerArticle {
height: 17vh;
width: 17vh;
background: transparent;
margin-top: 1rem;
margin-bottom: 1rem;
}
.big-user-photo {
border-radius: 50%;
}
.userAvatar {
height: 3rem;
width: 3rem;
border-radius: 50%;
margin-right: 1rem;
}
.mainPage {
height: 3rem;
width: 3rem;
border-radius: 50%;
margin-right: 1rem;
}
.headerRight {
grid-area: header;
justify-self: right;
padding: 1.2em;
background: #21313c;
font-family: Helvetica, Arial, sans-serif;
color: #e3eaee;
}
.right {
display: flex;
flex-direction: row;
flex-wrap: wrap;
padding: 0.5em;
background: #21313c;
font-family: Helvetica, Arial, sans-serif;
color: #e3eaee;
}
.left {
background: #21313c;
font-family: Helvetica, Arial, sans-serif;
color: #e3eaee;
align-content: left;
align-items: left;
justify-content: left;
}
.form-user-photo {
height: 15rem;
width: 15rem;
}
.alert {
position: fixed;
top: 0;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
z-index: 9999;
color: #fff;
font-size: 1.8rem;
font-weight: 400;
text-align: center;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
padding: 1.6rem 15rem;
-webkit-box-shadow: 0 2rem 4rem rgba(0, 0, 0, 0.25);
box-shadow: 0 2rem 4rem rgba(0, 0, 0, 0.25);
}
.alert--success {
background-color: #0ad05b;
}
.alert--error {
background-color: #eb4d4b;
}
.stars-container {
position: relative;
display: inline-block;
color: transparent;
}
.stars-container:before {
position: absolute;
top: 0;
left: 0;
content: '★★★★★';
color: lightgray;
}
.stars-container:after {
position: absolute;
top: 0;
left: 0;
content: '★★★★★';
color: gold;
overflow: hidden;
}
.stars-0:after {
width: 0%;
}
.stars-10:after {
width: 10%;
}
.stars-20:after {
width: 20%;
}
.stars-30:after {
width: 30%;
}
.stars-40:after {
width: 40%;
}
.stars-50:after {
width: 50%;
}
.stars-60:after {
width: 60%;
}
.stars-70:after {
width: 70%;
}
.stars-80:after {
width: 80%;
}
.stars-90:after {
width: 90%;
}
.stars-100:after {
width: 100;
}
.shipImage {
width: 200px;
height: auto;
border-radius: 10%;
}
.logo {
width: 100%;
max-width: 175px;
height: auto;
}
.otherShips {
align-content: flex-start;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
}
/* Stack the layout on small devices/viewports. */
@media all and (max-width: 575px) {
body {
grid-template-areas:
'header'
'article'
'ads'
'nav'
'footer';
grid-template-rows: 80px 1fr 70px 1fr 70px;
grid-template-columns: 1fr;
}
.form__group {
display: block;
}
}
@media (max-width: 1250px) {
.innerArticleForm,
.reviewForm,
form {
padding: 0;
}
.innerArticleForm {
width: 70%;
}
}
@media (max-width: 557px) {
.innerArticleForm {
width: 100%;
}
}
<!DOCTYPE html>
<head>
</head>
<body>
<header id="pageHeader">
<div class="left"><a href="/"><img class="logo"
src="https://cruisecrunch.s3.us-east-2.amazonaws.com/logo.png"></a></div>
<div class="right">
<p><a href="/signup">Sign up</a> | <a href="/login">Login</a></p>
</div>
</header>
<article id="mainArticle">
<div class="text">
<h2>All Cruise Ships</h2>
<p>Welcome to CruiseCrunch - the ultimate destination for cruise research. Enjoy free access to user reviews
and ratings for cruise ships across the industry. If you have cruised before, please <a
href="/addreview">leave a review</a> of your trip for others. </p>
</div>
<div class="innerArticle"><a href="/ship/disney-dream"><img class="mainPage" src="https://www.goport.com/blog/wp-content/uploads/2013/10/ship-photo-shopped.jpg"
alt="Disney Dream"></a><br>Disney Dream<br><br><span
class="stars-container stars-20">★★★★★</span><br><br><a href="/ship/disney-dream">See Reviews (1)</a>
</div>
</article>
<nav id="mainNav">Navigation<div class="nav">
<div class="ul">
<div class="li"><a href="/"><i class="fa fa-ship"></i> All Ships</a></div>
<div class="li"><a href="/addreview"><i class="fa fa-plus"></i> Add Review</a></div>
<div class="li"><a href="/topships"><i class="fa fa-trophy"></i> Top Rated Ships</a></div>
<div class="li"> <a href="/bestforkids"><i class="fa fa-child"></i> Best For Kids</a></div>
<div class="li"> <a href="/bestvalue"><i class="fa fa-dollar"></i> Best Value</a></div>
<div class="li"><a href="/cabins"><i class="fa fa-bed"></i> Best Cabins</a></div>
<div class="li"><a href="/bestdining"><i class="fa fa-beer"></i> Best Dining</a></div>
<div class="li"><a href="/entertainment"><i class="fa fa-film"></i> Best Entertainment</a></div>
<div class="li"><a href="/worstships"><i class="fa fa-thumbs-down"></i> Lowest Rated Ships</a></div>
<div class="li"><a href="/recentreviews"><i class="fa fa-rss-square"></i> Most Recent Reviews</a></div>
<div class="li"><a href="/newships"><i class="fa fa-anchor"></i> New Ships</a></div>
<div class="li"><br></div>
</div>
</div>
</nav>
<div id="siteAds">Over 6 cruise ship reviews!</div>
<footer id="pageFooter">
<p class="footer">© 2020, CruiseCrunch</p>
</footer>
</body>
【问题讨论】:
-
只需使用 :hover 效果并使用您可以或想要的任何东西。 Liek 发光的阴影,改变不透明度......从字面上看,一切都可以用 CSS 完成。
-
您可能对之前的帖子感兴趣:stackoverflow.com/questions/15275344/light-up-image-on-hover :)
-
看看developer.mozilla.org/en-US/docs/Web/CSS/filter(你可能对亮度和对比度感兴趣)。