IT story

html 링크를 단추처럼 보이게하려면 어떻게합니까?

hot-time 2020. 6. 21. 19:25
반응형

html 링크를 단추처럼 보이게하려면 어떻게합니까?


ASP.NET을 사용하고 있는데 일부 버튼은 리디렉션 만 수행합니다. 차라리 일반 링크 였지만 사용자가 모양에 큰 차이를 느끼지 않기를 바랍니다. 태그로 앵커로 둘러싸인 이미지를 고려했지만 버튼에서 텍스트를 변경할 때마다 이미지 편집기를 실행하고 싶지는 않습니다.


이 클래스를 적용하십시오

.button {
  font: bold 11px Arial;
  text-decoration: none;
  background-color: #EEEEEE;
  color: #333333;
  padding: 2px 6px 2px 6px;
  border-top: 1px solid #CCCCCC;
  border-right: 1px solid #333333;
  border-bottom: 1px solid #333333;
  border-left: 1px solid #CCCCCC;
}
<a href="#" class="button">Example</a>


내가 생각하는 것처럼 바보처럼 나는이 고대 질문을 게시 할 것입니다.

버튼 요소 주위에 앵커 태그를 감쌀 이유는 무엇입니까?

<a href="somepage.html"><button type="button">Text of Some Page</button></a>

이 게시물을 읽고 원하는 결과없이 허용 된 답변을 시도한 후 위의 방법을 시도하고 원하는 것을 정확하게 얻었습니다.

노트

이것은 IE9 +, Chrome, Safari, Firefox 및 Opera에서만 작동합니다.


IMHO, 더 좋고 더 우아한 솔루션이 있습니다. 귀하의 링크가 다음과 같은 경우 :

<a href="http://www.example.com">Click me!!!</a>

해당 버튼은 다음과 같아야합니다.

<form method="GET" action="http://www.example.com">
<input type="submit" value="Click me!!!">
</form>

이 방법은 간단한 html 요소를 사용하기 때문에 더 간단하므로 아무 것도 변경하지 않고 모든 브라우저에서 작동 합니다. 또한 버튼 스타일이있는 경우이 솔루션은 새 버튼에 동일한 스타일을 무료로 적용합니다.


CSS3 appearance속성은 브라우저의 내장 스타일로 모든 요소 (앵커 포함)의 스타일을 지정하는 간단한 방법을 제공 <button>합니다.

a.btn {
  -webkit-appearance: button;
  -moz-appearance: button;
  appearance: button;
}
<body>
  <a class="btn">CSS Button</a>
</body>

CSS 트릭 에는 이에 대한 자세한 내용이 포함 된 멋진 개요가 있습니다. caniuse.com에 따르면 현재 Internet Explorer 버전에서는이를 지원하지 않습니다 .


a {
    display: block;
    height: 20px;
    width: auto;
    border: 1px solid #000;
}

<a>블록 표시를 제공하면 이와 같은 태그로 재생할 수 있습니다 . 테두리 느낌을 조정하여 해당 버튼 느낌에 대한 음영 효과와 배경색을 줄 수 있습니다. :)


모서리가 둥근 멋진 버튼을 원한다면이 클래스를 사용하십시오.

.link_button {
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    border: solid 1px #20538D;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
    -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
    -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
    background: #4479BA;
    color: #FFF;
    padding: 8px 12px;
    text-decoration: none;
}
<a href="#" class="link_button">Example</a>


TStamper가 말했듯이 CSS 클래스를 적용하고 디자인 할 수 있습니다. CSS가 링크로 할 수있는 일의 수가 향상됨에 따라 이제는 테마를위한 놀라운 CSS 버튼을 만드는 데 중점을 둔 디자인 그룹이 있습니다.

예를 들어, -webkit-transition 속성 및 pseduo-classes를 사용하여 배경색으로 전환 할 수 있습니다. 이러한 디자인 중 일부는 상당히 까다로울 수 있지만 과거에는 플래시로 수행했을 수 있었던 것에 대한 환상적인 대안을 제공하고 있습니다.

예를 들어 (제 생각 에는 눈에 띄는 ) http://tympanus.net/Development/CreativeButtons/ (원본 페이지에 소스 코드가 포함 된 버튼에 대한 완전히 사용 가능한 일련의 애니메이션입니다) ). http://www.commentredirect.com/make-awesome-flat-buttons-css/ (동일한 줄에이 버튼은 훌륭하지만 최소한의 전환 효과가 있으며 새로운 "플랫"디자인 스타일을 사용합니다.)


당신은 JavaScript로 할 수 있습니다 :

  1. 로 실제 버튼의 CSS 스타일을 가져옵니다 getComputedStyle(realButton).
  2. 모든 링크에 스타일을 적용하십시오.

