How to keep the size of a box constant? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to keep the size of a box constant?

Hi, i am trying to keep the size of this box below constant, ss that it does not changes no mater how many texts i put in. .card { padding:10px; font-family: arial; font-size: 20px; text-align: justify; color: black; background-color: white; border-radius: 40px; box-shadow: 20px 20px 50px grey; box-sizing: inherit; width:90%; margin:auto; }

29th Dec 2022, 10:11 AM
Aditya Aryan
Aditya Aryan - avatar
9 Answers
+ 5
don't use % for width and height. use px
29th Dec 2022, 10:33 AM
Bob_Li
Bob_Li - avatar
+ 2
You can add: overflow:scroll; It will allow text to be scrolled, if there is overflow(if text can't fit container)
29th Dec 2022, 10:18 AM
PanicS
PanicS - avatar
+ 2
I used p tag to test, but you probably have div or something. Use next code: overflow:scroll; word-break:break-word; Overflow will stop text to go outside of container vertically Word-break: break-word will break word so it goes in new line and don't overflow horizontally or test some other values for word-break If you have nested elements inside this card, set its width to 100%(width of children), this will make children not go outside of parent horizontally. More about it: https://www.w3schools.com/cssref/css3_pr_word-wrap.php https://www.w3schools.com/css/css_overflow.asp
29th Dec 2022, 11:25 AM
PanicS
PanicS - avatar
+ 2
I agree with PanicS, it's probably a word-break issue. if your words are very long and your box is small, you might have to use: word-break:break-all; from mdn web docs_, it seems like word-break: break-word is deprecated. suggested to use: word-break: normal; overflow-wrap: anywhere; https://developer.mozilla.org/en-US/docs/Web/CSS/word-break
29th Dec 2022, 11:55 AM
Bob_Li
Bob_Li - avatar
+ 1
Can you post your html code also? overflow should don't allow text to go outside of container, you used it in your code and you said it is not working. please use "+" to add code, then we can test it in editor
29th Dec 2022, 11:17 AM
PanicS
PanicS - avatar
0
Thanks for replying PanicS . Its not working, like i want a stable box inside which i can put texts. And i think overflow will work only if my box is like in a constant dimension/size. I don't know if i have done something wrong, but it keeps expanding as i type down more texts.😅
29th Dec 2022, 10:25 AM
Aditya Aryan
Aditya Aryan - avatar
0
Bob_Li thanks for the idea. So finally i got a box of constant size, but i wanted the same in windows too but lets ignore that. But the extra texts goes outside of the box. Here is my code .card { padding:10px; font-family: arial; font-size: 20px; text-align: justify; color: black; background-color: white; border-radius: 40px; box-shadow: 20px 20px 50px grey; box-sizing: inherit; width:320px; height: 550px; margin:auto; overflow: scroll; } Please help
29th Dec 2022, 10:49 AM
Aditya Aryan
Aditya Aryan - avatar
0
Use the max-width property
30th Dec 2022, 9:40 AM
TWEG
TWEG - avatar
0
Ok u can use p tags
31st Dec 2022, 7:00 AM
Aye Vincent