[英]2 inline div's, 2nd one won't fit in line with the 1st one
I'm trying to get the first div, '#grp1', left-aligned and inline with the second div, '#grp2'. 我正在尝试将第一个div'#grp1'左对齐并与第二个div'#grp2'内联。 Both divs have 2 input elements in them which are vertically aligned within their divs.
两个div中都有2个输入元素,它们在其div中垂直对齐。
The issue is that the grp2 div isn't scaling its width to fit onto the same line. 问题是grp2 div的宽度没有按比例缩放以适合同一行。 I keep resetting its width, but the console element inspector shows it isn't reducing on the page.
我一直在重置其宽度,但控制台元素检查器显示页面上的宽度没有减少。 I've gotten them on the same line only by reducing the with of grp1.
我仅通过减少grp1的使用使它们处于同一行。 grp2 still wasn't changing.
grp2仍然没有改变。 I'd like everything to be much more compact.
我希望所有内容都更加紧凑。
Thank you very much. 非常感谢你。 If you have a sec, I'd appreciate some detail as to why the grp2 div isn't scaling at all;
如果您有时间,我将对grp2 div为何根本不扩展的一些细节表示赞赏; I seem to keep getting stuck on markup issues.
我似乎总是在标记问题上陷入困境。
legend{ color: RGB(25, 115, 115); } .label { float:left; width:60%; margin-top: 5px; font-weight:bold; color: RGB(25,90,90); font-size: 18; font-weight: 8; font-family: 'Open Sans Condensed', sans-serif; } .form-text{ color: RGB(100,100,100); font-size: 15; font-weight: 6; font-family: 'Open Sans Condensed', sans-serif; margin-top: 3px; } .grp1{ float: left; width: 40%; position: relative; } .grp2{ position: relative; margin-left: 45%; } select{ margin-bottom: 29px; } .err{ font-size: 15; font-style: italic; color: RGB(180,100,100); }
<div id="form-input"> <form id="form"> <fieldset> <legend class='form-text' style='font-size:20'>Hello World</legend> <div id='grp1' style='display:inline-block' class='grp1'> <label for='subject'style='display:block' class='label'> Choose your subject.<br> <input type="text" id="subject" name='subject' style="display:block" class='form-text'><br> </label> <label for='mode' style='display:block' class='label'> Select your search mode.<br> <select name="mode" form="form-input" id="mode" class='form-text' onchange="buttonHandler(this)"> <option value="1">Search</option> <option value="2">Live</option> </select> </label> </div> <div id='grp2' style='display:inline-block' class='grp2'> <label for='startdate' style='display:block' id='startlabel' class='label'> Choose a start date for a search, up to one week ago: <br> <input type="text" id="startdate" value="" placeholder="day/month/2016" style="display:block" class='form-text'><br> <div name="error1" id="starterror" style="display:none" class='err'></div> </label> <label for='enddate' style='display:block' id='endlabel' class='label'> Choose an end date for your search: <br> <input type="text" id="enddate" style="display:block" class='form-text'><br> <div name="error2" id="enderror" style="display:none" class='err'></div> </label> </div> </fieldset> </form> </div>
Since you have made it relative, no need to give 45% margin. 由于您已将其设为相对,因此无需提供45%的保证金。 Just remove it, and it will work.
只需将其删除,它将起作用。
legend{ color: RGB(25, 115, 115); } .label { float:left; width:60%; margin-top: 5px; font-weight:bold; color: RGB(25,90,90); font-size: 18; font-weight: 8; font-family: 'Open Sans Condensed', sans-serif; } .form-text{ color: RGB(100,100,100); font-size: 15; font-weight: 6; font-family: 'Open Sans Condensed', sans-serif; margin-top: 3px; } .grp1{ float: left; width: 40%; position: relative; } .grp2{ position: relative; } select{ margin-bottom: 29px; } .err{ font-size: 15; font-style: italic; color: RGB(180,100,100); }
<div id="form-input"> <form id="form"> <fieldset> <legend class='form-text' style='font-size:20'>Hello World</legend> <div id='grp1' style='display:inline-block' class='grp1'> <label for='subject'style='display:block' class='label'> Choose your subject.<br> <input type="text" id="subject" name='subject' style="display:block" class='form-text'><br> </label> <label for='mode' style='display:block' class='label'> Select your search mode.<br> <select name="mode" form="form-input" id="mode" class='form-text' onchange="buttonHandler(this)"> <option value="1">Search</option> <option value="2">Live</option> </select> </label> </div> <div id='grp2' style='display:inline-block' class='grp2'> <label for='startdate' style='display:block' id='startlabel' class='label'> Choose a start date for a search, up to one week ago: <br> <input type="text" id="startdate" value="" placeholder="day/month/2016" style="display:block" class='form-text'><br> <div name="error1" id="starterror" style="display:none" class='err'></div> </label> <label for='enddate' style='display:block' id='endlabel' class='label'> Choose an end date for your search: <br> <input type="text" id="enddate" style="display:block" class='form-text'><br> <div name="error2" id="enderror" style="display:none" class='err'></div> </label> </div> </fieldset> </form> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.