原因是默認情況下block-level元素采用full-width。 在HTML中做了一些更改:https://codepen.io/emmeiWhite/pen/PoGeJze FULL WORKING CODE: *{ margin:0; padding:0; box-sizing:border-box;}.hero-wrapper{ min-height: 100vh; background: linear-gradient(to right, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.6)), url(https://picsum.photos/id/1/367/267) center top; background-size: cover; position: relative; display: flex; flex-direction: row; justify-content: center; align-items: center;}.container{ color:#fff; text-align:center;}.navbar{ position:absolute; left:0; top:0; right:0; background:yellow; padding:0.5rem; opacity:0.5; color:red;