为什么在验证和InputTextArea元素之间存在无法解释的间隙?

huangapple go评论65阅读模式
英文:

Why is there an unexplainable gap between the validation and the InputTextArea elements?

问题

有输入框(InputTextArea)和其验证之间似乎存在一个小间隙。我使用了F12,但没有填充、边距等引起这个间隙。上面的普通InputText没有任何间隙,但下面的区域有?我附上了包含输入元素和相关CSS的表单。

    <EditForm Model=product OnValidSubmit="HandleSubmit">
        @* 模型作为EditContext的一部分传递给HandleSubmit *@

        <DataAnnotationsValidator />

        <div class="formSegment">
            <h1 class="heading">产品注册表单</h1>
            <p class="headingText">请填写必需信息</p>
        </div>

        <div class="formSegment">
            <h4>产品信息</h4>

            <label for="NameInput">名称:</label>
            <InputText id="NameInput" @bind-Value="product.Name" maxlength="100"></InputText>
            <ValidationMessage For="@(() => product.Name)" />

            <label for="KeywordsInput">关键词:</label>
            <InputText id="KeywordsInput" @bind-Value="product.Keywords" maxlength="3000" </InputText>
            <ValidationMessage For="@(() => product.Keywords)" />

            <label for="DescriptionInput">描述:</label>
            <InputTextArea id="DescriptionInput" @bind-Value="product.Description" maxlength="3000"  rows="3"></InputTextArea>
            <ValidationMessage For="@(() => product.Description)" />

            <label for="AdditionalInformationInput">附加信息:</label>
            <InputTextArea id="AdditionalInformationInput" @bind-Value="product.AdditionalInformation" maxlength="3000" rows="3"></InputTextArea>
            <ValidationMessage For="@(() => product.AdditionalInformation)" />

            <button type="submit" class="btn-primary">添加</button>
            <button type="submit" class="btn-secondary">取消</button>
        </EditForm>
/*Section CSS*/
    .heading {
       margin-bottom:0.35em;
        text-align: center;
    }
        
    .headingText {
        margin: 0.5em auto;
        text-align: center;
    }
        
    form {
        width: 60vw;
        max-width: 600px;
        min-width: 500px;
        margin: 0 auto;
        padding-bottom: 2em;
    }
       
    
    label {
        margin: 0.5rem 0;
        margin-bottom:auto
    }
            
    input {
        width: 100%;
        min-height: 2em;
    }
      
    textarea {
        width: 100%;
        min-height: 3em;
        max-height: 8em;
    }


    .formSegment {
        padding: 1rem 0;
        border-bottom: 3px solid #3b3b4f;
    }
      
    .formSegment:last-of-type {
        border-bottom: none;
    }
英文:

There seems to be a small gap between the InputTextArea and its validation. I've used F12 and there is no padding, margins ext. causing this gap. The normal InputText above it has no gaps at all but the area below does? I've attached the form the input elements are in and any CSS associated with it.

 <EditForm Model=product OnValidSubmit="HandleSubmit">
            @* the model is passed to HandleSubmit as part of the EditContext*@
            <DataAnnotationsValidator />

            <div class="formSegment">
                <h1 class="heading">Product Registration Form</h1>
                <p class="headingText">Please fill out this form with the required information</p>
            </div>

            <div class="formSegment">
                <h4>product Information</h4>

                <label for="NameInput">Name:</label>
                <InputText id="NameInput" @bind-Value="product.Name" maxlength="100"></InputText>
                <ValidationMessage For="@(() => product.Name)" />

                <label for="KeywordsInput">Keywords:</label>
                <InputText id="KeywordsInput" @bind-Value="product.Keywords" maxlength="3000" </InputText>
                <ValidationMessage For="@(() => product.Keywords)" />
                  
                <label for="DescriptionInput">Description:</label>
                <InputTextArea id="DescriptionInput" @bind-Value="product.Description" maxlength="3000"  rows="3"></InputTextArea>
                <ValidationMessage For="@(() => product.Description)" />

                

                <label for="AdditionalInformationInput">Additional Information:</label>
                <InputTextArea id="AdditionalInformationInput" @bind-Value="product.AdditionalInformation" maxlength="3000" rows="3"></InputTextArea>
                <ValidationMessage For="@(() => product.AdditionalInformation)" />
                                  
       
            <button type="submit" class="btn-primary">Add</button>
            <button type="submit" class="btn-secondary">Cancel</button>

        </EditForm>    



/*Section CSS*/
.heading {
   margin-bottom:0.35em;
    text-align: center;
}
    
.headingText {
    margin: 0.5em auto;
    text-align: center;
}
    
form {
    width: 60vw;
    max-width: 600px;
    min-width: 500px;
    margin: 0 auto;
    padding-bottom: 2em;
}
   

label {
    margin: 0.5rem 0;
    margin-bottom:auto
}
        
input {
    width: 100%;
    min-height: 2em;
}
  
textarea {
    width: 100%;
    min-height: 3em;
    max-height: 8em;
}


.formSegment {
    padding: 1rem 0;
    border-bottom: 3px solid #3b3b4f;
}
  
.formSegment:last-of-type {
    border-bottom: none;
}

答案1

得分: 1

这与为下行字符创建的空间有关(请参阅文章中的更多10.com)。请注意,Firefox不会为下行字符创建空间,而Chrome会。

内联显示

为什么在验证和InputTextArea元素之间存在无法解释的间隙?

块显示

为什么在验证和InputTextArea元素之间存在无法解释的间隙?

设置 textarea { display: block; } 可以去除它。下面是示例代码:

textarea {
  width: 100%;
}

.block {
  display: block;
}
<textarea></textarea> 示例文本 - 有间隙
<textarea class='block'></textarea> 示例文本 - 更小的间隙
英文:

It's to do with the space created for descenders (see article on more10.com). Note that firefox doesn't make space for the descender whereas Chrome does.

Inline display

为什么在验证和InputTextArea元素之间存在无法解释的间隙?

Block display

为什么在验证和InputTextArea元素之间存在无法解释的间隙?

Set textarea { display: block; } to remove it. Sample code below

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

textarea {
  width: 100%;
}

.block {
  display: block;
}

<!-- language: lang-html -->

&lt;textarea&gt;&lt;/textarea&gt; Sample Text - gap
&lt;textarea class=&#39;block&#39;&gt;&lt;/textarea&gt; Sample Text - smaller gap

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月16日 17:16:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定