物品持续超出容器。

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

items keep going outside the container

问题

我正在设计这个仪表板,但放在其中的"ant item"(可能是指某个元素)会跳出它应该在的容器,谢谢。

我在使用Bootstrap,并尝试将类设置为"container-fluid",因为它应该填充内容,还尝试将标签从<span>更改为<p>,以及普通的<div>,并尝试在CSS中使用display: block属性,我不知道出了什么问题。
编辑:
似乎是给<span>元素设置的margin属性导致了问题,但是为什么呢?

代码:

<section class="container">
    <div class="header">
        <h3></h3>
    </div>
    <hr>
    <div class="row">
        <div class="col-8">
            <div class="profPic">
                <img src="ProfilePicture.png" alt="Profile Picture" class="img-fluid">
            </div>
        </div>
        <div class="col-4 btns">
            <button type="submit" class="btn btn-Danger">gg</button>
            <button type="submit" class="btn btn-Danger">ff</button>
            <button type="submit" class="btn btn-Danger">dd</button>
            <button type="submit" class="btn btn-Danger">qq</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span>الصف:</span>
    </div>
</section>

CSS代码:

body {
    background-image: url('backgroundOne.jpg');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center center;
    background-attachment: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
}
section {
    background-color: white;
    border: solid 2px red;
    box-shadow: 0 0 3px red, 0 0 7px red, 0 0 15px red, 0 0 25px red;
    border-radius: 10px;
}
.header {
    width: 100%;
    border-top-left-radius: 7px;
    border-top-right-radius: 7px;
    padding: 2px;
    text-align: center;
    color: red;
    background-color: #525252;
}
.profPic {
    margin-left: 4%;
    width: 40%;
    height: auto;
    border-right: solid 2px #d3d3d3;
    padding-right: 20px;
}
img {
    width: 100%;
    height: 100%;
}
p:hover {
    color: red;
}
span {
    display: block;
    margin: 20px;
    background-color: #525252;
    color: #d3d3d3;
    border-radius: 6px;
    padding: 1%;
}
.btn {
    margin: 15px;
    float: center;
}
.btns {
    max-width: 25%;
}
.vll {
    border-left: solid;
}
英文:

I am designing this dashboard , but the ant item it put in it just jumps out of the container its supposed to be in, thanks

I am using bootstrap in this , so I tried setting the class to container-fluid , as it should fill the content , and I tried changing the tags from a &lt;span&gt; to &lt;p&gt; to a normal &lt;div&gt;, and also trying the display :block property in CSS , I just don't know what is wrong
Edit :
it seams that the margin property that is given for the span is making the problem , but why?

code :

&lt;section class=&quot;container&quot;&gt;
&lt;div class=&quot;header&quot;&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;profPic&quot;&gt;
&lt;img src=&quot;ProfilePicture.png&quot; alt=&quot;Profile Picture&quot; class=&quot;img-fluid&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-4 btns&quot;&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn btn-Danger&quot;&gt;gg&lt;/button&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn btn-Danger&quot;&gt;ff&lt;/button&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn btn-Danger&quot;&gt;dd&lt;/button&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn btn-Danger&quot;&gt;qq&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;span&gt;               
&lt;/span&gt;
&lt;span&gt;                 
&lt;/span&gt;
&lt;span&gt;
&lt;/span&gt;
&lt;span&gt;              
&lt;/span&gt;
&lt;span&gt; 
&lt;/span&gt;
&lt;span&gt;
الصف:
&lt;/span&gt;
&lt;/div&gt;     
&lt;/section&gt;

css code:

body{
background-image: url(&#39;backgroundOne.jpg&#39;);
background-repeat: no-repeat;
background-size: 100% 100%;
background-position: center center;
background-attachment: fixed;
display: flex;
justify-content: center;
align-items: center;
}
section{
background-color: white;
border: solid 2px red;
box-shadow: 0 0 3px red,
0 0 7px red,
0 0 15px red,
0 0 25px red;
border-radius: 10px;
}
.header{
width: 100%;
border-top-left-radius: 7px;
border-top-right-radius:7px;
padding: 2px;
text-align: center;
color: red;
background-color:#525252 ;
}
.profPic{
margin-left: 4%;
width: 40%;
height: auto;
border-right: solid 2px #d3d3d3;
padding-right: 20px;
}
img{
width: 100%;
height: 100%;
}
p:hover{
color: red;
}
span{
display: block;
margin: 20px;
background-color: #525252;
color: #d3d3d3;
border-radius: 6px;
padding: 1%;
}
.btn{
margin: 15px;
float: center;
}
.btns{
max-width: 25%;
}
.vll{
border-left: solid;
}

答案1

得分: 0

这可以通过修改你的 '.header' 类来解决。由于你的 <h3> 标签中没有内容,因此没有高度分配给父级 <div>。如果你从 '.header' 类中移除填充(padding),你会看到 <div> 消失,因为它填充了 h3 样式中的边距大小。你可以通过删除 '.header' 类中的填充元素并将 h3 的边距设置为 0 来解决所有这些问题。然后,一旦在标题中输入内容,它将成为文本的高度,或者你可以在 header 类中手动设置高度。

.header{
    width: 100%;
    border-top-left-radius: 7px;
    border-top-right-radius:7px;
    text-align: center;             /* 从此类中删除填充 */
    color: red;
    background-color:#525252 ;
}

/* 在 h3 中将边距设置为 0 */

h3 {
    margin: 0;
}
英文:

this can be fixed by modifying your '.header' class. Since there is no content in your &lt;h3&gt; tag, there is no height being assigned to the parent &lt;div&gt;. If you remove the padding from you '.header' class you can see the div disappears because it was padding the size of the margin in the h3 styles. you can fix all of this by getting rid of the padding element in your '.header' class and setting the margin for h3 to 0. Then once you type something in your heading it will be the height of the text or you can set the height manually in the header class.

.header{
width: 100%;
border-top-left-radius: 7px;
border-top-right-radius:7px;
text-align: center;             /* remove padding from this class */
color: red;
background-color:#525252 ;
}
/* set margin to 0 in h3 */
h3 {
margin: 0
}

答案2

得分: 0

问题在于给定给span的边距会将元素的长度增加到超过100%,并且部分元素会超出框架。要解决这个问题,首先从分配给span选择器的CSS中移除"margin: 20px;"。然后,将每个span放入一个带有所需类别(例如"span-container")的div标记中,如下所示:

<div class="span-container">
    <span>               
    </span>
</div>

<div class="span-container">
    <span>               
    </span>
</div>

<div class="span-container">
    <span>               
    </span>
</div>

<div class="span-container">
    <span>               
    </span>
</div>

<div class="span-container">
    <span>
        الصف:
    </span>
</div>

最后,将以下CSS代码添加到您的CSS样式中:

.span-container { padding: 20px;}
英文:

The problem is that the margin given to the span increases the length of the element to more than 100%, and part of the element is out of the frame. To fix the issue, first, remove "margin: 20px;" from the assigned CSS for the span selector. Then, put each of the spans in a div tag with the desired class (such as "span-container") like this:

&lt;div class=&quot;span-container&quot;&gt;
&lt;span&gt;               
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;span-container&quot;&gt;
&lt;span&gt;               
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;span-container&quot;&gt;
&lt;span&gt;               
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;span-container&quot;&gt;
&lt;span&gt;               
&lt;/span&gt;
&lt;/div&gt;
&lt;/span&gt;
&lt;div class=&quot;span-container&quot;&gt;
&lt;span&gt;
الصف:
&lt;/span&gt;
&lt;/div&gt;

Finally, add the following CSS code to your CSS styles:

.span-container { padding: 20px;}

huangapple
  • 本文由 发表于 2023年7月28日 06:05:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76783686.html
匿名

发表评论

匿名网友

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

确定