如何在我的表单字段上添加复选标记?

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

How do I add a checkmark on my form fields?

问题

我将从一个坦白开始;我在HTML和CSS方面非常新手。尽管如此,我已经从工作中获得了一个任务,要使用HTML和CSS自定义和优化Microsoft Dynamics表单。

请求是在已填写的字段上添加复选标记,并添加一个具有淡入效果的提交按钮。然而,无论我做什么,复选标记都出现在各个地方。

我认为通过添加以下CSS样式:

.input-container {
      position: relative;
    }
    
    .checkmark {
      position: absolute;
      top: 0%;
      right: 0px;
      transform: translateY(-50%);
    }

我以为复选标记会出现在电子邮件字段中。但是结果是这样的:

丢失的复选标记。

你有什么建议吗?

谢谢!

英文:

I'll start with a confession; I'm very new with HTML and CSS. Nonetheless, I haven gotten the task from work to customise and optimise the Microsoft Dynamics forms with HTML and CSS.

The request is to add checkmarks to the field that are filled in and a submit button that has a fade effect. However, everything I do, the checkmark is all over the place.

`*/ CS`your text`S styling */ 
.input-container {
      position: relative;
    }
    
    .checkmark {
      position: absolute;
      top: 0%;
      right: 0px;
      transform: translateY(-50%);
    }`
------------------
/* HTML */

`<div style="clear:both;"></div>
</div></div>
<div data-section="true" class="">
    <div style="display: flex; width: 100%; flex-wrap: wrap;">
        <div style="clear:both;"></div>
        <div data-container="true" class="columnContainer" data-container-width="100" style="display: block; min-height: 0px; min-width: 0px; width: calc(100% - 0px); box-sizing: border-box; padding: 10px; float: left; word-wrap: break-word; word-break: break-word; word-wrap: break-word; word-break: break-word;">

            <div data-editorblocktype="Field-email" style="padding-top: 0px;">
                <div class="marketing-field">
                    <div class="lp-form-field" data-required-field="true">
                        <input aria-required="true" class="lp-form-fieldInput" data-requirederrormessage="Vul een geldig emailadres in a.u.b." id="7f685ebb-7c54-4cff-a1bc-772562d25c38" name="7f685ebb-7c54-4cff-a1bc-772562d25c38" pattern="[^@\s\\"<>)(\[\]:;,.]+(([.]{1}[^@\s\\"<>)(\[\]:;,.]+)+?|)@([^@\s\\"<>)(\[\]\+:;,\.-]+(((\.|\+|-|--)[^@\s\\"<>)(\[\]+:;,.-]+)+?|)([.][^0-9@\s\\"<>)(\[\]+:;,.-]+)+?)" placeholder="E-mail adres" required="required" style="width:100%; font-family:Gilroy, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";" title="Please enter a valid email address like example@email.com" type="email">
                        <span class="checkmark">✔</span>
                    </div>
                </div>
            </div>`

What would you suggest?

Cheers!

By adding this CSS-styling

`.input-container {
position: relative;
}

.checkmark {
  position: absolute;
  top: 0%;
  right: 0px;
  transform: translateY(-50%);
}`

I thought that the checkmark would be in the e-mail field. But this is the result:

lost Checkmark.

答案1

得分: 1

你的尝试几乎正确,position: absolute 指的是最近的父元素,其位置设置为 relative,在你的代码中,你将相对位置设置给了正确的父元素,但在 HTML 中,图标是在其外部。另外,对于勾号,使用 top: 50% 可以使其居中显示。

.lp-form-field {
  position: relative;
}

.checkmark {
  visibility: hidden;
  position: absolute;
  top: 50%;
  right: 0px;
  transform: translateY(-50%);
}

.lp-form-fieldInput:valid + .checkmark {
  visibility: visible !important; 
}
英文:

your attempt was almost right, the position: absolute refers to the nearest parent that has a position set to relative, in your code you are setting the relative position to the correct parent but in the html the icon is outside of it. Also, using top: 50% for the checkmark is centered.

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

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

.lp-form-field {
  position: relative;
}
.lp-form-fieldInput{
  width: 100%;
}

