position:fixed导航菜单覆盖内容的一种解决方法

Kevin 杂记 943 次浏览 40条评论

通常我们会用 position: fixed 设置固定元素,但同时也衍生了一个问题,后面的元素会被固定元素覆盖掉一部分。例如常见固定导航菜单,紧接着的内容会被固定元素遮挡住。虽然可以用 margin-top 预留空隙,但这种方法比较刻板。当设置一个固定外边距,为了兼容响应式设计,你还要为不同设备设置对应值,很是麻烦。

这里分享一个相对简单可以解决该问题的方法,利用 position: sticky 设置固定元素,这个粘性定位属性就不会有上面所说问题。但同时也存在缺点,部分浏览器不支持(浏览器兼容列表)。

如果你的项目不用考虑老旧浏览器支持,只需下面几行 CSS 属性就可以解决问题。

position: -webkit-sticky;
position: sticky;
top: 0;

效果演示可以查看这个简单例子

评论列表

  1. #1

    what is in ivermectin https://ivermectin.mlsmalta.com/

  2. #2

    vidalista questions and answers https://vidalista40mg.mlsmalta.com/

  3. #3

    dapoxetine package insert pdf https://ddapoxetine.com/

  4. #4

    online doctors prescriptions for pain https://edmeds.buszcentrum.com/

  5. #5

    albuterol pills dosage https://amstyles.com/

  6. #6

    lowest cost for cialis https://wisig.org/

  7. #7

    plaquenil copay assistance card https://hydroxychloroquinee.com/

  8. #8

    prednisone dosage https://prednisone.bvsinfotech.com/

  9. #9

    top online canadian pharmacies canadian https://buymeds.mlsmalta.com/

  10. #10

    can women take mens cialis https://tadalafil365.online/

  11. #11

    can women take mens cialis https://atadalafil.online/

  12. #12

    dapoxetine 60 https://dapoxetine.confrancisyalgomas.com/

  13. #13

    cdc malaria prophylaxis dosage https://hydroxychloroquine4u.com/

  14. #14

    cialis versus levitra versus viagra http://cialis.audiovideoninja.com/

  15. #15

    cialis versus levitra versus viagra https://cialis.adicbc.com/

  16. #16

    hydroxychloroquine pills for sale https://hhydroxychloroquine.com/

  17. #17

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  18. #18

    muse alprostadil suppository https://alprostadildrugs.com/ edex (alprostadil)

  19. #19

    best place to buy generic viagra online buy generic 100mg viagra online
    best over the counter viagra

  20. #20

    tadalafil citrate – tadalafil daily dose tadalafil online pharmacy

  21. #21

    where to buy cheap sildenafil https://eunicesildenafilcitrate.com/ price for sildenafil 100 mg

  22. #22

    ed pills online cheap ed pills from canada
    cheap ed pills in mexico

  23. #23

    buy ed pills ed treatment drugs
    ed pills without a doctor prescription

  24. #24

    vardenafil prices india https://vegavardenafil.com/ buy generic vardenafil over the counter with no pres. online

  25. #25

    buy ed drugs ed pills without a doctor prescription
    male erectile dysfunction

  26. #26

    Kqmdhl – ivermectin 1 topical cream Dceume jiyroo

  27. #27

    40 mg tadalafil https://elitadalafill.com/ tadalafil 30 mg

  28. #28

    Iqlgkf – cialis livraison rapide Wccmem sdpook

  29. #29

    Ykqbvn – furosempi.com Qccqfr cscwof

  30. #30

    Ppvhar – https://zithrobiot.com/# Msntvm tikjwd

  31. #31

    Dteaox – order tadalafil from canada 5mg Igzfny ddwezf

  32. #32

    Uvyqhg – literature review paper Pafnob hxkvdl

  33. #33

    Uziusg – viagra costa rica Dpqyuv uflair

  34. #34

    keftab price: minocin generic
    cephalexin tablets

  35. #35

    buy medication online from india: india pharmacies online india pharmacies shipping to usa

  36. #36

    Txamas – generic finasteride dr reddy Xjwlig hworrj

  37. #37

    overseas pharmacies shipping to usa: indian online pharmacies review indian online pharmacies review

  38. #38

    Ompdqy – generic viagra walmart Bghcra pqpjvg

  39. #39

    buy medication online from india: india pharmacy drugs buy prescriptions from india pharmacy

  40. #40

    maximum dose of vidalista http://vidallista.com/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。