我正在try 制作一个字形浏览器网页

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Glyph browser</title>
    <style>     
                body {
            background-color: black;
        }
        .gridcontainer {
            margin-left: 3rem;
            display: grid;
            grid-template-columns: repeat(16, 1fr);
            }
        .gridcell {
            color: white;
            border: 0.1px solid gray;
            padding: 1rem;
            text-align: center;
            }
        
        p {
            text-align: center;
            margin: 2rem;
            font-size: 1rem;
            color: white;
        }
        
        p.unicode {
            font-size: 0.5rem;
            }
        .glyph-pop {
            display: none;
            position: absolute;
            z-index: 10;
        }
        .glyph-display {
            font-size: 5rem;
        }
        .glyph:hover .glyph-pop
        {
            display: inline-block;
        }
        .glyph-pop p {
            background-color: black;
            font-size: 20rem;
            color: orange;
        }
        .glyph-pop .unicode {
            color: orange;
            font-size: 2rem;
            }
        
        .glyph a {
            font-style: normal;
            font-weight: bold;
            color: inherit;
            text-decoration: none;
        }
</style>
</head>
<body>
<h1>
    Glyph browser
</h1>
<div class="gridcontainer">
    <div class="glyph">
        <p class="glyph-display" title="exclamation mark Punctuation, Other">
            <a>!</a>
        </p>
        <p class="unicode">
            0021
        </p>
        <div class="glyph-pop">
            <p>
                !
            </p>
            <p class="unicode">
                U+0021
            </p>
        </div>
    </div>
    <div class="glyph">
        <p class="glyph-display" title="exclamation mark Punctuation, Other">
            <a>@</a>
        </p>
        <p class="unicode">
            0022
        </p>
        <div class="glyph-pop">
            <p>
                @
            </p>
            <p class="unicode">
                U+0022
            </p>
        </div>
    </div>
    <div class="glyph">
        <p class="glyph-display" title="exclamation mark Punctuation, Other">
            <a>#</a>
        </p>
        <p class="unicode">
            0023
        </p>
        <div class="glyph-pop">
            <p>
                #
            </p>
            <p class="unicode">
                U+0023
            </p>
        </div>
    </div>
</div>
</body>
</html>

其 idea 是当用户将鼠标悬停在小版本上时,显示一个大字形.(尺寸可能会有所调整.)

moving over the glyphs displays larger image

它的工作正常,但我无法控制‘大’字形显示的位置,我不确定什么是可能的.理想情况下,我可以把较大的放在较小的下面.

推荐答案

在代码中,我添加了以下内容:

  • .glyph-op css类的top属性.此属性使用 用于计算小字形显示高度的Calc()函数, 加上1rem,并将大字形显示的像素 在小字形显示下方.
  • .glyph-op css类的Left属性.此属性设置 大字形显示的左侧位置为0像素,所以它是 定位在小字形显示的左侧.

            body {
            background-color: black;
        }
        .gridcontainer {
            margin-left: 3rem;
            display: grid;
            grid-template-columns: repeat(16, 1fr);
            }
        .gridcell {
            color: white;
            border: 0.1px solid gray;
            padding: 1rem;
            text-align: center;
            }
        
        p {
            text-align: center;
            margin: 2rem;
            font-size: 1rem;
            color: white;
        }
        
        p.unicode {
            font-size: 0.5rem;
            }
        .glyph-pop {
            display: none;
            position: absolute;
            z-index: 10;
        }
        .glyph-display {
            font-size: 5rem;
        }
        .glyph:hover .glyph-pop
        {
            display: inline-block;
        }
        .glyph-pop p {
            background-color: black;
            font-size: 20rem;
            color: orange;
        }
        .glyph-pop .unicode {
            color: orange;
            font-size: 2rem;
            }
        
        .glyph a {
            font-style: normal;
            font-weight: bold;
            color: inherit;
            text-decoration: none;
        }
        .glyph-pop {
          top: calc(100% + 1rem);
          left: 0;
        }
<h1>
    Glyph browser
</h1>
<div class="gridcontainer">
    <div class="glyph">
        <p class="glyph-display" title="exclamation mark Punctuation, Other">
            <a>!</a>
        </p>
        <p class="unicode">
            0021
        </p>
        <div class="glyph-pop">
            <p>
                !
            </p>
            <p class="unicode">
                U+0021
            </p>
        </div>
    </div>
    <div class="glyph">
        <p class="glyph-display" title="exclamation mark Punctuation, Other">
            <a>@</a>
        </p>
        <p class="unicode">
            0022
        </p>
        <div class="glyph-pop">
            <p>
                @
            </p>
            <p class="unicode">
                U+0022
            </p>
        </div>
    </div>
    <div class="glyph">
        <p class="glyph-display" title="exclamation mark Punctuation, Other">
            <a>#</a>
        </p>
        <p class="unicode">
            0023
        </p>
        <div class="glyph-pop">
            <p>
                #
            </p>
            <p class="unicode">
                U+0023
            </p>
        </div>
    </div>
</div>

Css相关问答推荐

下拉面板未与Angular中的下拉文本框垂直对齐

在ReactJS中使用动画在栅格上添加柱

当具有外部高度的网格项溢出时,为什么溢出滚动端口填充不应用于网格容器?

如何使背景出现在具有自己背景 colored颜色 的子元素上

Next.js 条件样式

CSS 中的 :not(style) ~ :not(style) 是什么?

同时实现渐变文本和闪光文本效果是否可行?

将重复的线性渐变锚定到元素的顶部

2 列 UL,右列中的列表项数量为奇数?

CSS 网格 - 具有独立可滚动区域的两列布局

为什么同一个 CSS 类连续出现两次

在不使用 position: fixed 的情况下从 CSS 网格中的自动布局中免除子元素?

没有 colored颜色 Select 器的 JavaFX colored颜色 Select 器

firefox overflow-y 不能使用嵌套的 flexbox

Angular Material 中的样式垫 Select

CSS:背景图像和填充

什么是 ::content/::slotted 伪元素,它是如何工作的?

如何在 Chrome 的判断器中添加/插入之前或之后的伪元素?

跨域 iframe 调整大小

height: 100% 或 min-height: 100% 用于 html 和 body 元素?