Reputation: 379
<div>
<fieldset>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</fieldset>
</div>
div {
width: 200px;
height: 100px;
}
How do I go about having the fieldset not exceed the size of the div?
For instance if I set the size of the div with CSS, it makes no difference as to how much space the fieldset will occupy.
How to go about this?
I would like to have two options to solve this:
one, having scroll functionality in the div
and two, having the text break up in to a new line inside the fieldset.
Upvotes: 0
Views: 2211
Reputation: 2469
You just need word-break: break-all;
on your container or fieldset
element.
Edited: Added overflow: auto;
to container element so it scrolls since it has a fixed height.
div {
height: 100px;
width: 200px;
overflow: auto;
}
fieldset {
word-break: break-all;
}
<div>
<fieldset>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</fieldset>
</div>
Upvotes: 1
Reputation: 701
Try this css code:
div {
word-break: break-all;
}
Fix this issue:
div {
height: 100px;
width: 100px;
word-break: break-all;
overflow-y: auto;
}
<div>
<fieldset>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</fieldset>
</div>
Upvotes: 5
Reputation: 591
The problem you are experiencing here is due to the fact that your test string "aaa" does not contain spaces so is not broken with line returns so the fieldset width is expanded.
Idealy you should test your layout with words such as "lorem ipsum" templates.
Upvotes: 0
Reputation: 55623
If you do not want the fieldset to exceed the fixed size of it's parent, then you'll have to allow it to have scrollbars:
div { width: 200px; height: 100px; }
fieldset { width: 100%; height: 100%; overflow: auto; }
Upvotes: 0