【发布时间】:2023-03-31 05:43:01
【问题描述】:
我有这个代码:
pre[class*="language-"] {
top: 0;
position: relative;
border-radius: 3px;
}
#copybutton {
position: absolute;
right: 1em;
top: 1em;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
border: 0px transparent;
font-size: 0.725rem;
padding: 3px;
border-radius: 5px;
background-color: #ebebeb;
transition: background-color 0.25s ease-in-out;
}
<link href="https://prismjs.com/themes/prism.css" rel="stylesheet">
<script src="https://prismjs.com/prism.js"></script>
<pre class="language-js">
<button id="copybutton">Copy</button>
<code>const name = "" //a really really really really really really really really really really really really really really really really long </code>
</pre>
我想定位按钮,这样当用户水平滚动代码时,按钮不应该移动它的位置。但是当用户滚动页面(而不是代码)时,它应该移动。 CSS 和 JS 答案表示赞赏。请不要在 jQuery 中回答。
【问题讨论】:
-
在
pre元素周围添加一个额外的包装器,并将按钮放在pre之外 ...? -
@CBroe 添加示例
标签: javascript html css