简体   繁体   English

UL元素在父容器之外溢出

[英]UL elements being overflow outside of parent container

I am having a bit of trouble getting my li elements to stay within the parent container. 让我的li元素留在父容器中有点麻烦。 They continue to go off the right side of the page for some reason. 由于某些原因,它们继续从页面右侧移出。

Overflow: Auto seems to fix the problem, but the issue with that is that it cuts off the border and doesn't allow me to scale the li elements properly (I want to have them be about 30% width of the parent container eventually). Overflow: Auto似乎可以解决问题,但是问题在于它会切断边界并且不允许我正确缩放li元素(我希望它们最终达到父容器宽度的30%) 。

Can anyone explain why this is happening or suggest an alternative solution? 谁能解释为什么会这样或建议替代解决方案?

Here is my code: https://repl.it/KZXi/0 这是我的代码: https : //repl.it/KZXi/0

You can change the box-sizing on your list elements to include padding. 您可以更改列表元素的框大小以包括填充。

box-sizing:border-box

At the moment your list elements are 100% width + padding-left:40px and padding-right:40px so they overflow the parent container. 目前,您的列表元素为100%宽度+ padding-left:40px和padding-right:40px,因此它们溢出了父容器。

https://repl.it/KZXi/2 The problem is the by the default the box-sizing property excludes the padding, that is why your li element contain more than 100% of its parent please read https://www.w3schools.com/cssref/css3_pr_box-sizing.asp To solve just add.. https://repl.it/KZXi/2问题是默认情况下box-sizing属性不包含填充,这就是为什么您的li元素包含其父元素的100%以上的原因,请阅读https://www.w3schools .com / cssref / css3_pr_box-sizing.asp要解决,只需添加。

.answerBox {
    border: 2px solid black;
    background-color: white;
    padding: 40px;
    width: 100%;
  height: 130px;
    box-sizing: border-box;
    /*margin-left: 20px;
    margin-bottom: 30px;*/
}

https://www.w3schools.com/cssref/css3_pr_box-sizing.asp https://www.w3schools.com/cssref/css3_pr_box-sizing.asp

Try this CSS to your li : 试试这个CSS到你的li

li.answerBox {
  border: 2px solid black;
  background-color: white;
  padding: 4%;            /* <---- */
  width: 91%;             /* <---- */
  height: 70px;

The problem is, when you give padding and border, the content overflows. 问题是,当您提供填充和边框时,内容会溢出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM