当锚点定位遇上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定位类型类似,但它的相对移动的坐标是视图(屏幕内的网页窗口)本身. 由于视图本身是固定的,它不会随浏览器窗口的滚动条滚动而变化,除非你在屏幕中移动浏览器窗口 ...
随机推荐
- hyperledger fabric 架设命令
单节点架设 Order 网络: cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/ rm -rf channel-artifacts ...
- js原型和原型链理解到面向对象
一.js中的两种对象,普通对象和函数对象 var obj1 = {}; var obj2 =new Object(); var obj3 = new obj1(); function fun1(){} ...
- webpack-工程化工具
一.简介 1.webpack 是 facebook 公司发布的一款工程化工具,早期有 react 使用. 2.核心理念: 一切都是资源,是资源我们就能模块化打包加载. 3.webpack 默认支持 c ...
- Struts 2 框架搭建HelloWorld
1.导包 导入相应的jar包,在blank项目中会出现 2.书写Action类 package com.littlepage.struts; public class HelloAction { pu ...
- English trip V2 - 3. A Healthy Diet Teacher:Corrine Key:各种前缀 im- un- in- re- over- under-
In this lesson you will learn to talk about foot and drink for a healthy diet. 课上内容(Lesson) What do ...
- linux——文件操作
1.创建文件夹 mkdir /myFolder 2.创建文件 touch hello.txt 3.复制文件 cp [-adfilprsu] 源文件 目标地址 4.移动 mv 源地址 目标地址 5.正向 ...
- Vue非父子级通信
<div id="app"> <xz-todo></xz-todo> </div> <!--1. 为每个组件定义HTML 模板 ...
- CentOS 7下安装GUI图形界面
https://www.linuxidc.com/Linux/2017-03/141465.htm
- Java线程池—ThreadPool简介
一.Java线程池类/接口关系图及作用 Executor接口:只有一个方法execute(Runnable command),用来执行用户的任务线程. ExecutorService接口:继承自Exe ...
- Vue+Element+Select获取选中的对象
案例演示:获取select当前选中的所有内容 <el-select v-model="value8" filterable placeholder=&qu ...