/* javascript, after body is loaded */
'use strict';

{ // Namespace starts (to avoid polluting root namespace).
  
  const btnCssText = window.getComputedStyle(
    document.querySelector('.used-for-btn-css-class')
  ).cssText;
  document.querySelectorAll('.btn').forEach(
    (btn) => {
      
      const _d = btn.style.display; // Hidden buttons should stay hidden.
      btn.style.cssText = btnCssText;
      btn.style.display = _d;
      
    }
  );
  
} // Namespace ends.
<body>
  <h3>Button Styled Links</h3>
  <button class="used-for-btn-css-class" style="display: none"></button>
  <a href="//github.io" class="btn">first</a>
  <a href="//github.io" class="btn">second</a>
  <button>real button</button>
  <script>/* You may put JS here. */</script>
</body>


표준 버튼을 만든 다음 링크의 배경 이미지로 사용할 수 있습니다. 그런 다음 이미지를 변경하지 않고 링크의 텍스트를 설정할 수 있습니다.

특수 렌더링 된 버튼이 아닌 경우 최상의 솔루션은 TStamper와 Ólafur Waage에서 이미 제공 한 것입니다.


이것은 CSS의 세부 사항을 조금 더 가져 와서 몇 가지 이미지를 제공합니다.

http://www.dynamicdrive.com/style/csslibrary/item/css_square_buttons/


뒤늦은 답변 :

ASP에서 처음 작업을 시작한 이래로 레슬링을 시작했습니다. 내가 찾은 최고는 다음과 같습니다.

개념 : 태그가있는 사용자 지정 컨트롤을 만듭니다. 그런 다음 버튼에 JavaScript를 사용하여 document.location을 원하는 값으로 설정하는 onclick 이벤트를 넣습니다.

컨트롤 ButtonLink를 호출하여 LinkButton과 혼동되는 경우 쉽게 얻을 수 있습니다.

aspx :

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ButtonLink.ascx.vb" Inherits="controls_ButtonLink" %>

<asp:Button runat="server" ID="button"/>

코드 뒤에 :

Partial Class controls_ButtonLink
Inherits System.Web.UI.UserControl

Dim _url As String
Dim _confirm As String

Public Property NavigateUrl As String
    Get
        Return _url
    End Get
    Set(value As String)
        _url = value
        BuildJs()
    End Set
End Property
Public Property confirm As String
    Get
        Return _confirm
    End Get
    Set(value As String)
        _confirm = value
        BuildJs()
    End Set
End Property
Public Property Text As String
    Get
        Return button.Text
    End Get
    Set(value As String)
        button.Text = value
    End Set
End Property
Public Property enabled As Boolean
    Get
        Return button.Enabled
    End Get
    Set(value As Boolean)
        button.Enabled = value
    End Set
End Property
Public Property CssClass As String
    Get
        Return button.CssClass
    End Get
    Set(value As String)
        button.CssClass = value
    End Set
End Property

Sub BuildJs()
    ' This is a little kludgey in that if the user gives a url and a confirm message, we'll build the onclick string twice.
    ' But it's not that big a deal.
    If String.IsNullOrEmpty(_url) Then
        button.OnClientClick = Nothing
    ElseIf String.IsNullOrEmpty(_confirm) Then
        button.OnClientClick = String.Format("document.location='{0}';return false;", ResolveClientUrl(_url))
    Else
        button.OnClientClick = String.Format("if (confirm('{0}')) {{document.location='{1}';}} return false;", _confirm, ResolveClientUrl(_url))
    End If
End Sub
End Class

이 체계의 장점 : 그것은 컨트롤처럼 보입니다. <ButtonLink id = "mybutton"navigateurl = "blahblah"/> 태그를 작성합니다.

결과 버튼은 "실제"HTML 버튼이므로 실제 버튼처럼 보입니다. CSS로 버튼 모양을 시뮬레이션하려고 시도한 다음 다른 브라우저에서 다른 모양으로 고심하지 않아도됩니다.

능력은 제한적이지만 더 많은 속성을 추가하여 쉽게 확장 할 수 있습니다. text, enabled 및 cssclass와 마찬가지로 대부분의 속성은 기본 버튼으로 "통과"해야 할 가능성이 큽니다.

더 간단하고 깨끗하거나 더 나은 솔루션을 가진 사람이 있다면 기뻐할 것입니다. 이것은 고통이지만 작동합니다.


이 수업을 사용하십시오. 태그 button클래스를 사용하여 적용하면 링크가 버튼과 동일하게 보입니다 a.

데모 JSFIDDLE이 있습니다

또는

또 다른 데모 JSFIDDLE입니다

