英文:
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 -->
<div class = Frame>
<div class = Header>
Hot Girls And Cigarette Butts
</div>
<br> <br>
<div class = text>
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.
</div>
<div class = cigbutt>
</div>
<div class = moretext>
hover over circle to light long press circle to puff
</div>
<img class = img1 src = "https://optimize.webmavens.in/?key=1949128684&url=https://prodimages.everythingneon.com/giant/n105-1565-pole-dance-girls-1-neon-sign.jpg"></img>
<div style = "margin-top: 100px;"></div>
<br>
</div>
<!-- end snippet -->
答案1
得分: 1
以下是您提供的内容的中文翻译部分:
主要错误:
- 类似于
class
的属性必须用引号("")括起来。因此,您写成了class=Frame
,但应该是class="Frame"
。 - 您的CSS中有一些行没有正确结束。请确保每行末尾都有分号
;
。 - 背景颜色是十六进制的,因此它们必须以井号
#
开头。
主要原因
- 您在位置和样式上使用了硬编码单位,如
px
。因此,它不会很好地缩放,应该使用动态单位(例如em,%
等)。 - 有一些地方应该使用定位和弹性盒子等,而不是边距来创建布局。甚至您的
cigbutt
动画由于使用了这种方式的边距而无法工作。 - 实际上有太多要数和说。所以我现在将提供修复后的代码。
修复后的代码
<!-- 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 -->
<div class="Frame">
<div class="Header">
热辣美女和香烟蒂
</div>
<br> <br>
<div class="wrapper">
<div class="text">
我不知道要写什么,所以这里有一个示例,展示了一个性感女郎和一个看起来像香烟蒂的交互式圆圈。请注意,框架移动,但其他所有内容都像魔术一样悬浮。
</div>
<div style="display: flex; flex-direction: column; align-items: center; gap: 10px;">
<div class="cigbutt">
</div>
<div class="moretext">
悬停在圆圈上以点亮,长按圆圈以吸气
</div>
</div>
<img class="img1" src="https://optimize.webmavens.in/?key=1949128684&url=https://prodimages.everythingneon.com/giant/n105-1565-pole-dance-girls-1-neon-sign.jpg"></img>
</div>
<div style="margin-top: 100px;"></div>
<br>
</div>
<!-- end snippet -->
请注意,我已经将HTML和CSS代码中的"
替换为引号以获得更清晰的翻译。
英文:
The Primary Mistakes:
- The attributes such as class must have quotes ("") for their value. So you did
class=Frame
but it should beclass="Frame"
- There are some lines in your CSS that did not end properly. Please make sure to have
;
at the end of each line. - The background colors are in HEX, so they must start with a hash
#
The main reason
- 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. - 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. - 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 -->
<div class="Frame">
<div class="Header">
Hot Girls And Cigarette Butts
</div>
<br> <br>
<div class="wrapper">
<div class="text">
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.
</div>
<div style="display: flex; flex-direction: column; align-items: center; gap: 10px;">
<div class="cigbutt">
</div>
<div class="moretext">
hover over circle to light long press circle to puff
</div>
</div>
<img class="img1" src="https://optimize.webmavens.in/?key=1949128684&url=https://prodimages.everythingneon.com/giant/n105-1565-pole-dance-girls-1-neon-sign.jpg"></img>
</div>
<div style="margin-top: 100px;"></div>
<br>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论