NepCoder
NepCoder

Reputation: 439

Add Css to dynamically created label and textbox

I am dynamically creating the label and textbox in my C# code and am having issues with css formatting. Since the label and textbox are generated separately adding css to it to float left and add padding has been a challenge. I am new to c# and would appreciate any help.

I tried adding the cssClass to both the text box and label but the formatting is off.

Here is my css:

.form-control{
    margin-bottom:10px;
    width:300px;
    float:left;
}

.form-control-label{
    display:block;
    float:left;
}

I added the css class in the script side using

label.CssClass = "form-control-label";
textbox.CssClass = "form-control"

Here is the output and expected resultenter image description here

Upvotes: 0

Views: 1539

Answers (1)

Martin Parenteau
Martin Parenteau

Reputation: 73791

Not sure about the text alignment that you expect for the Labels, but you can try the following style classes:

.form-control
{
    float: left;
    width: 300px;
}
.form-control-label
{
    clear: left;
    float: left;
    width: 120px;
    text-align: left;
}

If you prefer the Label texts to be right aligned, you can change the style for:

.form-control-label
{
    clear: left;
    float: left;
    width: 120px;
    text-align: right;
    margin-right: 8px;
}

Upvotes: 3

Related Questions