RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 694384
Accepted
Roman Rozum
Roman Rozum
Asked:2020-07-20 05:53:59 +0000 UTC2020-07-20 05:53:59 +0000 UTC 2020-07-20 05:53:59 +0000 UTC

悬停在元素上时如何制作不寻常的框架?

  • 772

将鼠标悬停在元素上时,实现这种框架的最佳方式是什么?

在此处输入图像描述

html
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Cheg
    2020-07-20T06:05:49Z2020-07-20T06:05:49Z

    您可以为此使用:before和伪元素:after。例如,像这样:

    html,
    body {
      padding: 10px;
      margin: 0px;
      background: #1a244e;
    }
    
    .block {
      width: 176px;
      height: 246px;
      position: relative;
      z-index: 1;
      margin: 20px auto;
    }
    
    .block:before,
    .block:after {
      content: '';
      position: absolute;
      display: block;
      width: 75px;
      height: 195px;
      border: green solid 2px;
      transition: all 0.4s ease-in-out;
      opacity: 0;
      visibility: hidden;
    }
    
    .block:before {
      right: -5px;
      top: -5px;
      border-left: none;
      border-bottom: none;
    }
    
    .block:after {
      left: -5px;
      bottom: -5px;
      border-right: none;
      border-top: none;
    }
    
    .block:hover:before,
    .block:hover:after {
      opacity: 1;
      visibility: visible;
    }
    <div class="block">
      <img src="http://i.imgur.com/jpBZGDX.png" alt="" />
    </div>


    您可以稍微调整一下样式并获得不同的效果。

    选项#1 transform: translate():

    html,
    body {
      padding: 10px;
      margin: 0px;
      background: #1a244e;
    }
    
    .block {
      width: 176px;
      height: 246px;
      background: #000;
      position: relative;
      z-index: 1;
      cursor: pointer;
      margin: 20px auto;
    }
    
    .block:before,
    .block:after {
      content: '';
      position: absolute;
      display: block;
      width: 75px;
      height: 195px;
      border: green solid 2px;
      transition: all 0.4s ease-in-out;
      opacity: 0;
      visibility: hidden;
    }
    
    .block:before {
      right: -5px;
      top: -5px;
      transform: translate(10px, -10px);
      border-left: none;
      border-bottom: none;
    }
    
    .block:after {
      left: -5px;
      bottom: -5px;
      transform: translate(-10px, 10px);
      border-right: none;
      border-top: none;
    }
    
    .block:hover:before,
    .block:hover:after {
      opacity: 1;
      visibility: visible;
      transform: translate(0, 0);
    }
    <div class="block">
      <img src="http://i.imgur.com/15ofDrj.png" alt="" />
    </div>


    选项#2 transform: translate():

    html,
    body {
      padding: 10px;
      margin: 0px;
      background: #1a244e;
    }
    
    .block {
      width: 176px;
      height: 246px;
      background: #000;
      position: relative;
      z-index: 1;
      cursor: pointer;
      margin: 20px auto;
    }
    
    .block:before,
    .block:after {
      content: '';
      position: absolute;
      display: block;
      width: 75px;
      height: 195px;
      border: green solid 2px;
      transition: all 0.4s ease-in-out;
      z-index: -1;
      opacity: 0;
      visibility: hidden;
    }
    
    .block:before {
      right: -5px;
      top: -5px;
      border-left: none;
      border-bottom: none;
      transform: translate(-10px, 10px);
    }
    
    .block:after {
      left: -5px;
      bottom: -5px;
      border-right: none;
      border-top: none;
      transform: translate(10px, -10px);
    }
    
    .block:hover:before,
    .block:hover:after {
      opacity: 1;
      visibility: visible;
      transform: translate(0, 0);
    }
    <div class="block">
      <img src="http://i.imgur.com/15ofDrj.png" alt="" />
    </div>


    选项 #3width和height:

    html,
    body {
      padding: 10px;
      margin: 0px;
      background: #1a244e;
    }
    
    .block {
      width: 176px;
      height: 246px;
      background: #000;
      position: relative;
      z-index: 1;
      cursor: pointer;
      margin: 20px auto;
    }
    
    .block:before,
    .block:after {
      content: '';
      position: absolute;
      display: block;
      width: 0px;
      height: 0px;
      border: green solid 2px;
      transition: all 0.4s ease-in-out;
      opacity: 0;
      visibility: hidden;
    }
    
    .block:before {
      right: -5px;
      top: -5px;
      border-left: none;
      border-bottom: none;
    }
    
    .block:after {
      left: -5px;
      bottom: -5px;
      border-right: none;
      border-top: none;
    }
    
    .block:hover:before,
    .block:hover:after {
      width: 75px;
      height: 195px;
      opacity: 1;
      visibility: visible;
    }
    <div class="block">
      <img src="http://i.imgur.com/15ofDrj.png" alt="" />
    </div>


    SVG 上的选项 #4:

    html,
    body {
      padding: 10px;
      margin: 0px;
      background: #1a244e;
    }
    
    .block {
      width: 176px;
      height: 246px;
      position: relative;
      z-index: 1;
      margin: 20px auto;
    }
    
    .border {
      width: 186px;
      height: 256px;
      display: block;
      position: absolute;
      left: -5px;
      bottom: -5px;
    }
    
    .border polyline {
      stroke: green;
      stroke-width: 2px;
      stroke-dasharray: 271;
      stroke-dashoffset: 271;
      transition: all 0.6s ease-in-out;
    }
    
    .block:hover .border polyline {
      stroke-dashoffset: 0;
      opacity: 1;
      visibility: visible;
    }
    <div class="block">
      <img src="http://i.imgur.com/15ofDrj.png" alt="" />
      <svg class="border" version="1.1" id="Слой_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="186px" height="256px" viewBox="0 0 186 256" enable-background="new 0 0 186 256" xml:space="preserve">
        <polyline fill="none" stroke-miterlimit="10" points="76,254.5 1.531,254.5 1.5,59"/>
        <polyline fill="none" stroke-miterlimit="10" points="110,1.5 184.969,1.5 184.75,197"/>
      </svg>
    </div>


    更新

    选项 #5 将框架分成单独的块并使用transform: translate():

    html,
    body {
      overflow: hidden;
      padding: 10px;
      margin: 0px;
      background: #1a244e;
    }
    
    .block {
      width: 176px;
      height: 246px;
      position: relative;
      z-index: 1;
      margin: 20px auto;
    }
    
    .border {
      position: absolute;
      left: -5px;
      top: -5px;
      right: -5px;
      bottom: -5px;
    }
    
    .border:before,
    .border:after {
      content: '';
      position: absolute;
      display: block;
      background: green;
      transition: all 0.2s ease-in-out;
      opacity: 0;
      visibility: hidden;
    }
    
    .border:before {
      width: 75px;
      height: 2px;
    }
    
    .border:after {
      width: 2px;
      height: 195px;
    }
    
    .border.border-rt:before,
    .border.border-rt:after {
      right: 0px;
      top: 0px;
    }
    
    .border.border-lb:before,
    .border.border-lb:after {
      left: 0px;
      bottom: 0px;
    }
    
    .border.border-rt:before {
      transform: translate(100%, 0);
    }
    
    .border.border-rt:after {
      transform: translate(0, -100%);
    }
    
    .border.border-lb:before {
      transform: translate(-100%, 0);
    }
    
    .border.border-lb:after {
      transform: translate(0, 100%);
    }
    
    .block:hover .border:before,
    .block:hover .border:after {
      opacity: 1;
      visibility: visible;
      transform: translate(0, 0);
    }
    <div class="block">
      <img src="http://i.imgur.com/15ofDrj.png" alt="" />
      <div class="border border-rt"></div>
      <div class="border border-lb"></div>
    </div>

    • 43
  2. Alexandr_TT
    2020-08-25T05:09:00Z2020-08-25T05:09:00Z

    使用四条线同时沿图像边缘混合的动画示例。下面是实现效果的解释方案:

    在此处输入图像描述

    body {
      background: #2c3e50;
    }
    
    .box {
      width: 176px;
      height: 246px;
      position: relative;
      background-image: url("http://i.imgur.com/15ofDrj.png");
      display: inline-block;
      cursor: pointer;
      opacity: 0.8;
    }
    
    .box:hover {
      opacity: 1;
      -webkit-transition: all .8s ease-in-out;
      transition: all .8s ease-in-out;
    }
    
    .box svg {
      position: absolute;
      top: 0;
      left: 0;
    }
    
    .box svg line {
      stroke-width: 4;
      stroke: skyblue;
      fill: none;
      -webkit-transition: all .8s ease-in-out;
      transition: all .8s ease-in-out;
    }
    
    .box:hover svg line {
      -webkit-transition-delay: 0.1s;
      transition-delay: 0.1s;
    }
    
    .box svg line.top,
    .box svg line.bottom {
      stroke-dasharray: 176 176;
    }
    
    .box svg line.left,
    .box svg line.right {
      stroke-dasharray: 246 246;
    }
    
    .box:hover svg line.top {
      -webkit-transform: translateX(-352px);
      transform: translateX(-352px);
    }
    
    .box:hover svg line.bottom {
      -webkit-transform: translateX(352px);
      transform: translateX(352px);
    }
    
    .box:hover svg line.left {
      -webkit-transform: translateY(492px);
      transform: translateY(492px);
    }
    
    .box:hover svg line.right {
      -webkit-transform: translateY(-492px);
      transform: translateY(-492px);
    }
    <div class="box">
      <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
        <line class="top" x1="0" y1="0" x2="528" y2="0"/> 
        <line class="bottom" x1="-352" y1="246" x2="176" y2="246"/> 
        <line class="left" x1="0" y1="-492" x2="0" y2="246"/> 
        <line class="right" x1="176" y1="0" x2="176" y2="738"/> 
      </svg>
    </div>

    在此处详细了解此效果的实现。

    • 9

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5