DIV 내부의 버튼을 중앙에 배치하는 데 문제가 있습니다.
현재 얻은 결과는 다음과 같습니다.
HTML은 다음과 같습니다.
<div id="buttonDiv">
<div class="button">
<button type="submit" onClick="setSid()">Click here to Start Test</button>
</div>
</div>
CSS는 다음으로 구성됩니다.
#buttonDiv {
position: fixed;
width:200px;
height:200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
border-bottom-width:1px;
border-top-width:1px;
border-right-width:1px;
border-left-width:1px;
border-style:solid;
border-color:#000000;
}
.button {
display:table-cell;
align-content:center;
vertical-align:middle;
}
이 경로는 텍스트에는 작동하지만 버튼에는 작동하지 않는 것 같습니다. 기쁨없이 버튼에 직접 클래스를 추가해 보았습니다.
감사
부모 컨테이너에 텍스트 정렬 중앙을 추가하면 버튼이 수평 중앙에 배치됩니다. 그런 다음 상단을 사용할 수 있습니다 : 50 %; 변환 : translateY (-50 %); 수직으로 중앙에 트릭.
HTML
<div id="buttonDiv">
<button type="submit" onClick="setSid()">Click here to Start Test</button>
</div>
CSS
#buttonDiv {
position: fixed;
width:200px;
height:200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
border-bottom-width:1px;
border-top-width:1px;
border-right-width:1px;
border-left-width:1px;
border-style:solid;
border-color:#000000;
text-align:center;
}
button {
position:relative;
top: 50%;
transform: translateY(-50%);
}
아래 수정
'.button'div를 유지해야하는 경우 상단을 이동할 수 있습니다 : 50 %; 변환 : translateY (-50 %); 그 수업에.
HTML
<div id="buttonDiv">
<div class="button">
<button type="submit" onClick="setSid()">Click here to Start Test</button>
</div>
</div>
CSS
#buttonDiv {
position: fixed;
width:200px;
height:200px;
top: 50%;
left: 50%;
margin: -100px 0px 0px -100px;
border: 1px solid #000;
text-align:center;
}
.button {
position:relative;
top: 50%;
transform: translateY(-50%);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다