HTML/CSS : A href exceeds linking image - how to avoid?

标签 html css image href

我把三个 HTML 元素排成一行 using inline-block :2 张链接到外部网站的图片(下图中的绿色框)和一个带有搜索表单和语言选择的 div 标签。

现在的问题是,在图像旁边 - 在它们的右侧 - 还有一个隐藏链接。为了使其可见,我在事件模式下设置了 text-decoration:underline 和蓝色背景(见图)。

如何将 a href 限制为仅包含图像?

Problem: a href link exceeds image which it was meant for

HTML 代码如下所示:

<div id="logo">
<a href="http://website1.example">
    <img src="image1.gif">
</a>
<a href="http://website2.example">
    <img src="image2.gif">
</a>
<div id="headermodules">
    <form class="search" method="post" action="index.php">
        <input type="text" value="Suchen...">
    </form>
    <div id="languageselection">
        <ul class="languageselection">
            <li id="active_language">
                <a href="http://localhost:81/de/">Deutsch</a>
            </li>
            <li>
                <a href="http://localhost:81/en/">English
            </li>
        </ul>
    </div>
</div>
<span style="width: 100%;"></span>
</div>

CSS 看起来像这样:

#logo
{
position: relative;
height:129px;
text-align: justify;
z-index: 0;
border-top: 0px solid #000;
}
#logo  img 
{
display: inline-block;
vertical-align: middle;
}
#logo span
{
width: 100%;
height: 0;
display: inline-block;
}
#headermodules
{
display: inline-block;
vertical-align: middle;
}

最佳答案

您应该将 a 元素样式设置为 inline-block 而不是 imgimg 应该是 display: block。我认为应该这样做。

#logo a { display: inline-block; }
#logo img { display: block; }

关于HTML/CSS : A href exceeds linking image - how to avoid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21627469/

相关文章:

html - flex 盒悬停 child 全高

javascript - 使用 JavaScript 在 Internet Explorer 中插入外部 CSS

mysql - 无法在 MySQL 中保存大图像

python-3.x - python 枕头 :Load Image with data

python - 遍历文件夹树并将 xmp 数据添加到文件夹中的文件,然后移动

javascript - 以移动为中心的 Bootstrap 导航栏品牌

html - 缩放具有固定尺寸的 SVG

html - 为什么流体容器内的一行会在 x 轴上溢出?

css - 是否有 CSS 父级选择器?

html - 我怎样才能在同一行上获得两个div?