programing

HTML 링크를 단추처럼 만들려면 어떻게 해야 합니까?

oldcodes 2023. 8. 12. 10:40
반응형

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 요소를 사용하기 때문에 더 간단하며, 따라서 아무것도 변경하지 않고 모든 브라우저에서 작동합니다.또한 단추 스타일이 있는 경우 이 솔루션은 새 단추에 동일한 스타일을 무료로 적용합니다.

CSS3appearance속성은 브라우저의 기본 제공 기능을 사용하여 모든 요소(앵커 포함)를 스타일화할 수 있는 간단한 방법을 제공합니다.<button>스타일:

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

CSS Tricks는 이에 대한 자세한 내용이 포함된 멋진 개요를 가지고 있습니다.caniuse.com 따르면 현재 이 기능을 지원하는 Internet Explorer 버전은 없습니다.

모서리가 둥근 멋진 단추를 사용하려면 다음 클래스를 사용합니다.

.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>

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

가지고 놀 수 있습니다.<a>이와 같은 태그는 차단 디스플레이를 제공합니다.줄 수 :) 두리를테 음효버 느배경 줄을수 있니다 :)

Tsamper가 말했듯이, 당신은 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>

HTML

<a class="btn">Button</a>

CSS

  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;

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

특별한 렌더링 버튼이 없다면 가장 좋은 해결책은 TSamper와 Olafur Waage가 이미 제공한 두 가지입니다.

이것은 CSS의 세부 사항도 조금 더 자세히 설명하고 몇 가지 이미지를 제공합니다.

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

한참 뒤늦은 대답:

저는 ASP에서 처음 일을 시작한 이후로 이것을 계속 반복하며 씨름해 왔습니다.제가 생각해낸 최고의 아이디어는 다음과 같습니다.

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

LinkButton과 혼동될 경우 쉽게 헷갈릴 수 있도록 제어 ButtonLink를 호출했습니다.

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" 탐색 url="blahblah"/> 태그 하나만 작성하면 됩니다.

결과 단추는 "실제" HTML 단추이므로 실제 단추와 똑같이 보입니다.당신은 CSS로 버튼 모양을 시뮬레이션하고 다른 브라우저에서 다른 모양과 씨름할 필요가 없습니다.

기능은 제한적이지만 속성을 추가하여 쉽게 확장할 수 있습니다.대부분의 속성은 텍스트, 활성화 및 CSS 클래스에서 했던 것처럼 기본 버튼으로 "통과"해야 할 것입니다.

더 단순하고, 더 깨끗하고, 더 나은 해결책을 가진 사람이 있다면, 저는 기꺼이 그것을 듣겠습니다.이것은 고통이지만 효과가 있습니다.

이거 제가 쓰던 거예요.링크 버튼은

<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를 사용하는 것은 어떻습니까?링크 버튼?

당신은 그렇게 할 수 있습니다 - TS tamper의 엔트리를 사용하여 링크 버튼을 표준 버튼처럼 만들었습니다.하지만 밑줄은 내가 맴돌았을 때 텍스트 아래에 표시되었습니다.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>

이것이 도움이 되길 바랍니다 :]

클래스를 사용합니다.링크를 사용하여 적용할 때 버튼과 동일한 모양으로 표시됩니다.button에 관한 수업.a꼬리표를 달다

또는

여기 또 다른 데모 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;
}

.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>

나는 사용합니다.asp:Button:

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

이러한 방식으로, 버튼의 작동은 완전히 클라이언트 측이며 버튼은 마치 링크와 같은 역할을 합니다.targetPage.

아래 스니펫을 사용합니다.

    .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>

시원한 효과가 필요한 경우 마우스 커서를 놓고 그림자를 표시합니다. 다음을 사용할 수 있습니다.

    .button {
        text-decoration: none;
        padding: 15px 25px;
        font-size: 24px;
        cursor: pointer;
        text-align: center;
        text-decoration: none;
        outline: none;
        color: #fff;
        background-color: #450775;
        border: none;
        border-radius: 15px;
        box-shadow: 0 9px #e1d5ed;

    }

    .button:hover {background-color: #220440}

    .button:active {
        background-color: #230545;
        box-shadow: 0 5px #e1d5ed;
        transform: translateY(4px);
    }

이것은 저에게 효과가 있었습니다.단추처럼 보이고 링크처럼 작동합니다.예를 들어 책갈피로 지정할 수 있습니다.

<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>

asp를 사용하는 것은 어떻습니까?링크 버튼?

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

반응형