如何超链接 html/css 框部分?

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

How to hyperlink a html/css box section?

htmlcss

提问by defiant

What I want is, a css box which is hyperlinked, so that if anyone clicks on that box s/he will go to that specified link!

我想要的是,一个超链接的 css 框,这样如果有人点击那个框,他/她就会转到那个指定的链接!

For example, I want to hyperlink the following box wrapped around "My Title":

例如,我想超链接以下环绕“我的标题”的框:

<header>
       <h1 class="title" style = "text-align:center; margin = 20px"> My Title </h1>
</header>

回答by Hans Wassink

<div><a href="yoururl.html" style="display:block;height:100%;width:100%"></a></div>

basically: make a link in your box, make it a block and make it as big as the box

基本上:在你的盒子里做一个链接,把它做成一个块,让它和盒子一样大

回答by m4rk

Maybe try:

也许尝试:

<div onclick="location.href='http://myurl.com';" >(Whatever you want in here*</div>

...as long as you don't mind a little JS...

...只要你不介意一点点JS...

回答by T I

You could have a big block link like:

你可以有一个大块链接,如:

/* html */
<a id="foo" href="www.google.com"></a>

/* css */
#foo {
    background: green;
    display: block;
    height: 100px;
    width: 200px;
}  

回答by lvil

If you are meaning a div or a,here is the code:

如果你的意思是 div 或 a,这里是代码:

<a href="www.google.com" style="width:100px;height:100px; float:left"></a>

回答by roNn23

I'm not sure what you mean with a "css box", but I think you mean a box for clicking. You can transform an a-tag as block element and give them a height and width.

我不确定“css 框”是什么意思,但我认为您的意思是单击框。您可以将 a-tag 转换为块元素并为其指定高度和宽度。

<!-- HTML -->
<a href="#">"Linkbox"</a>

/* CSS */
a { 
  display:block;
  width:100px;
  height:100px;
}

回答by Manuel Rauber

You can either use <a>-Tag which is formatted via CSS into a box or surround an element with a <a>to make it clicky.

您可以使用<a>通过 CSS 格式化为框的 -Tag,也可以使用a 包围元素<a>以使其可点击。