html - 如何仅使用 CSS 鼠标相关事件来换出文本框中的文本?

标签 html css mouseevent replace

我现在设置页面的方式非常可靠。我有一个图片库,当您的鼠标悬停在其中一个小图标上方时,会弹出一个较大的图标,并且页面上最大的图像会变为该图像。我通过内联 CSS 使用 onMouseOver 和 onMouseOff 事件完成了这一切。

但是,我想对文本框做同样的事情。比如说,当我将鼠标悬停在狗的图片上时,我希望页面底部附近名为“dogdiv”的 div 中的文本出现在 ID 为 textarea 的文本框中。我知道如何使用 JavaScript (JS) 执行此操作,但由于我们使用的服务器的限制,这不再是一种选择。它必须是直接的 CSS。

我知道这是可能的,但我似乎无法找到方法。你们中的任何人都可以告诉我我需要做什么才能完成这项工作吗?

<html> 
<head>
<title>Text/Photo Swap Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {background: url('gradient.png');}

#gallery {position: relative; }
#gallery ul {list-style-type: none;
    width: 300px; }
#gallery li { display: inline; 
     float: left;
     padding: 5px; }
#gallery img {border-style: solid: 10px; border-color: #333; }
#gallery a { text-decoration: none;
             font-style: none;  
             color: #333; }

#mainPicture {
    float: right;
        }

.popOut
{
    cursor: default;
    list-style: none;
}
.popOut a
{
    cursor: default;
}
.popOut a .preview
{
    display: none;
}
.popOut a:hover .preview
{
    display: block;
    position: absolute;
    top: -33px;
    left: -45px;
    z-index: 1;
}
.popOut img
{
    background: #ebf0f3;
    border-color: #ebf0f3;
    border-style: solid;
    border-width: 1px;
    color: inherit;
    vertical-align: top;
    width: 100px;
    height: 75px;
}
.popOut li
{
    background: #ebf0f3;
    border-color: #CCCCCC;
    border-style: solid;
    border-width: 0px;
    color: inherit;
    display: inline;
    float: left;
    margin: 3px;
    padding: 2px;
    position: relative;
}
.popOut .preview
{
    border-color: #000;
    width: 200px;
    height: 150px;
}
.popOut p
{
    text-align: center;
}

#textarea
{
    background-color: #ebf0f3;
}

div.hideText
{
display:none;
}


</style>
</head>

<body>
<div class="mainPicture"><img id="awesome" src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/awesome.png" height="300" width="400" alt="" name="Awesome2"><!--style="position:relative; left:600px; top:326px;"--></div>

<td width="1000" rowdiv="3">
<div id="gallery">
    <ul class="popOut">
        <li>
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/dog.jpg';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/dog.jpg';">
                <img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/dog.jpg" width="100" height="75" alt="dog"><img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/dog.jpg" width="100" height="75" alt="dog" class="preview"> 
            </a>
        </li>
        <li>
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/cat.jpg';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/cat.jpg';">
                <img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/cat.jpg" width="100" height="75" alt="cat"><img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/cat.jpg" width="100" height="75" alt="cat" class="preview"> 
            </a>
        </li>
        <li>
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/parrot.jpg';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/parrot.jpg';">
                <img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/parrot.jpg" width="100" height="75" alt="parrot"><img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/parrot.jpg" width="100" height="75" alt="parrot" class="preview"> 
            </a>
        </li>
        <li>
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/lizard.jpg';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/lizard.jpg';">
                <img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/lizard.jpg" width="100" height="75" alt="lizard"><img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/lizard.jpg" width="100" height="75" alt="lizard" class="preview"> 
            </a>
        </li>
        <li>
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/horse.jpg';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/horse.jpg';">
                <img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/horse.jpg" width="100" height="75" alt="horse"><img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/horse.jpg" width="100" height="75" alt="horse" class="preview"> 
            </a>
        </li>
        <li>
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/chicken.jpg';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/chicken.jpg';">
                <img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/chicken.jpg" width="100" height="75" alt="chicken"><img src="http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/chicken.jpg" width="100" height="75" alt="chicken" class="preview"> 
            </a>
        </li>
        <li onMouseOver="textarea.textarea2='chickendiv'">
            <a href="" onMouseOver="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/awesome.png';" onMouseOut="document.Awesome2.src='http://ctd-dev.jdc.ao.dcn/sites/ctd-dev.jdc.ao.dcn/files/pictures/awesome.png';">
                <p>Default Image</p>
            </a>
        </li>
    </ul>

    <div id="textarea" style="height:600px;width:320px;font:14px;font:14px/26px Arial, Helvetica, sans-serif;overflow:scroll; position:relative;
    top:12px;"><div id="textarea2"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pulvinar lectus non lectus auctor egestas. Donec at nunc neque. Morbi ornare condimentum lobortis. Nam vehicula urna ac mauris pharetra rutrum. Duis et arcu eget sapien interdum porttitor ut et tortor. Maecenas ultricies dignissim pretium. Integer quis enim metus. Sed enim lacus, eleifend eu euismod volutpat, blandit eu sem. Vestibulum varius purus ut est accumsan pellentesque. Donec quis enim id lectus sollicitudin suscipit at volutpat augue. Curabitur et metus purus. Fusce luctus nunc vitae sapien pharetra id accumsan lectus malesuada.</p></div>
    </div>
    </div>