.button {
    display: inline-block;
    outline: none;
    cursor: pointer;
    border: solid 1px #da7c0c;
    background: #478dad;
    text-align: center;
    text-decoration: none;
    font: 14px/100% Arial, Helvetica, sans-serif;
    padding: .5em 2em .55em;
    text-shadow: 0 1px 1px rgba(0,0,0,.3);
    -webkit-border-radius: .5em; 
    -moz-border-radius: .5em;
    border-radius: .3em;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.button:hover {
    background: #f47c20;
    background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
    background: -moz-linear-gradient(top,  #f88e11,  #f06015);
    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
}
.button:active {
    position: relative;
    top: 1px;
}

asp : LinkButton을 사용하는 것은 어떻습니까?

TStamper의 항목을 사용하여 링크 버튼을 표준 버튼처럼 보이게 만들었습니다. 그러나 text-decoration: none설정 에도 불구하고 마우스를 가져 가면 밑줄이 텍스트 아래에 표시됩니다 .

링크 버튼 style="text-decoration: none"내에 추가하여 호버 밑줄을 멈출 수있었습니다 .

<asp:LinkButton 
id="btnUpdate" 
CssClass="btnStyleTStamper" 
style="text-decoration: none" 
Text="Update Items"   
Onclick="UpdateGrid"  
runat="server"
/>

테두리, 색상 및 배경 색상 속성을 사용하면 HTML 링크와 유사한 버튼을 만들 수 있습니다!

a {
background-color: white;
color: black;
padding: 5px;
text-decoration: none;
border: 1px solid black;
}
a:hover {
background-color: black;
color: white;

}
<a href="https://stackoverflow.com/

">Open StackOverflow</a>

도움이 되었기를 바랍니다 :]


이것이 내가 사용한 것입니다. 링크 버튼은

<div class="link-button"><a href="/">Example</a></div>

CSS

/* body is sans-serif */ 

.link-button {
    margin-top:15px;
    max-width:90px;
    background-color:#eee;
    border-color:#888888;
    color:#333;
    display:inline-block;
    vertical-align:middle;
    text-align:center;
    text-decoration:none;
    align-items:flex-start;
    cursor:default;
    -webkit-appearence: push-button;
    border-style: solid;
    border-width: 1px;
    border-radius: 5px;
    font-size: 1em;
    font-family: inherit;
    border-color: #000;
    padding-left: 5px;
    padding-right: 5px;
    width: 100%;
    min-height: 30px;
}

.link-button a {
    margin-top:4px;
    display:inline-block;
    text-decoration:none;
    color:#333;
}

.link-button:hover {
    background-color:#888;
}

.link-button:active {
    background-color:#333;
}

.link-button:hover a, .link-button:active a {
    color:#fff;
}

나는 asp:Button:

<asp:Button runat="server"
            OnClientClick="return location='targetPage', true;"
            UseSubmitBehavior="False"
            Text="Button Text Here"
/>

이런 식으로 버튼의 작동은 완전히 클라이언트 측이며 버튼은에 대한 링크처럼 작동합니다 targetPage.


이것은 나를 위해 일했습니다. 버튼처럼 보이고 링크처럼 동작합니다. 예를 들어 책갈피를 지정할 수 있습니다.

<a href="mypage.aspx?param1=1" style="text-decoration:none;">
    <asp:Button PostBackUrl="mypage.aspx?param1=1" Text="my button-like link" runat="server" />
</a>

.button {
  font: bold 11px Arial;
  text-decoration: none;
  background-color: #EEEEEE;
  color: #333333;
  padding: 2px 6px 2px 6px;
  border-top: 1px solid #CCCCCC;
  border-right: 1px solid #333333;
  border-bottom: 1px solid #333333;
  border-left: 1px solid #CCCCCC;
}
<a href="#" class="button">Example</a>


아래 스 니펫을 사용하십시오.

    .a{
  color: $brn-acc-clr;
  background-color: transparent;
  border-color: #888888;

  &:hover:active{
    outline: none;
    color: #888888;
    border-color: #888888;
  }
  &:fill{
    background-color: #888888;
    color: #fff;
    box-shadow: 0 3px 10px rgba(#888888, 0.5);
    &:hover:active{
      color: #fff;
    }
    &:hover:not(:disabled){
      transform: translateY(-2px);
      background-color: darken(#888888, 4);
    }
  }
}

간단한 버튼 CSS는 이제 편집기로 놀 수 있습니다.

a {
  display: inline-block;
  background: #000000c9;
  color: #000;
  padding: 12px 24px;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
}
a:hover {
  background:#000
  cursor: pointer;
  transition: 0.3s ease-in;
}

링크 태그

<a href="#">Hover me<a>

How about using asp:LinkButton?

참고URL : https://stackoverflow.com/questions/710089/how-do-i-make-an-html-link-look-like-a-button

반응형