将 CSS 和 Html 中的 URL 链接添加到按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16812559/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:52:36  来源:igfitidea点击:

Add URL link in CSS & Html to button

htmlcssurl

提问by user1782663

How do I change a CSS button into a button with URL link? Ive read I need to also add HTML codes?

如何将 CSS 按钮更改为带有 URL 链接的按钮?我读过我还需要添加 HTML 代码吗?

The only code for the button I can find is this one:

我能找到的按钮的唯一代码是这个:

 .ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {
position: relative;
margin-bottom: 1px;
color: #FFF;
background-color: #2265B9;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(#FCEEC1), to(#EEDC94));
background-image: -moz-linear-gradient(top, #FCEEC1, #EEDC94);
background-image: -ms-linear-gradient(top, #FCEEC1, #EEDC94);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #FCEEC1), color-stop(100%, #EEDC94));
background-image: -webkit-linear-gradient(top, #069CFF, #0A6AB6);
background-image: -o-linear-gradient(top, #FCEEC1, #EEDC94);
background-image: linear-gradient(top, #FCEEC1, #EEDC94);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fceec1', endColorstr='#eedc94', GradientType=0);
border-color: #EEDC94 #EEDC94 #E4C652;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
border-width: 1px;
border-style: solid;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

Im not sure if this is a correct question or correct codes.

我不确定这是一个正确的问题还是正确的代码。

回答by abhishekgarg

if you just want to add a link to a button then you can use

如果您只想添加到按钮的链接,那么您可以使用

<button onlick="#"><a href="http://google.com/"> Open this website</a></button>

or do you want to open the url into new page??

或者你想打开这个网址到新页面??

回答by James Donnelly

Links aren't added through CSS, they're added through the HTML:

链接不是通过 CSS 添加的,而是通过 HTML 添加的:

<a href="http://example.com">My Link</a>

If you want it to appear with the styling you've given, simply give it a .ui-state-highlightclass:

如果您希望它以您提供的样式出现,只需给它一个.ui-state-highlight类:

<a href="http://example.com" class="ui-state-highlight">My Styled Link</a>