我運行了你的代碼,它工作得和我想的一樣好。 不,在CSS中,float屬性還沒有被棄用,您仍然可以使用它。但是,對于高級且更簡潔的代碼,最好使用flexbox 您的代碼可以是這樣的: body { margin: 0; padding: 0;}#security { position: relative; background: url('https://zupimages.net/up/20/21/9zj3.jpg') no-repeat; background-size: cover; background-attachment: fixed; width: 100%; min-height: 500px; display: flex; /* displaying it as a flexbox */ justify-content: end; /* shifting its content to the end "right" */}#security .security-wrapper { background-color: rgba(255, 255, 255, 0.7); width: 50%;}#security .security-title { text-transform: uppercase; font-size: 32px; color: #c22312;