英文:
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\\&quot;<>)(\[\]:;,.]+(([.]{1}[^@\s\\&quot;<>)(\[\]:;,.]+)+?|)@([^@\s\\&quot;<>)(\[\]\+:;,\.-]+(((\.|\+|-|--)[^@\s\\&quot;<>)(\[\]+:;,.-]+)+?|)([.][^0-9@\s\\&quot;<>)(\[\]+:;,.-]+)+?)" placeholder="E-mail adres" required="required" style="width:100%; font-family:Gilroy, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;;" title="Please enter a valid email address like example@email.com" type="email">
<span class="checkmark">&#10004;</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:
答案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 -->
<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\\&quot;<>)(\[\]:;,.]+(([.]{1}[^@\s\\&quot;<>)(\[\]:;,.]+)+?|)@([^@\s\\&quot;<>)(\[\]\+:;,\.-]+(((\.|\+|-|--)[^@\s\\&quot;<>)(\[\]+:;,.-]+)+?|)([.][^0-9@\s\\&quot;<>)(\[\]+:;,.-]+)+?)" placeholder="E-mail adres" required="required" style="width:100%; font-family:Gilroy, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;;" title="Please enter a valid email address like example@email.com" type="email">
<span class="checkmark">&#10004;</span>
</div>
<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\\&quot;<>)(\[\]:;,.]+(([.]{1}[^@\s\\&quot;<>)(\[\]:;,.]+)+?|)@([^@\s\\&quot;<>)(\[\]\+:;,\.-]+(((\.|\+|-|--)[^@\s\\&quot;<>)(\[\]+:;,.-]+)+?|)([.][^0-9@\s\\&quot;<>)(\[\]+:;,.-]+)+?)" placeholder="E-mail adres" required="required" style="width:100%; font-family:Gilroy, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;;" title="Please enter a valid email address like example@email.com" type="email" value="example@gmail.com">
<span class="checkmark">&#10004;</span>
</div>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论