【问题标题】:Display image on text hover在文本悬停时显示图像
【发布时间】:2020-07-17 02:59:48
【问题描述】:

供参考,我正在开发的网站是https://truecolor.blog

我正在尝试在鼠标悬停在博客标题上时显示特色图片,类似于this websitethis one。我正在开发的网站基于blot.im (documentation here)。 This blot template 使用降价条目中的图像作为索引缩略图——不确定是否有任何信息可以帮助。理想情况下,一旦用户将鼠标悬停在文本上,特色图片就会以 0.5 秒的缓动过渡在页面中间居中。

这是作为索引和主页的条目页面:

<html>
  {{> head}}
  <body>
    {{> header}}
    <div class="container index">

      {{#entries}}
      <p>
        <span class="light margin left">{{date}}</span>
        <a href="{{{url}}}">{{title}}</a>
      </p>
      {{/entries}}

      <br /><Br />

      {{#pagination}}
      <p>

        {{#previous}}
        <span class="margin left">
          <a href="/page/{{previous}}">&larr; Newer posts</a>
        </span>
        {{/previous}}

        <span class="light" style="margin-right:30px">page {{current}} of {{total}}</span>

        {{#next}}
        <a href="/page/{{next}}">Older posts &rarr;</a>
        {{/next}}

      </p>
      {{/pagination}}
    </div>
    {{> footer}}
  </body>
</html>

还有 CSS:

{{{body_font.styles}}}

body {
  font-size: 1.3em;
  line-height: 1.7;
  font-family: linotype-sabon, sans-serif;
  font-weight: 400;
  font-style: normal;
  color: {{text_color}};
  background: {{background_color}};
  padding: 3em 4em 5em;
  word-wrap: break-word; /* for long words & urls */
}

.container {
  max-width: 800px;
  min-width: 320px;
  margin: 4em 4em 2em 222px;
}

h1, h2, h3, h4, h5, h6 {font-size: inherit;}

h2, h3 {margin-top: 2em}

h1 {font-size: 28px;line-height: 1.4}

a {color: {{link_color}};text-decoration: none;}

a:hover {background: {{link_color}};color: white}

.logo {float: left;}

.nav {float: right;}
.nav a {margin: 0 0 0 2em}

.small, .light {color: {{text_color}}}

.small {font-size: 12px}

.underlay {
  background: #f9f8f7;
  bottom: 0;
  position: fixed;
  opacity: 0.0;
  top: 0;
  transition: opacity 300ms ease-in-out;
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
  -webkit-perspective: 1000;
  width: 100%;
  z-index: 0; }

.underlay--show {
  opacity: 1.0; }

hr {
  width: 200px;
  margin: 1.5em auto;
  border: none;
  border-top: 1px solid {{text_color}};
  display: block;
}

.caption, blockquote {color: {{text_color}}}

blockquote {font-style: italic;margin:0;padding: 0 0 0 1em;border-left: 1px solid {{text_color}}}

table {
  word-break: normal;
  word-break: keep-all;
  border-collapse: collapse;
  border-spacing: 0;
  box-sizing: border-box;
  font-size: 15px;
  line-height: 24px;
}

tr {box-sizing: border-box;border-top: 1px solid {{text_color}};padding: 0}
th, td {box-sizing: border-box;border: 1px solid {{text_color}};padding: 5px 12px 6px}

/* Date spacing for entry */
h1 + .light {margin-top: -0.75em;margin-bottom: 1.5em}

input[type="text"],
input[type="submit"] {
  font:inherit;
  font-size:20px;padding: 3px 6px;
  margin: 1em 0;
  border: 1px solid {{text_color}};
}

input[type="text"] {
  background: none;
  max-width: 100%;
  min-width: 300px;
  box-shadow: inset 0 1px 2px 0 rgba(0,0,0,.075);
}

input[type="submit"] {
  padding: 3px 12px;
  color: {{link_color}};
  background: none;
  border: 1px solid {{link_color}};
  cursor: pointer;
}

{{> plugin}}

.clear {width: 100%;clear: both;}

.archive h2.margin,
.archive h3.margin {margin: 0}

.archive h2.margin.left {left: -45%;}

/* MESSY RESPONSIVE BUSINESS */

@media screen and (max-width: 1200px) {
  .container {margin-left: 140px}
}

@media screen and (max-width: 1060px) {
  .container {margin: 2em 16px 16px}
  .archive h2.margin.left {left: auto}

}

@media screen and (max-width: 1060px) {
  .archive .margin {display: block;width: 100%}
}

@media screen and (max-width: 800px) {
  .index .margin {display: block;width: 100%}
}

@media screen and (max-width: 600px) {

  body {padding: 0.4em;}

  .container {margin: 1em 0 2em;padding-top:0.5em;border-top:1px solid rgba(0,0,0,0.1);min-width: auto}

  input {font-size: 1em;}

  input[type="text"] {min-width: 200px;}

  .nav {float: none;display: block;margin: 0;width: 100%}
  .nav a {margin: 0 1em 0 0;color:{{text_color}};}
}

【问题讨论】:

    标签: html css mustache


    【解决方案1】:

    请不要发布大量代码;只发布重现您的问题所需的最低限度。

    这会让你开始。

    <style>
    #title:hover:after {
        content: url(image.jpg);
        display: block;
    }
    </style>
    
    <p id=title>Title</p>
    

    【讨论】:

      【解决方案2】:

      您可以使用 span 类并使用普通 CSS 执行类似的操作

      <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="UTF-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Image Hover</title>
          <style>
            .container {
              display: inline-block;
            }
            .hover {
              display: none;
            }
            .hover-text:hover ~ .hover {
              display: block;
            }
          </style>
        </head>
        <body>
          <span class="container">
            <p class="hover-text">Hover text here</p>
            <img
              class="hover"
              src="https://www.google.com/logos/doodles/2017/abdul-sattar-edhis-89th-birthday-5757526734798848-hp.jpg"
            />
          </span>
        </body>
      </html>

      【讨论】:

        猜你喜欢
        • 2016-12-23
        • 2017-02-09
        • 2021-05-01
        • 2017-02-06
        • 2013-07-11
        • 2015-05-11
        • 2019-06-10
        • 2014-05-14
        相关资源
        最近更新 更多