Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I have a label and want it closer to the @Html.EditorFor. Its far apart with so much spaces, here is what i tried on.

What I have tried:

C#
<pre> <div class="form-group">
                        <label for="CourseName" class="col-sm-3 col-form-label">CourseName</label>
                        <div class="col-sm-5">
                            @Html.EditorFor(model => model.CourseName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "CourseName" } })
                            
                            <label for="Content Licence" class="col-sm-3 col-form-label">Content Licence</label> 
                        </div>
                    </div>
Posted
Updated 18-Aug-20 1:53am

1 solution

If you want to use the col-* classes, your parent element needs the row class:
HTML
<div class="form-group row">
It doesn't make any sense to have the "Content Licence" label inside the <div class="col-sm-5"> element, since it's not related to the Course Name input.

If you want the input to stretch to fill the available width, use col-sm instead of col-sm-5.

If you want the label to only take up the space it requires, use col-sm-auto instead of col-sm-3. This will of course mean that other fields in the same form don't line up if their labels are longer or shorter.

Alternatively, you could right-align the labels by adding text-right to their class list.

Forms · Bootstrap v4.5[^]
Grid system · Bootstrap v4.5[^]
 
Share this answer
 
Comments
gcogco10 18-Aug-20 7:57am    
Thanks Richard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900