如何将所有内容保持在 div 内部?

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

How do I keep all contents INSIDE the div?

问题

我正在尝试创建一个Ebay模板。但我已经花了整整2天(真的)来使所有内容都保持在“frame” div内。

但是当我调整页面大小或有人在手机上查看时,所有垃圾,如图像和形状(边框项),都散落在白色页面上,超出了栗色框架之外。

我只希望一切都像固定在一个div上一样,就像它是一个画布,不会在调整浏览器大小时移动或调整大小。

P.S. 这个网站由于某种原因无法正确显示我的代码。请将html和css部分复制并粘贴到https://htmledit.squarefree.com/中查看并查看我所看到的内容。这个网站的html查看器太古怪了。

英文:

I'm trying to make an Ebay template. But I have spent 2 whole days (literally) to make everything to stay INSIDE the "frame" div.

But when I resize the page or someone checks it on the phone, all the junk like images and shapes (border items) are all over the place on the white page outside the maroon frame.

I just want everything to be cemented down onto that one div as if it is a canvas and not move nor resize when I resize the browser.

P.S. The cig will not puff due to it being blocked by something. I'm pretty new to this so I'm clueless.

IMPORTANT*: This website does not display my code properly for some reason. Please copy and paste both html and css sections into https://htmledit.squarefree.com/ to view and see what I see. This site's html viewer is too goofy.

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

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

