简体   繁体   English

将P标签制作为链接

[英]make a P tag into a link

I have a problem. 我有个问题。 The designer I hired did not separate out the logo and the header and its to late to get it done from him. 我聘请的设计师并没有将徽标和标题分开,直到他将其完成。

so I have a header image which has the sites logo in it. 所以我有一个带有网站徽标的标题图像。 I want to make this logo clickable . 我想使该徽标可点击 You can see the site here: http://www.stopsweats.org/ 您可以在此处查看该站点: http : //www.stopsweats.org/

The code for the logo tag is: 徽标标记的代码是:

<div id="header">
<p id="logo">
<a href="http://www.stopsweats.org"></a>
</p>

Here is the CSS, added as per comments 这是CSS,按注释添加

#header {
    background-image: url("http://www.stopsweats.org/wp-content/uploads
/2010/12/sweatbackground1.jpg");
    border-color: transparent;
    height: 108px;
    padding-top: 2em;
    z-index: -1;
}

So how can I make this into a valid link.? 那么如何使它成为有效的链接。

  1. I don't want to add any visible text as it will look ugly. 我不想添加任何可见的文本,因为它看起来很难看。
  2. I will change the #logo width and height and placement as an overlay on the image. 我将#logo宽度,高度和位置更改为图像上的叠加层。 Hope fully that should be ok among all browsers. 完全希望在所有浏览器中都可以。

Write like this: HTML: 这样写: HTML:

<div id="header">
 <a href="http://www.stopsweats.org" id="logo"></a>
</div>  

CSS: CSS:

#header {
background-image: url("http://www.stopsweats.org/wp-content/uploads/2010/12/sweatbackground1.jpg");
border-color: transparent;
height: 108px;
z-index: -1;
width:1000px;
padding-top:10px;
}
#logo{
    display:block;
    width:245px;
    height:60px;
    margin-left:90px;
}

http://jsfiddle.net/rEFRw/ http://jsfiddle.net/rEFRw/

The easiest thing to do is make the a take up some space. 最容易做的事情是让a占用一些空间。 It's already properly positioned, so there's only a little bit to do. 它的位置已经正确放置,因此只需要做一点。

Remove these css width and height properties: 删除以下CSS width和height属性:

#logo a {
    width:1px;
    height:1px;
}

Then add a little text to the a : 再加入少许文本的a

<a href="http://www.stopsweats.org">StopSweats</a>

The text won't be displayed because you have text-indent: -9999px applied to that a , but the block will be about the right width and height to cover the banner image area. 该文本将不会显示,因为您已将text-indent: -9999px应用于该a ,但是该块的宽度和高度大约正确,可以覆盖横幅图像区域。

Esiaest way to do according to your structure I would prefer to put your logo image directly into your html instead of background-image through css. 根据您的结构做的最简便的方法我宁愿将徽标图像直接放入html中,而不是通过CSS来放置背景图像。 If you would like to do than only need to add image tag between your anchor tag (....) just change your css and html according to below code.. 如果您只想在锚标记(....)之间添加图像标记,则只需根据以下代码更改CSS和html。

CSS CSS

#header {
border-color: transparent;
height: 108px; /* change according your logo image height */
padding-top: 2em;
z-index: -1;
}

HTML HTML

<div id="header">
    <p id="logo">
    <a href="http://www.stopsweats.org"><img src="http://www.stopsweats.org/wp-content/uploads/2010/12/sweatbackground1.jpg" alt="logo" title="go back to home" width="logo width here" height="logo height here" /></a>
    </p>
</div>

Check your logo image url properly and make sure you endup your header div tag where it is in your current html file. 正确检查徽标图像的网址,并确保将其头div标签放在当前html文件中。

Also if your #logo id has width and height value set than change accordingly. 同样,如果您的#logo ID设置了宽度和高度值,则应相应地进行更改。

#logo a{display:block; height:XXpx; width:XXpx; text-indent:-999px;}

you may have to adjust some css of other tags also. 您可能还需要调整其他标签的某些CSS。 but it will work 但它会工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM