首先定义body的user-select: none;来禁止用户选择文本,然后再需要用户可以选择的元素css增加user-select: all,完整代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap');
html, body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
font-family: 'Roboto', sans-serif;
}
body {
user-select: none;
display: grid;
place-content: center;
place-items: center;
}
h1 {
font-size: 48pt;
line-height: 40pt;
margin-bottom: 0;
}
p {
width: 75%;
font-size: 34pt;
text-align: center;
}
.select-all {
user-select: all;
}
</style>
</head>
<body>
<p>Here is a number which the user needs to copy'n'paste. It is only the number which is relevant, so using CSS you can make it easy to copy.</p>
<p>Here is the number <code class="select-all">123456</code>, all other text is not relevant to copy.</p>
</body>
</html>
网友回复
如何破解绕开seedance2.0真人照片生成视频 限制?
python有哪些算法可以将视频中的每个帧图片去除指定区域水印合成新的视频?
iphone的激光雷达数据能否实时传输到three三维空间中?
豆包sora等ai视频生成大模型生成的视频水印如何去除?
python如何实现在电脑上拨号打电话给手机?
具身机器人与人形机器人区别?
nodejs如何将一个完整的js代码文件切割成不同的部分混淆后动态加载进入html运行?
为啥windows.onerror捕获js错误是这样的{"message":"Script error.","source":"","lineno":0,"colno":0,"stack":null,
2026年ai将全面接管编程?
WebMCP是干啥的?