.lp-form-fieldInput:valid{
  background-color: green;
}

.checkmark {
  visibility: hidden;
  position: absolute;
  top: 50%;
  right: 0px;
  transform: translateY(-50%);
}

.lp-form-fieldInput:valid + .checkmark{
  visibility: visible !important; 
}

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

&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;div data-section=&quot;true&quot; class=&quot;&quot;&gt;
    &lt;div style=&quot;display: flex; width: 100%; flex-wrap: wrap;&quot;&gt;
        &lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;
        &lt;div data-container=&quot;true&quot; class=&quot;columnContainer&quot; data-container-width=&quot;100&quot; style=&quot;display: block; min-height: 0px; min-width: 0px; width: calc(100% - 0px); box-sizing: border-box; padding: 10px; float: left; word-wrap: break-word; word-break: break-word; word-wrap: break-word; word-break: break-word;&quot;&gt;
            &lt;div data-editorblocktype=&quot;Field-email&quot; style=&quot;padding-top: 0px;&quot;&gt;
                &lt;div class=&quot;marketing-field&quot;&gt;
                    &lt;div class=&quot;lp-form-field&quot; data-required-field=&quot;true&quot;&gt;
                        &lt;input aria-required=&quot;true&quot; class=&quot;lp-form-fieldInput&quot; data-requirederrormessage=&quot;Vul een geldig emailadres in a.u.b.&quot; id=&quot;7f685ebb-7c54-4cff-a1bc-772562d25c38&quot; name=&quot;7f685ebb-7c54-4cff-a1bc-772562d25c38&quot; pattern=&quot;[^@\s\\&amp;quot;&lt;&gt;)(\[\]:;,.]+(([.]{1}[^@\s\\&amp;quot;&lt;&gt;)(\[\]:;,.]+)+?|)@([^@\s\\&amp;quot;&lt;&gt;)(\[\]\+:;,\.-]+(((\.|\+|-|--)[^@\s\\&amp;quot;&lt;&gt;)(\[\]+:;,.-]+)+?|)([.][^0-9@\s\\&amp;quot;&lt;&gt;)(\[\]+:;,.-]+)+?)&quot; placeholder=&quot;E-mail adres&quot; required=&quot;required&quot; style=&quot;width:100%; font-family:Gilroy, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, Arial, &amp;quot;Noto Sans&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;;&quot; title=&quot;Please enter a valid email address like example@email.com&quot; type=&quot;email&quot;&gt;
                      &lt;span class=&quot;checkmark&quot;&gt;&amp;#10004;&lt;/span&gt; 
                    &lt;/div&gt;
                   &lt;div class=&quot;lp-form-field&quot; data-required-field=&quot;true&quot;&gt;
                        &lt;input aria-required=&quot;true&quot; class=&quot;lp-form-fieldInput&quot; data-requirederrormessage=&quot;Vul een geldig emailadres in a.u.b.&quot; id=&quot;7f685ebb-7c54-4cff-a1bc-772562d25c38&quot; name=&quot;7f685ebb-7c54-4cff-a1bc-772562d25c38&quot; pattern=&quot;[^@\s\\&amp;quot;&lt;&gt;)(\[\]:;,.]+(([.]{1}[^@\s\\&amp;quot;&lt;&gt;)(\[\]:;,.]+)+?|)@([^@\s\\&amp;quot;&lt;&gt;)(\[\]\+:;,\.-]+(((\.|\+|-|--)[^@\s\\&amp;quot;&lt;&gt;)(\[\]+:;,.-]+)+?|)([.][^0-9@\s\\&amp;quot;&lt;&gt;)(\[\]+:;,.-]+)+?)&quot; placeholder=&quot;E-mail adres&quot; required=&quot;required&quot; style=&quot;width:100%; font-family:Gilroy, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, Arial, &amp;quot;Noto Sans&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;;&quot; title=&quot;Please enter a valid email address like example@email.com&quot; type=&quot;email&quot; value=&quot;example@gmail.com&quot;&gt;
                      &lt;span class=&quot;checkmark&quot;&gt;&amp;#10004;&lt;/span&gt; 
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月13日 18:55:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678582.html
匿名

发表评论

匿名网友

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

确定