简体   繁体   中英

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 result 在此处输入图片说明

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM