My html page has a container, a left div and a right div. Both of left and right div are enclosed within the container, having width as 20% and 80% respectively.
The Problem
In #right
div I have a fieldset
who's width
is set as auto
. This fieldset
have two html elements of class .form-label
and .form-input
both having a equal width of 48%
. The problem is that if one of my label has large text (not larger than the space available in right div and with respect to all rules) than the fieldset is only expanded upto a particular width and after that my label and input element instead staying on same line are moved into two different lines. This happens even if there is still the space for the div to expand.
Note: I want to point out that even though the issue is applicable to both firefox and chrome but, the issue is more visible in chrome even with mid lenght of text as given in the example.
Here is the code: [Please see the output at fullscreen to understand the issue]
.container
{
box-sizing: border-box;
max-width: 100%;
position:relative;
float:bottom;
height: 100%;
margin: 6rem 0 1.5rem 0;
overflow-x: auto;
clear: both;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap:nowrap;
flex-basis:0;
align-items:stretch;
justify-content: center;
}
#left{
margin: 0;
width:20%;
padding: 4px 4px 4px 4px;
color: #000011;
font-weight:bold;
text-align: center;
order:0;
flex-order: 0;
-webkit-order: 0;
-ms-flex-order: 0;
align-self:stretch;
}
#right{
margin-top: 0;
width: 80%;
padding: 4px 4px 4px 6px;
text-align: center;
flex-order: 1;
order:1;
-webkit-order: 1;
-ms-flex-order: 1;
align-self:stretch;
overflow: auto;
}
.form{
text-align:right !important;
}
.form-input{
width:48%;
margin-left:0.5rem !important;
margin-bottom: 0.5rem !important;
vertical-align: middle;
display: inline-block;
text-align: left;
}
.form-label{
width:48%;
margin-right: 0.5rem;
margin-bottom: 0.5rem;
vertical-align: super ;
}
.form-button{
width:auto;
margin-top: 1rem;
}
fieldset{
width: auto;
max-width: 100%;
display:inline;
margin: 1rem auto 2rem auto;
border-radius: 0.5rem;
border: 3px double #000000;
}
<div class="container">
<div id="left">
blah blah balah blah blah.......
</div>
<div id="right">
<fieldset class="form">
<legend class="fit-title-blackgrad">Defaulter List Selection</legend>
<div>
<label class="form-label">Select Semester</label>
<select class="form-input selecttodiv" name="dsem" id="dsem" tabindex="1" required=""><option value="">------</option><option value="I">I</option><option value="II">II</option><option value="III">III</option><option value="IV">IV</option><option value="V">V</option><option value="VI">VI</option><option value="VII">VII</option><option value="VIII">VIII</option> </select>
</div>
<div>
<label class="form-label">From (Month)</label>
<select class="form-input" name="dfmonth" id="dfmonth" tabindex="2" required=""><option value="">------</option><option value="7">July</option> </select>
</div>
<div>
<label class="form-label">Cut-Off Percentage........................</label>
<input class="form-input" type="number" min="50" max="75" name="dcutoff" id="dcutoff" tabindex="4" value="75" required="">
</div>
<div>
<input type="submit" class="button form-button" value="Load">
</div>
</fieldset>
</div>
</div>
I have gone through various post, however I am unable to find a solution.
I hope somebody helps me here.
Thanks in advance for any help.
UPDATE
Let me explain in detail what is happening exactly.
The width of #right
container is 1071px in fullscreen. fieldset
which is the container of form elements in #right
div is an inline
element, because I don't want it to occupy fullscreen but, in case if it have that much content. Hence fieldset
can occupy max-width
of 100%
. Now the total width
of fieldset
is distributed equally among .form-input
and .form-label
(viz width:48%
). Both of the said element is enclosed in the div which does not have any css property assigned to it except overflow:hidden;'. Hence considering the width of 1066px, each of
.form-inputand '.form-label
should be able to occupy maximum width of 511px
. But this does not happen in mycase.
If you see the given example in full screen. You will find that even if the total space of 1066px available in #right
div. My cut-off percentage... label occupy only 272px
and the corresponding input occupies around 229px
. This two elements appears on two different line even though they should appear on same line. Also the sum of their width's+margins+paddings+borders=524px
which is much less than the total space available i.e. 1066px. Even if I add padding,margin and border of fieldset
, the total width comes out to be 550px.
So my question is that why does the fieldset does not expand as per the width of its inner content and what could i do to overcome this without hampering my site layout.
Note: I don't want label to break into separate line, so display:inline-block;
alone is not an option in this case. I had also tried setting white-space:nowrap
but, this lead to truncation of my string i.e it keeps flowing towards right until it is made hidden by coming input element at right.
min-widthand
max-width` are removed because it does not serve any purpose as i have realized while discussing the problem with @Ankush