</td>

<div id="dogdiv" class="hideText"><p>The domestic dog (Canis lupus familiaris), is a subspecies of the gray wolf (Canis lupus), a member of the Canidae family of the mammilian order Carnivora. The term domestic dog is generally used for both domesticated and feral varieties. The dog may have been the first animal to be domesticated, and has been the most widely kept working, hunting, and companion animal in human history. The word dog may also mean the male of a canine species, as opposed to the word bitch for the female of the species.</p>
</div>
<div id="catdiv" class="hideText"><p>The domestic cat (Felis catus or Felis silvestris catus) is a small, usually furry, domesticated, carnivorous mammal. It is often called the housecat when kept as an indoor pet, or simply the cat when there is no need to distinguish it from other felids and felines. Cats are valued by humans for companionship and ability to hunt vermin and household pests. They are primarily nocturnal.</p>
</div>
<div id="parrotdiv" class="hideText"><p>Parrots, also known as psittacines are birds of the roughly 372 species in 86 genera that make up the order Psittaciformes, found in most tropical and subtropical regions. The order is subdivided into three superfamilies: the Psittacoidea  parrots), the Cacatuoidea (cockatoos) and the Strigopoidea (New Zealand parrots). Parrots have a generally pantropical distribution with several species inhabiting temperate regions in the Southern Hemisphere as well. The greatest diversity of parrots is found in South America and Australasia.</p>
</div>
<div id="lizarddiv" class="hideText"><p>Lizards are a widespread group of squamate reptiles, with more than 5600 species , ranging across all continents except Antarctica as well as most oceanic island chains. The group, traditionally recognized as the suborder Lacertilia, is defined as all extant members of the Lepidosauria (reptiles with overlapping scales), which are neither sphenodonts (i.e., tuatara) nor snakes ? they form an evolutionary grade. While the snakes are recognized as falling phylogenetically within the Toxicofera clade from which they evolved, the Sphenodonts are the sister group to the Squamates, the larger monophyletic group, which includes both the lizards and the snakes.</p>
</div>
<div id="horsediv" class="hideText"><p>The horse (Equus ferus caballus) is one of two extant subspecies of Equus ferus, or the wild horse. It is an odd-toed ungulate mammal belonging to the taxonomic family Equidae. The horse has evolved over the past 45 to 55 million years from a small multi-toed creature into the large, single-toed animal of today. Humans began to domesticate horses around 4000 BC, and their domestication is believed to have been widespread by 3000 BC. Horses in the subspecies caballus are domesticated, although some domesticated populations live in the wild as feral horses. These feral populations are not true wild horses, as this term is used to describe horses that have never been domesticated, such as the endangered Przewalski Horse, a separate subspecies, and the only remaining true wild horse. There is an extensive, specialized vocabulary used to describe equine-related concepts, covering everything from anatomy to life stages, size, colors, markings, breeds, locomotion, and behavior.</p>
</div>
<div id="chickendiv" class="hideText"><p>The chicken (Gallus gallus domesticus) is a domesticated fowl, a subspecies of the Red Junglefowl. As one of the most common and widespread domestic animals, and with a population of more than 24 billion in 2003, there are more chickens in the world than any other species of bird. Humans keep chickens primarily as a source of food, consuming both their meat and their eggs.</p>
</div>
</body>
</html>

最佳答案

这就是你想要的

<ul id="thumbs">

  <li>
    <div class="large-thumb"><img src="large-thumb.jpg" /></div>
    <div class="small-thumb"><img src="small-thumb.jpg /></div>
  </li>

  <li>
    <div class="large-thumb"><img src="large-thumb.jpg" /></div>
    <div class="small-thumb"><img src="small-thumb.jpg /></div>
  </li>

</ul>

使用 CSS,您可能希望将 display: none; 应用于 .large-thumb 类,请参见下面的 css:

#thumbs {
  float: left;
  width: 100%;
  padding: 20px 0;}

#thumbs li {
  float: left;
  display: inline;
  margin-right: 10px;}

#thumbs li .large-thumb { display: none; /*Hide the large thumb*/}

#thumbs li:hover .large-thumb { display: block; /*Show on Hover*/}

我会把剩下的 CSS 留给你去做,但是你需要相对定位 li 然后绝对定位大拇指来实现你想要做的事情。

希望这有帮助:-)

关于html - 如何仅使用 CSS 鼠标相关事件来换出文本框中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587499/

相关文章:

Java 事件监听器(鼠标和键盘)

javascript - 自定义选择标签

html - 添加了多个空白链接的 CSS

javascript - 如何使用 JavaScript 设置带前缀的 CSS3 过渡效果?

html - 动态创建复选框列

html - CSS 背景图片链接正确;不在浏览器中显示

python - 单击圆圈内的任意位置时,使用 Python 验证鼠标位置是否在圆圈内。

javascript - WebAudio 平移不适用于 WebRTC

html - 重新加载时文本从自定义字体恢复为网络安全字体(覆盖缓存)

c# - 调整窗口大小时锚定控件不会调整大小(56k 小心)