Html 如何使字形作为提交按钮工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34127151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a glyphicon work as a submit button?
提问by Raviteja
I have a button of type Submit
with text as edit
for POST method in asp.net HTML.BeginForm.I want to replace it with a glyphicon-edit
.How to achieve the same functionality as input
.I am able to achieve the functionality using Edit button.I want the same functionality using glyphicon-edit
我在asp.net HTML.BeginForm 中有一个Submit
带有文本类型的按钮,edit
对于POST 方法。我想用一个替换它。glyphicon-edit
如何实现相同的功能input
。我能够使用编辑按钮实现该功能。我想要使用相同的功能glyphicon-edit
HTML
HTML
<br />
<input type="submit" class="btn btn-default" name="Editing" value="Edit" />
<div class="circle">
<div class="glyphicon glyphicon-edit"></div>
</div>
CSS and Look of glyphicon-edit
is included in a fiddle here
CSS 和 Look ofglyphicon-edit
包含在此处的小提琴中
回答by Suman K.C
You can write a button with a type submit
and wrap an glyphicon inside
你可以写一个带有类型的按钮submit
并在里面包裹一个字形
<button type="submit">
<span class="glyphicon glyphicon-edit"></span>
</button>
Edit :
编辑 :
- The button style will applied to glyphicon, but you can remote the default button css properties (for eg.
background:none;border:none;padding:0;
) and apply new style - onclick border appears ? -
outline:none
should solve the outline border issue onclick.
- 按钮样式将应用于 glyphicon,但您可以远程默认按钮 css 属性(例如
background:none;border:none;padding:0;
)并应用新样式 - 出现onclick边框?-
outline:none
应该解决点击时的轮廓边框问题。
回答by Noopur Dabhi
Use above html and css:
使用上面的 html 和 css:
Html:
网址:
<div class="circle">
<button type="submit" class="submit-with-icon">
<span class="glyphicon glyphicon-edit"></span>
</button>
</div>
Css :
css :
.circle {
border-radius: 100%;
border: 0.25em solid black;
height: 50px;
width: 50px;
}
.glyphicon.glyphicon-edit{
font-size:28px;
padding: 8px 3px 0 8px;
}
.submit-with-icon {
background: transparent;
border: 0px;
padding: 0;
outline: 0;
}
.circle:active {
content: '';
background-color: rgb(235, 235, 235);
border-color: rgb(173, 173, 173);
}
I've added one class named submit-with-icon
in which I'm removing border and making background transparent.
我添加了一个名为的类submit-with-icon
,其中我正在删除边框并使背景透明。
Here is working fiddle.
这是工作小提琴。
回答by misterManSam
From what I can see, there is no need to use other elements. Use a <button>
element for the submit button, instead of <input>
, and apply the glyphicon-edit
class directly to it.
据我所知,没有必要使用其他元素。<button>
为提交按钮使用一个元素,而不是<input>
,并将glyphicon-edit
类直接应用到它。
Style the hover, focus and active states as desired and remove the default focus outline.
The glyph is vertically centered with
line-height
.
根据需要设置悬停、焦点和活动状态的样式,并删除默认的焦点轮廓。
字形以 垂直居中
line-height
。
Example
例子
.glyphicon.glyphicon-edit {
font-size: 25px;
line-height: 45px;
border-radius: 50%;
border: 3px solid black;
height: 50px;
width: 50px;
background: none;
transition: color .3s, background .3s;
/*box-shadow helps soften the choppy circle*/
box-shadow: 0 0 1px #000, inset 0 0 2px #000;
}
.glyphicon.glyphicon-edit:hover {
background: #000;
color: #FFF;
}
.glyphicon.glyphicon-edit:focus {
border-color: blue;
outline: none;
}
.glyphicon.glyphicon-edit:active {
border-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="https://jsfiddle.net/iamraviteja/DTcHh/14991/netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet" />
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<button class="glyphicon glyphicon-edit" name="Editing" value="Edit"></button>
回答by Jinu Kurian
Try this :)
尝试这个 :)
.circle {
border-radius: 100%;
border: 0.25em solid black;
height: 50px;
width: 50px;
}
.glyphicon.glyphicon-edit {
font-size: 28px;
padding: 8px 0 0 3px;
}
.circle button {
background: none;
border: none;
outline: none;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="circle">
<button type="submit">
<span class="glyphicon glyphicon-edit"></span>
</button>
</div>