<!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的更多相关文章

  1. transform 遇上 position: fixed

    最近遇到一个有意思的现象,以下 demo 中 fixed 的元素没有相对 viewport 定位,而是相对于它的父元素进行定位. <html> <head> <style ...

  2. 关于锚点定位,ul设置fixed后,div被覆盖一部分的问题

    例如: 问题: 刚开始的时候 .ul是正常显示的,当页面的滚动条滚动到一定的高度是 ,ul就被设置为 position:fixed:那么 点击 li相对应div就会被 固定定位的ul覆盖住一部分. 解 ...

  3. ios上position:fixed失效问题

    手机端上的猫腻真是多啊~~~ 此起彼伏! 最近又遇到了 固定定位的底部导航在ios上被弹出去 此时内心1w+个草泥马奔过~~~~~~~~ 直接上解决方案: <div class="ma ...

  4. 通过定位position="fixed"实现网页内容的固定层效果

    在网页的顶部或者底部导航栏中经常需要使用到固定层的效果,即紧挨浏览器窗口的顶部或底部而网页其他内容的影响. 一.实现 主要通过设置导航栏元素的位置属性position="fixed" ...

  5. 移动端采坑:Position: fixed 在Safari上的Bug

    Position: fixed 在IOS上的显示效果 会出现两种情况: 点击fixed定位的元素会出现fixed定位失效导致的元素贴向底部,即position: absolute,bottom: 0p ...

  6. position:fixed 相对父元素定位

    position:fixed是对于浏览器窗口定位的,要实现相当于父元素定位,可以这样: 不设置fixed元素的top,bottom,left,right,只设置margin来实现. 这种方法本质上fi ...

  7. 如何让position fixed不再基于浏览器窗口定位

    position:fixed默认是相对浏览器定位的. 就是将某个元素固定在浏览器的某个确定的位置,不随滚动条的移动而变化: MDN对position: fixed有一个注释: 当元素祖先的 trans ...

  8. ios position:fixed 上滑下拉抖动

    ios position:fixed 上滑下拉抖动 最近呢遇到一个ios的兼容问题,界面是需要一个头底部的固定的效果,用的position:fixed定位布局,写完测试发现安卓手机正常的,按时ios上 ...

  9. 层模型--固定定位(position:fixed)

    fixed:表示固定定位,与absolute定位类型类似,但它的相对移动的坐标是视图(屏幕内的网页窗口)本身. 由于视图本身是固定的,它不会随浏览器窗口的滚动条滚动而变化,除非你在屏幕中移动浏览器窗口 ...

随机推荐

  1. mongodb在ubuntu下无法打开的问题

    通过查询大概知道了是非正常关闭,mongod.lock的事,ubuntu的mongod.lock在/var/lib/mongodb中,删除之后即可重新打开.

  2. IDLE清屏扩展

    新建ClearWindows.py,复制以下代码: class ClearWindow: menudefs = [ ('options', [None, ('Clear Shell Window', ...

  3. eee

    package demo; public class Phone { String phonexinghao; String phonepinpai; public void shouji (){ S ...

  4. 解决JS中取URL地址中的参数中文乱码

    GET请求会将中文编码,如果取出乱码的话,应该进行解码操作, 下面的函数是获取指定参数名的参数值,参数值可是中文.英文. function getQueryString(name) { var reg ...

  5. 20190323——HeadFirestPython学习之异常处理

    man=[] other=[] try: data=open('sketch.txt') for each_line in data: try: (role,line_spoken)=each_lin ...

  6. 安装weblogic

    附:wls1036_generic.jar 链接:https://pan.baidu.com/s/1W5g-SHeKL96yrOeDKJJoxw 提取码:vxft 注:以下安装步骤是一个前辈整理的,我 ...

  7. mac电脑上不能用移动硬盘的原因和方法

    原因: 一般性是因为这个移动硬盘的格式是 NTFS 格式的,对于这种格式的磁盘格式,在苹果系统中却是不支持往硬盘里写入数据的 解决方法: 方法一: ntfs的格式分区,这种格式分区与我们的苹果电脑自身 ...

  8. java的equals()与hashCode()以及包装类中的实现

    1. hashcode 1.1 hashcode来源 1.2 hashcode的形式 1.3 hashcode目的 1.4 hashcode规则 1.5 hashcode作用体现 1.6 重写hash ...

  9. max of 直线划平面

    在一个无限延伸平面上有一个圆和n条直线,这些直线中每一条都在一个圆内,并且同其他所有的直线相交,假设没有3条直线相交于一点,试问这些直线最多将圆分成多少区域. Input 第一行包含一个整数T,(0& ...

  10. Maven中基于POM.xml的Profile来动态切换配置信息

    [转载:https://blog.csdn.net/blueheart20/article/details/52838093] 1. Maven中的profile设置 Maven是目前主流的项目代码结 ...