css label width not taking effect

前端 未结 6 1041
青春惊慌失措
青春惊慌失措 2020-12-23 02:37

I have a generic form, which I\'d like to style to align the labels and the input fields. For some reason when I give a width to the label selector, nothing happens:

6条回答
  •  悲&欢浪女
    2020-12-23 03:11

    Use display: inline-block;

    Explanation:

    The label is an inline element, meaning it is only as big as it needs to be.

    Set the display property to either inline-block or block in order for the width property to take effect.

    Example:

    #report-upload-form {
        background-color: #316091;
        color: #ddeff1;
        font-weight: bold;
        margin: 23px auto 0 auto;
        border-radius: 10px;
        width: 650px;
        box-shadow: 0 0 2px 2px #d9d9d9;
    
    }
    
    #report-upload-form label {
        padding-left: 26px;
        width: 125px;
        text-transform: uppercase;
        display: inline-block;
    }
    
    #report-upload-form input[type=text], 
    #report-upload-form input[type=file],
    #report-upload-form textarea {
        width: 305px;
    }

提交回复
热议问题