Google지도 API를 사용하고 생성 된지도를 배경으로 설정하려고합니다. div 중첩 및 중심
이
은<div class="content">
<div class="map"></div>
<div class="element"></div>
</div>
CSS의
.content {
position: relative;
height: 500px;
}
.map {
position: absolute;
width: 100%;
height: 100%;
}
.element {
position: absolute;
width: 900px;
margin-left: auto;
margin-right: auto;
z-index: 1;
}
내 HTML 인 사이트는이
|-------------------------------------|
| |
| |
| | <- Other content
| |
|-------------------------------------|
|.map |-------------------------| |
| |.element | | <- The concerned content (.content)
| | | |
| |-------------------------| |
|-------------------------------------|
같이하도록되어 그러나 결과는 동일하지 않습니다. 마진을 남긴 자동차는 물론 작동하지 않습니다. 중첩은 괜찮지 만 오른쪽 여백도 있지만 왼쪽 여백을 위해 어떻게 할 수 있습니까? 내 사이트는 항상 중심에 위치해야합니다.
감사합니다. 앨런에서
해결 방법 : DOM 요소가 절대적으로 위치를
.content {
position: relative;
height: 500px;
}
.map {
position: absolute;
width: 100%;
height: 100%;
z-index: 0;
}
.element {
position: relative;
width: 900px;
margin-left: auto;
margin-right: auto;
z-index: 1;
}
'left'와'right'을 0으로 설정하면'auto'의 왼쪽과 오른쪽 여백은 절대적으로 배치되고 명시 적으로 크기가 조정되는 블록에서 작동합니다. 그러나 화면의 너비가 900px보다 작 으면 블록을 가운데 놓지 마라. 대체로 @Niels Keurentjes가 보여 주듯이 음수 여백을 사용하면 절대 요소를 가운데에 배치하는 데 가장 유용 할 수 있습니다. – DRD