当锚点定位遇上position: fixed
<!DOCTYPE html>
<html>
<head>
<title>当锚点定位遇上position: fixed</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
position: relative;
}
a {
color: white;
text-decoration: none;
}
.nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
background-color: black;
}
.part-one,
.part-two,
.part-three {
width: 100%;
height: 800px;
}
.part-one {
background-color: red;
padding-top: 100px;
}
.part-two {
background-color: blue;
padding-top: 100px;
margin-top: -100px;
}
.part-three {
background-color: yellow;
padding-top: 100px;
margin-top: -100px;
}
</style>
</head>
<body>
<div class="nav">
<a href="#part-one">part one</a>
<a href="#part-two">part two</a>
<a href="#part-three">part three</a>
</div>
<div class="part-one" id="part-one">I'm part one</div>
<div class="part-two" id="part-two">I'm part two</div>
<div class="part-three" id="part-three">I'm part three</div>
</body>
</html>
<!DOCTYPE html>
<html> <head>
<title>CSS解决有固定导航时链接锚点定位偏移</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
} body {
position: relative;
} a {
color: white;
text-decoration: none;
} .nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
background-color: black;
} .part-one,
.part-two,
.part-three {
width: 100%;
height: 800px;
} .part-one {
background-color: red;
padding-top: 100px;
} .part-two {
background-color: blue;
padding-top: 100px;
margin-top: -100px;
} .part-three {
background-color: yellow;
padding-top: 100px;
margin-top: -100px;
}
</style>
</head> <body>
<div class="nav">
<a href="#part-one">part one</a>
<a href="#part-two">part two</a>
<a href="#part-three">part three</a>
</div>
<div class="part-one" id="part-one">I'm part one</div>
<div class="part-two" id="part-two">I'm part two</div>
<div class="part-three" id="part-three">I'm part three</div>
</body> </html>
当锚点定位遇上position: fixed的更多相关文章
- transform 遇上 position: fixed
最近遇到一个有意思的现象,以下 demo 中 fixed 的元素没有相对 viewport 定位,而是相对于它的父元素进行定位. <html> <head> <style ...
- 关于锚点定位,ul设置fixed后,div被覆盖一部分的问题
例如: 问题: 刚开始的时候 .ul是正常显示的,当页面的滚动条滚动到一定的高度是 ,ul就被设置为 position:fixed:那么 点击 li相对应div就会被 固定定位的ul覆盖住一部分. 解 ...
- ios上position:fixed失效问题
手机端上的猫腻真是多啊~~~ 此起彼伏! 最近又遇到了 固定定位的底部导航在ios上被弹出去 此时内心1w+个草泥马奔过~~~~~~~~ 直接上解决方案: <div class="ma ...
- 通过定位position="fixed"实现网页内容的固定层效果
在网页的顶部或者底部导航栏中经常需要使用到固定层的效果,即紧挨浏览器窗口的顶部或底部而网页其他内容的影响. 一.实现 主要通过设置导航栏元素的位置属性position="fixed" ...
- 移动端采坑:Position: fixed 在Safari上的Bug
Position: fixed 在IOS上的显示效果 会出现两种情况: 点击fixed定位的元素会出现fixed定位失效导致的元素贴向底部,即position: absolute,bottom: 0p ...
- position:fixed 相对父元素定位
position:fixed是对于浏览器窗口定位的,要实现相当于父元素定位,可以这样: 不设置fixed元素的top,bottom,left,right,只设置margin来实现. 这种方法本质上fi ...
- 如何让position fixed不再基于浏览器窗口定位
position:fixed默认是相对浏览器定位的. 就是将某个元素固定在浏览器的某个确定的位置,不随滚动条的移动而变化: MDN对position: fixed有一个注释: 当元素祖先的 trans ...
- ios position:fixed 上滑下拉抖动
ios position:fixed 上滑下拉抖动 最近呢遇到一个ios的兼容问题,界面是需要一个头底部的固定的效果,用的position:fixed定位布局,写完测试发现安卓手机正常的,按时ios上 ...
- 层模型--固定定位(position:fixed)
fixed:表示固定定位,与absolute定位类型类似,但它的相对移动的坐标是视图(屏幕内的网页窗口)本身. 由于视图本身是固定的,它不会随浏览器窗口的滚动条滚动而变化,除非你在屏幕中移动浏览器窗口 ...
随机推荐
- Request method 'PUT'/ 'POST' not supported
起因 在项目中遇到需要进行crud操作的功能,用的是Springboot+MybatisPlus+MySQL+AVue,在通过postman测试接口正确性时遇到此错误. 排查过程 因为项目运行是没问题 ...
- Visual Studio 2017/2019 企业版 Enterprise 激活码
VS2017 Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF VS2017 Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH ...
- golang协程踩坑记录
1.主线程等待多个协程执行完毕后,再执行下面的程序.golang提供了一个很好用的工具. sync.WaitGroup下面是个简单的例子. 执行结果: 2.主线程主动去结束已经启动了的多个协程.执行结 ...
- golang Mysql -- Tx
Transaction 事务 事务处理是数据的重要特性.尤其是对于一些支付系统,事务保证性对业务逻辑会有重要影响.golang的mysql驱动也封装好了事务相关的操作.我们已经学习了db的Query和 ...
- Maven安装环境变量配置教程(带图)
Maven安装配置环境变量教程 什么是maven:Maven是一个软件项目管理和综合工具.基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报告和文件. (简单来说就是,安 ...
- Layui使用心得(1)---- 数据表格
前端的框架我了解的不是太多,现在在用Layui的框架开发.之后准备转向Vue和React 这一系列博客主要讲一些我使用的Layui的常用组件的心得,官方的网站讲解已经很详细了,这里我只是结合我的实际使 ...
- Xilinx Vivado的使用详细介绍(5):调用用户自定义封装的IP核
Zedboard OLED Display Controller IP v1 介绍 Author:zhangxianhe 本文档提供了快速添加,连接和使用ZedboardOLED v1.0 IP内核的 ...
- React子组件和父组件通信
React子组件和父组件通信包括以下几个方面: 子组件获取父组件属性:props或者state 子组件调用父组件的方法 父组件获取子组件的属性:props或者state 父组件调用子组件的方法 我们从 ...
- Springboot使用alibaba的fastJson,@JSONField不起作用的问题
在Springboot中默认的JSON解析框架是jackson 今天引入alibaba的fastjson,使用@JSONField(serialize=false),让@RestController转 ...
- Android测试(三)——burpsuite抓包设置
导出证书: 将证书导入模拟器中: 设置监听端口,透明代理(一定要设置这个): 进入adb shell,输入如下命令,即可抓包了: iptables -t nat -A OUTPUT -p tcp - ...