javascript - 如何将 CSS 添加到链接预览?

标签 javascript html css hexo

我有这个 HTML:

  <a href="http://waterfordwhispersnews.com/2017/01/19/im-the-only-one-creating-jobs-around-here-local-drug-dealer-slams-government/#FB-Comments" class="link-preview" target="_blank" rel="nofollow">
    <div class="link-area">
      <div class="og-image">
        <a href="http://waterfordwhispersnews.com/wp-content/uploads/2017/01/grater.jpg" title="" class="fancybox" rel="article0">
          <img src="http://waterfordwhispersnews.com/wp-content/uploads/2017/01/grater.jpg">
        </a>
      </div>
      <div class="descriptions">
        <div class="og-title">
        “I’m The Only One Creating Jobs Around Here” Local Drug Dealer Slams Government
        </div>
        <div class="og-description">
          WATERFORD drug dealer Richie 'The Grater' Harrington has today slammed the Irish government for ignoring the young people in his council est…
        </div>
      </div>
    </div>
 </a>

看起来像这样:

enter image description here

我想添加 CSS 使其看起来更像 Facebook 帖子,但我不确定从哪里开始。

enter image description here

我的想法是这是一篇新闻文章的预览,我会在一篇讨论它的博客文章中链接它。这是我用来生成它的hexo插件。 https://github.com/minamo173/hexo-tag-link-preview

至少,它需要被装箱。截至目前,它只是继承典型帖子的链接和图像的样式。

最佳答案

这里有一个建议,你可以如何做,添加虚线边框,标题上更大的字体 + anchor 和标题上的一些填充,使它看起来很好:)

还有一个小技巧 (display: table-caption) 让文本换行并适合图像。

我还删除了内部链接 a,因为它对嵌套 anchor 无效。

堆栈片段

a.link-preview {
  display: inline-block;
  border: 2px dotted black;
  padding: 5px;
}
a.link-preview .link-area {
  display: table-caption;              /*  make text wrap under image  */
}
a.link-preview .link-area .og-title {
  font-size: 22px;
  padding-bottom: 15px;
}
<a href="http://waterfordwhispersnews.com/2017/01/19/im-the-only-one-creating-jobs-around-here-local-drug-dealer-slams-government/#FB-Comments" class="link-preview" target="_blank" rel="nofollow">
  <div class="link-area">
    <div class="og-image">
        <img src="http://waterfordwhispersnews.com/wp-content/uploads/2017/01/grater.jpg">
    </div>
    <div class="descriptions">
      <div class="og-title">
        “I’m The Only One Creating Jobs Around Here” Local Drug Dealer Slams Government
      </div>
      <div class="og-description">
        WATERFORD drug dealer Richie 'The Grater' Harrington has today slammed the Irish government for ignoring the young people in his council est…
      </div>
    </div>
  </div>
</a>

关于javascript - 如何将 CSS 添加到链接预览?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51227692/

相关文章:

jquery - 如何保持图像动态的位置

javascript - 使用 anchor 标记切换 block 和不显示

javascript - 单击更改动态元素的背景颜色

Jquery 滑动切换不起作用

javascript - 我的 AJAX 请求对象没有正确解析 URL 的协议(protocol)部分

javascript - 转换此 JavaScript 以处理多首歌曲?

html - 使链接的大小与父链接一样大?

javascript - 嵌套选项卡界面内有 700 个音频播放器。最佳选项卡代码类型(jquery/ajax/etc)

javascript - jquery 中此引用的范围?

javascript - 配置 .babelrc 和 out-dir/target 目录参数