.Frame {
  background-color: black;
  border: solid 20px maroon;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.header {
  border: solid 1px red;
  color: Red;
  background-color: ;
  height: 60px;
  width: 899;
  font-size: 35px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: cursive;
}

.cigbutt {
  border: solid 3px white;
  width: 40px;
  height: 40px;
  border-radius: 100px;
  margin-left: 510px;
  margin-top: -30px;
  background-color: 7B2424;
  transition: 2.5s;
}

.cigbutt:hover {
  background-color: BF3D12;
}

.cigbutt:active {
  background-color: EE4007;
}

.moretext {
  color: white;
  text-align: right;
  margin-left: 450px;
  margin-top: -90px;
  width: 160px;
}

.text {
  color: white;
  width: 400px;
}

.img1 {
  margin-top: -50px;
  margin-left: 640px;
  width: 250px;
  height: 400px;
}

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

&lt;div class = Frame&gt;

&lt;div class = Header&gt;
Hot Girls And Cigarette Butts
&lt;/div&gt;

&lt;br&gt; &lt;br&gt;

&lt;div class = text&gt;
I do not know what to put down so here as an example so here is a hot girl and an interactive circle that looks and acts like a cigarette butt. Please notice how the frame moves but everything else just magically hovers.
&lt;/div&gt;

&lt;div class = cigbutt&gt;

&lt;/div&gt;

&lt;div class = moretext&gt;
hover over circle to light long press circle to puff
&lt;/div&gt;


&lt;img class = img1 src = &quot;https://optimize.webmavens.in/?key=1949128684&amp;url=https://prodimages.everythingneon.com/giant/n105-1565-pole-dance-girls-1-neon-sign.jpg&quot;&gt;&lt;/img&gt;


&lt;div style = &quot;margin-top: 100px;&quot;&gt;&lt;/div&gt;

&lt;br&gt;



&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

以下是您提供的内容的中文翻译部分:

主要错误:

  1. 类似于class的属性必须用引号("")括起来。因此,您写成了class=Frame,但应该是class=&quot;Frame&quot;
  2. 您的CSS中有一些行没有正确结束。请确保每行末尾都有分号
  3. 背景颜色是十六进制的,因此它们必须以井号#开头。

主要原因

  1. 您在位置和样式上使用了硬编码单位,如px。因此,它不会很好地缩放,应该使用动态单位(例如em,%等)。
  2. 有一些地方应该使用定位和弹性盒子等,而不是边距来创建布局。甚至您的cigbutt动画由于使用了这种方式的边距而无法工作。
  3. 实际上有太多要数和说。所以我现在将提供修复后的代码。

修复后的代码

&lt;!-- begin snippet: js hide: false console: true babel: false --&gt;

&lt;!-- language: lang-css --&gt;

.Frame {
  background-color: black;
  border: solid 20px maroon;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  isolation: isolate;
}

.Header {
  border: solid 1px red;
  color: Red;
  height: 60px;
  width: 100%;
  font-size: 1.5em;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: cursive;
}

.wrapper {
  display: flex;
  gap: 2em;
}

.cigbutt {
  border: solid 3px white;
  width: 40px;
  height: 40px;
  border-radius: 100px;
  background-color: #7B2424;
  transition: 2.5s;
}

.cigbutt:hover {
  background-color: #BF3D12;
}

.cigbutt:active {
  background-color: #EE4007;
}

.moretext {
  color: white;
  text-align: right;
  width: 160px;
}

.text {
  color: white;
  width: 400px;
  padding: 10px;
}

.img1 {
  position: absolute;
  top: 10%;
  right: 0;
  width: 250px;
  height: 400px;
  max-height: 90%;
  z-index: -1;
}

&lt;!-- language: lang-html --&gt;

&lt;div class=&quot;Frame&quot;&gt;

  &lt;div class=&quot;Header&quot;&gt;
    热辣美女和香烟蒂
  &lt;/div&gt;

  &lt;br&gt; &lt;br&gt;

  &lt;div class=&quot;wrapper&quot;&gt;
    &lt;div class=&quot;text&quot;&gt;
      我不知道要写什么,所以这里有一个示例,展示了一个性感女郎和一个看起来像香烟蒂的交互式圆圈。请注意,框架移动,但其他所有内容都像魔术一样悬浮。
    &lt;/div&gt;

    &lt;div style=&quot;display: flex; flex-direction: column; align-items: center; gap: 10px;&quot;&gt;
      &lt;div class=&quot;cigbutt&quot;&gt;

      &lt;/div&gt;

      &lt;div class=&quot;moretext&quot;&gt;
        悬停在圆圈上以点亮,长按圆圈以吸气
      &lt;/div&gt;
    &lt;/div&gt;


    &lt;img class=&quot;img1&quot; src=&quot;https://optimize.webmavens.in/?key=1949128684&amp;url=https://prodimages.everythingneon.com/giant/n105-1565-pole-dance-girls-1-neon-sign.jpg&quot;&gt;&lt;/img&gt;

  &lt;/div&gt;

  &lt;div style=&quot;margin-top: 100px;&quot;&gt;&lt;/div&gt;

  &lt;br&gt;

&lt;/div&gt;

&lt;!-- end snippet --&gt;

请注意,我已经将HTML和CSS代码中的&quot;替换为引号以获得更清晰的翻译。

英文:

The Primary Mistakes:

  1. The attributes such as class must have quotes ("") for their value. So you did class=Frame but it should be class=&quot;Frame&quot;
  2. There are some lines in your CSS that did not end properly. Please make sure to have ; at the end of each line.
  3. The background colors are in HEX, so they must start with a hash #

The main reason

  1. You are using hard-coded units like px for positioning and stylings. Thus it does not scale well, use dynamic units (e.g. em, % etc) for these.
  2. There are some places where you should have used positioning and flexbox etc instead of margin to create the layout. even your cigbutt animation was not working due to using margins like that.
  3. There are just too many to actually count and say. so I'll provide the fixed code now

Fixed code

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

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

.Frame {
  background-color: black;
  border: solid 20px maroon;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  isolation: isolate;
}

.Header {
  border: solid 1px red;
  color: Red;
  height: 60px;
  width: 100%;
  font-size: 1.5em;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: cursive;
}

.wrapper {
  display: flex;
  gap: 2em;
}

.cigbutt {
  border: solid 3px white;
  width: 40px;
  height: 40px;
  border-radius: 100px;
  background-color: #7B2424;
  transition: 2.5s;
}

.cigbutt:hover {
  background-color: #BF3D12;
}

.cigbutt:active {
  background-color: #EE4007;
}

.moretext {
  color: white;
  text-align: right;
  width: 160px;
}

.text {
  color: white;
  width: 400px;
  padding: 10px;
}

.img1 {
  position: absolute;
  top: 10%;
  right: 0;
  width: 250px;
  height: 400px;
  max-height: 90%;
  z-index: -1;
}

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

&lt;div class=&quot;Frame&quot;&gt;

  &lt;div class=&quot;Header&quot;&gt;
    Hot Girls And Cigarette Butts
  &lt;/div&gt;

  &lt;br&gt; &lt;br&gt;

  &lt;div class=&quot;wrapper&quot;&gt;
    &lt;div class=&quot;text&quot;&gt;
      I do not know what to put down so here as an example so here is a hot girl and an interactive circle that looks and acts like a cigarette butt. Please notice how the frame moves but everything else just magically hovers.
    &lt;/div&gt;

    &lt;div style=&quot;display: flex; flex-direction: column; align-items: center; gap: 10px;&quot;&gt;
      &lt;div class=&quot;cigbutt&quot;&gt;

      &lt;/div&gt;

      &lt;div class=&quot;moretext&quot;&gt;
        hover over circle to light long press circle to puff
      &lt;/div&gt;
    &lt;/div&gt;


    &lt;img class=&quot;img1&quot; src=&quot;https://optimize.webmavens.in/?key=1949128684&amp;url=https://prodimages.everythingneon.com/giant/n105-1565-pole-dance-girls-1-neon-sign.jpg&quot;&gt;&lt;/img&gt;

  &lt;/div&gt;

  &lt;div style=&quot;margin-top: 100px;&quot;&gt;&lt;/div&gt;

  &lt;br&gt;



&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月18日 15:02:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710229.html
匿名

发表评论

匿名网友

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

确定