search

Home  >  Q&A  >  body text

前端 - div宽度设置成百分比问题

今天做一个页面时,一个p的width设置成70%,屏幕宽度是1366px,所以这个p宽度是956px左右,这没什么问题。但是当做自适应缩小屏幕时,p的宽度并不是屏幕的70%,这是怎么回事。

PHP中文网PHP中文网2769 days ago707

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:32:18

    I solved it myself. If Google Chrome does not add the meta name="viewport" tag to set it, there will be problems with the scaling ratio, but Firefox has no effect.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:32:18

    The width percentage unit is calculated relative to the width of its parent element. When the parent element of this p is Body, it should be 70% of the browser window width

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:32:18

    The screen has shrunk, and the 70% you set will be based on your current width * 70%, instead of the previous 956px

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:32:18

    Set width 100% for the parent element

    reply
    0
  • Cancelreply