RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1226425
Accepted
spoon 100500
spoon 100500
Asked:2022-01-02 20:17:00 +0000 UTC2022-01-02 20:17:00 +0000 UTC 2022-01-02 20:17:00 +0000 UTC

悬停时更改网格容器中的列宽[关闭]

  • 772
关闭 这个问题是题外话。目前不接受回复。

寻求调试帮助的问题(“为什么这段代码不起作用? ”)应该包括期望的行为、具体的问题或错误,以及在问题中重现它的最少代码。没有明确描述问题的问题对其他访问者毫无用处。请参阅如何创建一个最小的、独立的和可重现的示例。

1 年前关闭。

改进问题

如何使网格中的列在悬停时缩放,程序显示代码,所以你需要在这个css代码上构建,我添加了悬停。

#FlexGrid2 {
    display: grid;
    background-color: transparent;
    background-image: none;
    border: 0px solid #CCCCCC;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-size: 0px;
    grid-column-gap: 1px;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
    grid-template-rows: auto;
    grid-template-areas: "col1 col2 col3 col4 col5 col6 col7";
     
     overflow: hidden;
      align-items: center;
}

#FlexGrid2 > div {
  display: flex;
    background-color: transparent;
    background-image: none;
    border: 0px solid #FFFFFF;
    padding: 0;
    -webkit-flex-direction: row;
    flex-direction: row;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-justify-content: space-around;
    justify-content: space-around;
    -webkit-align-items: center;
    align-items: center;
    -webkit-align-content: center;
    align-content: center;
    
    width: 100%;
    height: 100%;
    transition: all .3s linear;
}

#FlexGrid2 img {
    margin: 0;
    vertical-align: top;
    border: 0px solid #000000;
    box-sizing: border-box;
    padding: 0;
    display: block;
    width: 100%;
   height: auto;
    max-width: 270px;
    margin-left: auto;
    margin-right: auto;
    vertical-align: top;
}
#FlexGrid2 > div:hover{
  cursor: pointer;
  width: 200%;
  margin: -50% 0;
}
<div id="FlexGrid2">
<div class="col1">
<div id="wb_Image1">
<img src="https://images.unsplash.com/photo-1607022505609-a8978bdbe015?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image1">
</div>
</div>
<div class="col2">
<div id="wb_Image2">
<img src="https://images.unsplash.com/photo-1607801354062-c7520503e178?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image2">
</div>
</div>
<div class="col3">
<div id="wb_Image3">
<img src="https://images.unsplash.com/photo-1608755374285-1700d287bc52?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image3">
</div>
</div>
<div class="col4">
<div id="wb_Image4">
<img src="https://images.unsplash.com/photo-1608112906300-03db6a5af97c?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image4">
</div>
</div>
<div class="col5">
<div id="wb_Image5">
<img src="https://images.unsplash.com/photo-1608156618704-ab992d2e5152?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image5">
</div>
</div>
<div class="col6">
<div id="wb_Image6">
<img src="https://images.unsplash.com/photo-1608571785041-22349e5bfdb9?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image6">
</div>
</div>
<div class="col7">
<div id="wb_Image7">
<img src="https://images.unsplash.com/photo-1609439408825-b2a24e29871f?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image7">
</div>
</div>
</div>

