简体   繁体   English

当鼠标悬停在文本超链接上时,图像显示出来,但是需要更改图像相对于每个链接的位置

[英]Image shows when hovering over text hyperlink, but need to change position of image relative to each link

On my site, I have text hyperlinks, and when I hover the mouse over them, a small thumbnail image appears on the line below the link. 在我的网站上,我有文本超链接,当我将鼠标悬停在它们上时,链接下方的行上会出现一个小的缩略图。

-- example found on the following page: http://synapsecomic.com/synapse_archive.html --. - 在以下页面上找到示例: http : //synapsecomic.com/synapse_archive.html-

The initial code was found here: Display Image On Text Link Hover CSS Only . 在此处找到了初始代码: 仅在文本链接悬停CSS上显示图像

Now I'd like to tweak it if is possible, stated below. 现在,我想对它进行调整,如下所述。 To do this, I'm using only HTML and CSS: 为此,我仅使用HTML和CSS:

HTML: HTML:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, (...), 
<a href="synapse_author.html">24,
<div><img src="comic_images/Panels/Master_List/synapse_00001.gif" width="150" height="100"   />
</div></a> 
25<br /><br />

<a href="synapse_author.html">26,
<div><img src="comic_images/Panels/Master_List/synapse_00000.gif" width="150" height="100" />
</div></a>
27, 28, 29, 30, 31

CSS: CSS:

a>div { display: none; }
a:hover>div { display: block; position:absolute; border: 5px solid #FFF;}

If you hover over link 26, the thumbnail displays directly below the link, which is good. 如果将鼠标悬停在链接26上,缩略图将直接显示在链接下方,这很好。 My issue is that when you hover over link to 24, the thumbnail displays aligned along the left instead of right below the text. 我的问题是,当您将鼠标悬停在链接到24上时,缩略图的显示沿文本的左侧而不是右侧对齐。 This will probably be an issue for all of the other pages as well (just haven't turned any of them into links yet). 这对于所有其他页面也可能是个问题(只是还没有将它们转换成链接)。 Is there any way to have the thumbnail appear directly below the link it is attached to? 有什么方法可以使缩略图直接显示在附加的链接下方?

If possible, explain your answer in layman's terms. 如果可能,请以外行的方式解释您的答案。 I'm still really new to coding (I'm surprised I've gotten this far honestly). 我仍然对编码真的很陌生(很惊讶我已经诚实地做到了这一点)。 I appreciate your help, and will clarify any of my explanations if necessary. 感谢您的帮助,如有必要,我们将澄清我的任何解释。

Why not adopt an approach more like this which doesnt nest block elements within anchor tags (not ideal..) 为什么不采用更像这样的方法,即不会将块元素嵌套在锚标签中(不理想)。

HTML: HTML:

<ul>
    <li>
        <a href='#'>Item 1</a>
        <ul>
            <li>
                image 1
            </li>       
        </ul>
    </li> 
    <li>
        <a href='#'>Item 2</a>
        <ul>
            <li>
                image 2
            </li>       
        </ul>
    </li>     
</ul>

CSS: CSS:

ul, li{
    list-style:none;
    margin:0;
    padding:0;
}
ul ul{
    display:none;
}
ul li{
    position:relative;
    display:inline;
}
ul li:hover ul{
   display:block;
   position:absolute;
}

modify css to: 将CSS修改为:

.archivepage_body a {
   position: relative;
}
a > div {
   display: none;
   position: absolute;
   left: 0px;
   top: 0px;
}

you can adjust the "left" and "top" values to find a suitable position. 您可以调整“左”和“上”值以找到合适的位置。 Also it will be good to give a CSS classname to "a" tags and use that class for styling. 将CSS类名赋予“ a”标签并使用该类进行样式设置也将是一件好事。

As an example: <a class="link" href="synapse_author.html">24,..... then in style instead of "a > div" use ".link > div" 例如: <a class="link" href="synapse_author.html">24,.....然后使用样式代替"a > div"使用".link > div"

                     <

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

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