margin left and right on width 100%

前端 未结 4 1651
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 21:16

I have a div that\'s set to width 100%. I wanted to set a margin right and left of 20px. For some reason only the left is being pushed over 20px. It ignores the right. Is th

4条回答
  •  走了就别回头了
    2021-01-14 22:12

    Not stupid at all. What's happening is you are trying to set a banner somewhat like this: (# is the margin)

    ==========
    #--------#
    ==========
    

    but it ends up like this:

    ==========
    #----------#
    ==========
    

    making it look like this:

    ==========
    #---------
    ==========
    

    adding a margin does not reduce the set width of 100%.

    you might try using left:20px; right:20px; and leave the width and margin auto

    EDIT
    or just leaving width off like the others have suggested. :P

提交回复
热议问题