开发者

MVC view element aligning problem

开发者 https://www.devze.com 2023-04-02 22:19 出处:网络
This is probably a dump question but I can\'t find a way to align the secondelements on the view. Tried using width on the display-labels but it does not affect anything; the display-fields start imme

This is probably a dump question but I can't find a way to align the second elements on the view. Tried using width on the display-labels but it does not affect anything; the display-fields start immediatelly after the labels. What should to manipulate the width of the labels?

Update

<div>
    <div class="display-label">Name:</div >
    <div class="display-field"><%: Model.personalInfo.FirstNa开发者_JAVA百科me + " " + Model.personalInfo.LastName%></div >
</div>
<div>
    <div class="display-label">Date of Birth:</div >
    <div class="display-field"><%: Model.personalInfo.DOB.ToShortDateString() %></div >
</div>

Here is the css

.display-label
{
margin: 0.5em 0;
font-weight:bold;
padding: 0.5em 0;
width: 10em;
float: left;
}

.display-field
{
margin: 0.5em 0;
padding: 0.5em 0;
}


Put the labels in divs with float: left rule and fixed width. Also put the values in divs.

<div>
    <div class="display-label">Name:</div>
    <div><%: Model.personalInfo.FirstName + " " + Model.personalInfo.LastName%></div>
</div>
<div>
    <div class="display-label">Date of Birth:</div>
    <div><%: Model.personalInfo.DOB.ToShortDateString() %></div>
</div>

and then:

.display-label {
    float: left;
    width: 200px;
}

and a live demo.

Or if for some cryptic reason you cannot change those spans to divs you could also display them as blocks (a.k.a divs):

.display-label {
    display: block;
    float: left;
    width: 200px;
}

.display-field {
    display: block;
}


Apply your margin and padding to the parent div

0

精彩评论

暂无评论...
验证码 换一张
取 消