html - 转换不适用于 :target, 不确定我做错了什么

标签 html css

我只是想创建一个过渡示例 :target。定位有效,但转换无效(这只是为了更改背景颜色)。有人可以告诉我我做错了什么吗?谢谢。

<!DOCTYPE html>
<html>
<head>
<style>
#news1 {
    background-color: white;
    -webkit-transition: background-color, 2s, ease, .1s;
    -moz-transition: background-color, 2s, ease, .1s;
    -o-transition: background-color, 2s, ease, .1s;
    -ms-transition: background-color, 2s, ease, .1s;
    transition: background-color, 2s, ease, .1s;
}
#news2 {
    background-color: white;
    -webkit-transition: background-color, 2s, ease, .1s;
    -moz-transition: background-color, 2s, ease, .1s;
    -o-transition: background-color, 2s, ease, .1s;
    -ms-transition: background-color, 2s, ease, .1s;
    transition: background-color, 2s, ease, .1s;
}
#news1:target {
    border: 2px solid #FF0000;
    background-color: #e5eecc;
}
#news2:target {
    border: 2px solid #FF0000;
    background-color: #e5eecc;
}
</style>
</head>
<body>

<h1>This is a heading</h1>

<p><a href="#news1">Jump to New content 1</a></p>
<p><a href="#news2">Jump to New content 2</a></p>

<p>Click on the links above and the :target selector highlight the current active HTML anchor.</p>

<p id="news1"><b>New content 1...</b></p>
<p id="news2"><b>New content 2...</b></p>

</body>
</html>

最佳答案

transition中移除,

transition: background-color, 2s, ease, .1s;

应该是

transition: background-color 2s ease .1s;

您可以为目标添加 border: 2px solid transparent; 边框,这样它们就不会移动

演示 - http://jsfiddle.net/wzgnqpsq/1/

关于html - 转换不适用于 :target, 不确定我做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26869714/

相关文章:

html - 保持 div 的宽度固定,但在调整大小时匹配视频元素的高度

css - 无法使用 webpack 设置 React 组件的样式

jquery - 如何使用 jQuery 指定通配符 (*) 以将颜色应用于所有子级(深层)?

javascript - 通过鼠标单击显示/隐藏 div 搜索下拉列表

html - Bootstrap 错误消息不适用于 php,如果

javascript - 禁用时如何设置我的 react 选择样式(在 CSS 中)?

iphone - Read And then HTML 页面 +IOS

Jquery 背景图像在 Safari 中不起作用

php - 关于在 PHP 中包含 html 页面的问题

html - Chrome <td> border-top 跨行流血