尝试在点击卡片时创建一个与屏幕重叠的元素

huangapple go评论50阅读模式
英文:

Trying to create an overlapping element to the screen when a card is clicked

问题

基本上,我想要一个新的元素来覆盖其他所有元素,以营造当点击卡片时出现新屏幕的幻觉。看起来我做到了,但问题出现在调整屏幕大小时,然后那些元素看起来很不协调。

这是我使用的 CSS 代码:

.overlap {
  max-width: 1000px;
  background-color: #4f00e7;
  position: sticky;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9;
  padding: 30px;
  border-radius: 10px;
}

还有我正在工作的网站:https://strong-salamander-b1af56.netlify.app/portfolio

谢谢,祝您有美好的一天!

英文:

Basically I want a new element to override every other element to give the illusion that a new screen has appeared when a card is clicked. Looks like I did it but the problem appears when I resize the screen, then that elements looks very off.

This is the css code that I used:

.overlap {
  max-width: 1000px;
  background-color: #4f00e7;
  position: sticky;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9;
  padding: 30px;
  border-radius: 10px;
}

And also the site Im working on: https://strong-salamander-b1af56.netlify.app/portfolio

Thank you and have a nice day!

尝试在点击卡片时创建一个与屏幕重叠的元素

答案1

得分: 1

也许你应该尝试使用 position: fixed

.overlap {
  max-width: 1000px;
  background-color: #4f00e7;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9;
  padding: 30px;
  border-radius: 10px;
}
content

<div class="overlap">overlap</div>
英文:

Maybe you should try with position: fixed

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.overlap {
  max-width: 1000px;
  background-color: #4f00e7;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9;
  padding: 30px;
  border-radius: 10px;
}

<!-- language: lang-html -->

content

&lt;div class=&quot;overlap&quot;&gt;overlap&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月10日 05:58:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定