【问题标题】:CSS extract element outside several parents几个父级之外的 CSS 提取元素
【发布时间】:2021-07-17 17:04:48
【问题描述】:

在几个父级中有一个红色圆圈元素(elementToExtract),其结构应为:

https://jsfiddle.net/dwxmb87L/1/

#main {
  top: 17px;
  left: 32px;
  position: absolute;
  overflow: hidden;
}
#yellow {
  display: inline-block;
  transform: translate(0px, 0px) translateZ(0px);
  position: relative;
  width: 240px;  
  background: yellow;
}
#scroller {
}
#someDiv {  
}
#lightblue {
  position: relative;
  width: 220px;
  height: 200px;   
  margin: 10px;
  background: lightblue;
  overflow: hidden;    
}
#elementToExtract {
  width: 30px;
  height: 30px;
  border-radius: 30px;
  position: fixed;
  top: 0;
  right: -15px;
  background: red;
}
<div id="main">
  <div id="yellow">
    <div id="scroller">   
      <div id="someDiv">
        <div id="lightblue">    
          <div id="elementToExtract"></div>
        </div>
      </div>
    </div>  
  </div>
</div>

我如何提取它以显示在所有元素上(由于溢出而没有切成两半)没有

  1. 更改 DOM 结构(HTML 必须保持原样)
  2. 删除黄色元素的变换 CSS 声明
  3. 尽可能少地改变其他元素的 CSS(如果可能的话,完全不要!)

所以基本上,如果可能的话,只能通过修改 elementToExtract 的 CSS。 如果绝对不可撤销,则对其他元素进行一些小修改,但请注意条件 2

【问题讨论】:

  • 请做你自己的任务 :D 也向我们展示你到目前为止所做的事情,以便我们提供帮助;)
  • 到目前为止,我做了我所做的(位置固定,但问题是因为父级已转换,因此固定未应用于整个屏幕)但我卡住了。

标签: html css css-position css-transforms


【解决方案1】:

更新:只改变了父级的宽度

我试图尽可能少地改变。

#main {
  top: 17px;
  left: 32px;
  position: absolute;
  overflow: hidden;
  width: 300px; /* added this line only */
}

#yellow {
  display: inline-block;
  transform: translate(0px, 0px) translateZ(0px);
  position: relative;
  width: 240px;
  background: yellow;
}

#scroller {}

#someDiv {}

#lightblue {
  position: relative;
  width: 220px;
  height: 200px;
  margin: 10px;
  background: lightblue;
  overflow: hidden;
}

#elementToExtract {
  width: 30px;
  height: 30px;
  border-radius: 30px;
  position: fixed;
  top: 0;
  right: -15px;
  background: red;
}
<div id="main">
  <div id="yellow">
    <div id="scroller">
      <div id="someDiv">
        <div id="lightblue">
          <div id="elementToExtract"></div>
        </div>
      </div>
    </div>
  </div>
</div>

【讨论】:

  • 谢谢。您会为努力获得一票,但这对我不起作用,因为这两个元素应该被溢出。我知道我没有提到它,但我不能去“不要更新这个或这个或这个......”
  • 更新了我的答案
  • 你就是那个男人!如果我能给你 3 票,你就会得到它!
猜你喜欢
  • 1970-01-01
  • 2016-08-21
  • 2016-04-19
  • 2013-01-02
  • 2021-06-19
  • 1970-01-01
  • 2014-05-04
  • 2012-11-08
  • 1970-01-01
相关资源
最近更新 更多