css3
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    De.Minov
    2022-01-03T21:56:21Z2022-01-03T21:56:21Z

    作为一种选择

    body {
      display: flex;
      align-items: center;
      height: 100vh;
      margin: 0;
      overflow: hidden;
    }
    
    #FlexGrid2 {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
    }
    
    #FlexGrid2 > div {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      transition: all .3s linear;
    }
    
    #FlexGrid2 img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    
    #FlexGrid2 > div:hover {
      width: 200%;
      margin: -50% 0;
    }
    <div id="FlexGrid2">
      <div class="col1">
        <div id="wb_Image1">
          <img src="https://images.unsplash.com/photo-1607022505609-a8978bdbe015?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image1">
        </div>
      </div>
      <div class="col2">
        <div id="wb_Image2">
          <img src="https://images.unsplash.com/photo-1607801354062-c7520503e178?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image2">
        </div>
      </div>
      <div class="col3">
        <div id="wb_Image3">
          <img src="https://images.unsplash.com/photo-1608755374285-1700d287bc52?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image3">
        </div>
      </div>
      <div class="col4">
        <div id="wb_Image4">
          <img src="https://images.unsplash.com/photo-1608112906300-03db6a5af97c?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image4">
        </div>
      </div>
      <div class="col5">
        <div id="wb_Image5">
          <img src="https://images.unsplash.com/photo-1608156618704-ab992d2e5152?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image5">
        </div>
      </div>
      <div class="col6">
        <div id="wb_Image6">
          <img src="https://images.unsplash.com/photo-1608571785041-22349e5bfdb9?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image6">
        </div>
      </div>
      <div class="col7">
        <div id="wb_Image7">
          <img src="https://images.unsplash.com/photo-1609439408825-b2a24e29871f?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image7">
        </div>
      </div>
    </div>

    • 2
  2. Михаил Камахин
    2022-01-03T22:10:20Z2022-01-03T22:10:20Z

    用js(只有这里需要放弃使用transition的动画,使用requestAnimationFrame,不会有卡顿):

    const gridItems = Array.from(document.querySelectorAll('#FlexGrid2 > *'));
    let widthItem = document.querySelector('#FlexGrid2 > *:not(.active)').offsetWidth;
    
    for (let i = 0; i < gridItems.length; i++) {
      const item = gridItems[i];
      const arrayNotItem = gridItems.slice();
      arrayNotItem.splice(i, 1);
      
      
      item.addEventListener('mouseover', (e) => {
        e.preventDefault();
        item.classList.add('active');
        arrayNotItem.forEach(offItem => {
          offItem.classList.add('off');
        });
      });
      
      item.addEventListener('mouseout', (e) => {
        e.preventDefault();
        item.classList.remove('active');
        arrayNotItem.forEach(offItem => {
          offItem.classList.remove('off');
        });
      });
    }
    
    window.addEventListener('resize', (e) => {
      widthItem = document.querySelector('#FlexGrid2 > *:not(.active)').offsetWidth;
    });
    *, *::before, *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    
    img {
      display: block;
      max-width: 100%;
    }
    
    #FlexGrid2 {
      display: flex;
    }
    
    #FlexGrid2 > * {
      flex: 1;
      display: flex;
      transition-property: transform, filter, flex, width;
      transition-duration: 0.5s;
      transition-timing-function: linear;
      transform-origin: center top;
    }
    
    #FlexGrid2 > * + * {
      margin-left: 4px;
    }
    
    #FlexGrid2 > *.active {
      cursor: pointer;
      width: 100%;
      z-index: 1;
    }
    
    #FlexGrid2 > *.off {
      filter: grayscale(100%);
      flex: 0.5;
    }
    
    #FlexGrid2 > *:first-child {
      transform-origin: left top;
    }
    
    #FlexGrid2 > *:last-child {
      transform-origin: right top;
    }
    <div id="FlexGrid2">
      <div class="col1">
        <div id="wb_Image1">
          <img src="https://images.unsplash.com/photo-1607022505609-a8978bdbe015?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image1">
        </div>
      </div>
      <div class="col2">
        <div id="wb_Image2">
          <img src="https://images.unsplash.com/photo-1607801354062-c7520503e178?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image2">
        </div>
      </div>
      <div class="col3">
        <div id="wb_Image3">
          <img src="https://images.unsplash.com/photo-1608755374285-1700d287bc52?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image3">
        </div>
      </div>
      <div class="col4">
        <div id="wb_Image4">
          <img src="https://images.unsplash.com/photo-1608112906300-03db6a5af97c?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image4">
        </div>
      </div>
      <div class="col5">
        <div id="wb_Image5">
          <img src="https://images.unsplash.com/photo-1608156618704-ab992d2e5152?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image5">
        </div>
      </div>
      <div class="col6">
        <div id="wb_Image6">
          <img src="https://images.unsplash.com/photo-1608571785041-22349e5bfdb9?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image6">
        </div>
      </div>
      <div class="col7">
        <div id="wb_Image7">
          <img src="https://images.unsplash.com/photo-1609439408825-b2a24e29871f?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image7">
        </div>
      </div>
    </div>

    没有js:

    *, *::before, *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    
    img {
      display: block;
      max-width: 100%;
    }
    
    #FlexGrid2 {
      display: flex;
    }
    
    #FlexGrid2 > * {
      flex: 1;
      display: flex;
      transition-property: transform, flex;
      transition-duration: 0.5s;
      transition-timing-function: linear;
      transform-origin: center top;
      cursor: pointer;
    }
    
    #FlexGrid2 > * + * {
      margin-left: 4px;
    }
    
    #FlexGrid2 > *:hover {
      flex: 2;
    }
    
    #FlexGrid2 > *:first-child {
      transform-origin: left top;
    }
    
    #FlexGrid2 > *:last-child {
      transform-origin: right top;
    }
    <div id="FlexGrid2">
      <div class="col1">
        <div id="wb_Image1">
          <img src="https://images.unsplash.com/photo-1607022505609-a8978bdbe015?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image1">
        </div>
      </div>
      <div class="col2">
        <div id="wb_Image2">
          <img src="https://images.unsplash.com/photo-1607801354062-c7520503e178?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image2">
        </div>
      </div>
      <div class="col3">
        <div id="wb_Image3">
          <img src="https://images.unsplash.com/photo-1608755374285-1700d287bc52?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image3">
        </div>
      </div>
      <div class="col4">
        <div id="wb_Image4">
          <img src="https://images.unsplash.com/photo-1608112906300-03db6a5af97c?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image4">
        </div>
      </div>
      <div class="col5">
        <div id="wb_Image5">
          <img src="https://images.unsplash.com/photo-1608156618704-ab992d2e5152?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image5">
        </div>
      </div>
      <div class="col6">
        <div id="wb_Image6">
          <img src="https://images.unsplash.com/photo-1608571785041-22349e5bfdb9?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image6">
        </div>
      </div>
      <div class="col7">
        <div id="wb_Image7">
          <img src="https://images.unsplash.com/photo-1609439408825-b2a24e29871f?crop=entropy\u0026cs=tinysrgb\u0026fit=max\u0026fm=jpg\u0026ixid=MXw2ODk0MXwwfDF8cmFuZG9tfHx8fHx8fHw\u0026ixlib=rb-1.2.1\u0026q=80\u0026w=1080" id="Image7">
        </div>
      </div>
    </div>

    • 0

相关问题

  • 如何用线条绘制立体图并进行动画处理?

  • 如何将心形图像添加到按钮?

  • 如何布置菜单

  • 如何将转换应用于按钮内的文本?

  • 如何在网格中制作滚动项目?

  • 图片与文本重叠的矩形

Sidebar

Stats

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

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +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
    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