Hongmu Notes
Home Language Notes css image overlay effect displayed on mouseover
Language Notes CSS

css image overlay effect displayed on mouseover

css image overlay effect displayed on mouseover

Show image overlay effect on hover.
鼠标悬停时显示图像叠加效果

Use the and pseudo-elements for the overlay's top and bottom bars respectively. Set them up and produce the desired effect. :before:afteropacitytransformtransition
Use for overlay text. Set , and center the text into the image. <figcaption>display: flexflex-direction: columnjustify-content: center
Use a pseudo-selector to update the sum of all elements and show the overlay. :hoveropacitytransform


<figure class="hover-img">
  <img src="https://picsum.photos/id/200/440/320.jpg"/>
  <figcaption>
    <h3>Lorem <br/>Ipsum</h3>
  </figcaption>
</figure>

.hover-img {
  background-color: #000;
  color: #fff;
  display: inline-block;
  margin: 8px;
  max-width: 320px;
  min-width: 240px;
  overflow: hidden;
  position: relative;
  text-align: center;
  width: 100%;
}

.hover-img * {
  box-sizing: border-box;
  transition: all 0.45s ease;
}

.hover-img:before,
.hover-img:after {
  background-color: rgba(0, 0, 0, 0.5);
  border-top: 32px solid rgba(0, 0, 0, 0.5);
  border-bottom: 32px solid rgba(0, 0, 0, 0.5);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  content: '';
  transition: all 0.3s ease;
  z-index: 1;
  opacity: 0;
  transform: scaleY(2);
}

.hover-img img {
  vertical-align: top;
  max-width: 100%;
  backface-visibility: hidden;
}

.hover-img figcaption {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  align-items: center;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.1em;
  opacity: 0;
  z-index: 2;
  transition-delay: 0.1s;
  font-size: 24px;
  font-family: sans-serif;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.hover-img:hover:before,
.hover-img:hover:after {
  transform: scale(1);
  opacity: 1;
}

.hover-img:hover > img {
  opacity: 0.7;
}

.hover-img:hover figcaption {
  opacity: 1;
}

 

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

css positioning

css positioning Language Notes CSS

Syntax: position: static | relative | absolute | fixed | center | page | sticky Default value: static Applies to: All elements except the display attribute defined as table-column-group | table-column Inheritance: No Animation: No...
👁 119
css vh and vw adaptive

css vh and vw adaptive Language Notes CSS

In the mobile terminal, REM is used to change the root HTML, and the mobile terminal adaptation is realized through a piece of JS. This article uses pure CSS viewport units to self-adapt. Although the current compatibility is not fully acceptable, it does not prevent you from recognizing the power of vw and vh. The implementation of responsive layout relies on media queries (Media Queries). Select the width size of mainstream devices as breakpoints to target...
👁 356

Recommended reading

Government Association Website Template 1141

Government Association Website Template 1141 Practical Collection Yiyou template

An eYouCMS website template designed specifically for government agencies and industry associations. Its sophisticated and professional design is ideal for showcasing government transparency initiatives, association functions, industry trends, and member services. This template helps government bodies and industry associations establish an official online information publishing platform. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS | eYouCMS...
👁 38
Responsive Entrepreneurship Park Management Committee Website Template 1142

Responsive Entrepreneurship Park Management Committee Website Template 1142 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for startup parks and administrative committees. Its modern and professional design effectively showcases the park's environment, corporate services, investment promotion policies, and the businesses operating within the park. It helps startup parks attract startups and investors online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (Eyou...
👁 41
Intellectual Property Financial Accounting Website Template 1143

Intellectual Property Financial Accounting Website Template 1143 Practical Collection Yiyou template

An EyouCMS website template designed for the intellectual property and financial accounting industries. Its professional and sophisticated design effectively showcases intellectual property services, financial accounting services, and success stories. This template helps professional service providers attract corporate clients online and expand their business reach. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 35
Resource website typecho001 template

Resource website typecho001 template Program Notes Typecho

typecho001 template template please do not modify the folder name of this template. The folder name is: typecho001 1.4 Fix the js output problem on the article page 1.3 Fix the error prompt when the plug-in is not installed Optimize the list page code output 1.2 Fix the comment function and add a custom homepage title 1.1 Fix the comment reply asymmetry function Add a separate title setting function on the homepage Add the website favicon.ico icon Add one...
👁 198
Financial Registration Company Business Service Website Template 1144

Financial Registration Company Business Service Website Template 1144 Practical Collection Yiyou template

This EyouCMS template is ideal for the finance, company registration, and business registration services industries. Its professional and sophisticated design effectively showcases business registration services, financial agency services, qualification application services, and success stories, helping business service providers attract entrepreneurial clients online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 60
Modification of typecho paging style

Modification of typecho paging style Program Notes Typecho

Sir, times have changed! Typecho is currently the most perfect solution, because Baidu can only see the code of fixed thinking. The actual generated HTML code is breathtakingly clean and fully customized, including adding classes to the li element, adding classes to the a element, adding classes to the previous page and next page, and removing the li tags that come with typecho to express more. I can even add some text to the content inside...
👁 517