styling an image title attribute using css?

前端 未结 7 1351
猫巷女王i
猫巷女王i 2020-12-14 13:07

I want to style the text we see when we hover over the image. I tried the following but it won’t work:


         


        
7条回答
  •  春和景丽
    2020-12-14 13:41

    Another great fiddle is http://jsfiddle.net/tDQWN/129/ (I can't take credit, but in the same search I found both posts). It's a similar solution but the styling is a bit fancier.

    a {
      color: #900;
      text-decoration: none;
    }
    
    a:hover {
      color: red;
      position: relative;
    }
    
    a[data-title]:hover:after {
      content: attr(data-title);
      padding: 4px 8px;
      color: #333;
      position: absolute;
      left: 0;
      top: 100%;
      white-space: nowrap;
      z-index: 20px;
      -moz-border-radius: 5px;
      -webkit-border-radius: 5px;
      border-radius: 5px;
      -moz-box-shadow: 0px 0px 4px #222;
      -webkit-box-shadow: 0px 0px 4px #222;
      box-shadow: 0px 0px 4px #222;
      background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
      background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #eeeeee),color-stop(1, #cccccc));
      background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
      background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
      background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
      background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
    }
    

    And HTML:

    Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

    Hope this helps someone!

提交回复
热议问题