简体   繁体   English

如何在列表项中拥有可点击的图像和链接(锚点)

[英]How can I have a clickable image and link (anchor) in a list item

As mentioned in the title, i want to get an icon and an a tag inside a li.正如标题中提到的,我想在 li 中获得一个图标和一个标签。

I want a small icon to the left of the text in a navigation bar but also have the entire bar clickable.我想要导航栏中文本左侧的小图标,但也可以单击整个栏。

I tried to google it but without and results.我试图用谷歌搜索它,但没有结果。

My current situation looks like this:我目前的情况是这样的:

HTML HTML

<ul>
    <li><img src="../resources/images/test.png" /><a href="#text">Login</a></li>
    <li><a href="#test">Test1</a></li>
    <li><a href="#test">Test2</a></li>
    <li><a href="#test">Test3</a></li>
    <li><a href="#test">Test4</a></li>
</ul>

CSS CSS

ul {
    list-style-type: none;
    height: 40px;
    width: auto;
    padding: 0;
    margin: 0;
}

li a {
    margin-right: 50px;
    background: #B0AA9A;
    float: left;
    height: 30px;
    width: 150px;
    font-size: 25px;
    color: #454138;
    font-family: helvetica, sans-serif;
    text-decoration: none;
}

img {
    height: 20px;
    width: 20px;
    float: left
}

Do something like this, Put the Img inside the A tag and then both will be clickable to whatever href you give.做这样的事情,把 Img 放在 A 标签内,然后两者都可以点击你提供的任何 href。

<ul>
    <li>
    <a href="https://www.google.com" target="_blank">
    Login
    <img src="../resources/images/test.png" />
    </a>
    </li>
    <li><a href="#test">Test1</a></li>
    <li><a href="#test">Test2</a></li>
    <li><a href="#test">Test3</a></li>
    <li><a href="#test">Test4</a></li>
</ul>

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

相关问题 如果我无法嵌套锚标签,如何创建带有链接的可点击项目 - If I can't nest anchor tags how do I create a a clickable item with a link in it 如何使用jQuery将图像或列表项涂成灰色,但使图像或列表项可点击? - How can I grey out an image or list item with jQuery, but leave the image or list item clickable? 我怎样才能将元素放入锚标签中,而不必点击? - How can I do element into anchor tag dont have to clickable? 如何<a>在无序列表中</a>仅使<a>标签可单击而不使整个列表项可单击?</a> - How can I make only the <a> tag clickable not the entire list item clickable in an un-ordered list? 我怎样才能在 vuetify 文本字段的 label 中有一个可点击的锚标记? - How can I have a clickable anchor tag in the label of a vuetify text-field? 如何单击列表项内的锚标记? - How can I click an anchor tag inside a list item? 链接内列表项中的图像在IE中不可点击 - Image inside list item inside link not clickable in IE 如何使导航栏中的列表项的整个区域可作为链接单击? - How do I make the whole area of a list item in my navigation bar, clickable as a link? 如何在TTTAttributedLabel中将HTML锚点设为可点击链接? - How to make an HTML anchor as clickable link in TTTAttributedLabel? 如何在此跨度中添加可点击链接? - How can I add a clickable link into this span?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM