简体   繁体   English

在按钮值中添加HTML图标

[英]Add html icon in button value

<input type="submit" id="appCreate" name="Reds" value="Reds" formaction=@Url.Action("") formmethod="post" class="btn btn-success btn-block" onclick="javascript: return SubmitForm(this);" />

CSS - CSS-

.reddot {
  content: "\25cf";
  font-size: 1.5em;
  color: red;
}

I want to add <span class="reddot"></span> to the value of my button (it just creates a red dot icon). 我想将<span class="reddot"></span>到按钮的值(它只会创建一个红点图标)。 So the value of my button shown is Reds<red dot icon> 所以我显示的按钮的值为Reds<red dot icon>

How can I do this? 我怎样才能做到这一点?

Instead of content: "\\25cf"; 而不是content: "\\25cf"; Try background: url('xyz.png'); 尝试background: url('xyz.png');

<input> elements are considered void elements, therefore they cannot contain children. <input>元素被视为void元素,因此它们不能包含子元素。 You could use a <button> element, but personally I'd discourage this method because the HTML spec deems it invalid. 可以使用<button>元素,但我个人不建议使用此方法,因为HTML规范认为该方法无效。

One possible solution is to wrap the button in a container. 一种可能的解决方案是将按钮包装在容器中。 That container could have a pseudo-element ( ::after ) that places the red dot for you. 该容器可以有一个伪元素( ::after )为您放置红点。

 .reddot { display: inline-block; position: relative; } .reddot > input[type=submit] { text-align: left; padding-right: 20px; /* Add padding to make space for the dot */ } .reddot::after { /* Place an element inside of .reddot */ display: block; position: absolute; top: 50%; transform: translateY(-50%); /* Center it vertically */ right: 5px; /* 5px off the right edge */ content: "\\25cf"; font-size: 1.5em; color: red; pointer-events: none; /* Make sure the dot doesn't block the button */ } 
 <div class="reddot"> <input type="submit" /> </div> <div class="reddot"> <input type="submit" value="Here's another button with a red dot!" /> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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