HTML에서 테이블은 특히 데이터 표시 및 레이아웃 시나리오에서 가장 일반적인 요소 중 하나입니다. 스타일이 추가되지 않으면 기본적으로 테이블은 왼쪽 정렬 방식으로 조판됩니다. 이 경우 스타일을 사용하여 테이블을 중앙에 배치해야 합니다.
다음은 페이지에서 표를 수평 및 수직 중앙에 배치하는 데 도움이 되는 세 가지 방법입니다.
방법 1: CSS를 사용하여 표를 중앙에 배치합니다.
이것은 CSS text-align 속성 Center를 사용하는 가장 일반적이고 권장되는 방법입니다. 테이블 내용.
코드는 다음과 같습니다.
<style> table { margin: 0 auto; text-align: center; } </style> <table> <tr> <th>姓名</th> <th>年龄</th> <th>城市</th> </tr> <tr> <td>小明</td> <td>18</td> <td>北京</td> </tr> <tr> <td>小红</td> <td>17</td> <td>上海</td> </tr> </table>
CSS text-align 속성을 통해 테이블 텍스트 내용이 중앙에 오도록 설정합니다. 그중 margin: 0 auto
는 테이블을 가로 중앙에 놓도록 설정합니다.
방법 2: HTML 속성 사용
CSS를 사용하지 않으려면 HTML의 속성을 사용하여 테이블의 수평 중앙 정렬을 구현할 수도 있습니다.
코드는 다음과 같습니다.
<table align="center"> <tr> <th>姓名</th> <th>年龄</th> <th>城市</th> </tr> <tr> <td>小明</td> <td>18</td> <td>北京</td> </tr> <tr> <td>小红</td> <td>17</td> <td>上海</td> </tr> </table>
정렬을 추가하여 ="center" 속성을 테이블 태그에 추가하면 테이블을 중앙에 배치합니다.
방법 3: Flexbox 사용
CSS의 Flexbox는 수평 및 수직 중앙 정렬을 쉽게 구현할 수 있는 매우 유용한 레이아웃 방법입니다.
코드는 다음과 같습니다.
<style> .wrapper { display: flex; justify-content: center; align-items: center; height: 100vh; } .wrapper table{ width: 200px; } </style> <div class="wrapper"> <table> <tr> <th>姓名</th> <th>年龄</th> <th>城市</th> </tr> <tr> <td>小明</td> <td>18</td> <td>北京</td> </tr> <tr> <td>小红</td> <td>17</td> <td>上海</td> </tr> </table> </div>
div 요소에서 display: flex;, justify-content: center; 및 align-items: center를 설정하여 테이블을 중앙에 배치합니다. 여기서 height: 100vh는 컨테이너 요소를 차지합니다. 전체 뷰포트가 높습니다.
위는 테이블의 수평 중심을 맞추는 세 가지 방법입니다. 그러나 HTML에서 스타일을 설정하기 위해 속성을 사용하는 것은 CSS를 사용하는 것만큼 유지하고 관리하기가 쉽지 않다는 점에 유의하는 것이 중요합니다. 실제 개발에서는 더 나은 가독성과 유지 관리성을 위해 가능할 때마다 CSS를 사용하여 테이블 스타일을 제어하는 것이 좋습니다.
위 내용은 HTML에서 테이블을 중앙에 맞추는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

usestate () isareacthookusedtomanagestatefunctionalcomponents.1) itinitializesandupdatesstate, 2) workaledtthetThetThepleFcomponents, 3) canleadto'Stalestate'ifnotusedCorrecrally 및 4) performancanoptimizedUsecandusecaldates.

Reactispopularduetoitscomponent 기반 아카데입, 가상, Richcosystem 및 declarativenature.1) 구성 요소 기반 ectureallowsforeusableuipieces, Modularityandmainability 개선 가능성.

TodebugreactApplicationseffective, UsetheseStradegies : 1) 주소 propdrillingwithContapiorredux.2) handleaSnchronousOperationswithUsestAndUseefect, abortControllerTopReceConditions.3) 최적화 formanceSeMoAnduseCalbackTooid

usestate () inreactAllowsStateManagementInfunctionalComponents.1) itsimplifiessTatemanagement, 2) usethepRevCountFunctionToupDatesTestateSpreviousValue, PropeingStaleScallanceBackferperperperperperperperperperperperperpertoptiMizatio

chelectionSimple, IndependentStateVaribles; useUserEducer () useuserEducer () forcomplexStateLogicor () whenStatedSonpreviousState.1) usestate () isidealforsimpleupdatesliketogglingabooleorupdatingacounter.2) usbetterformanagingmentiplesub-vvalusorac

Usestate는 클래스 구성 요소 및 기타 상태 관리 솔루션보다 우수합니다. 국가 관리를 단순화하고 코드를 더 명확하게하고 읽기 쉽고 React의 선언적 특성과 일치하기 때문입니다. 1) Usestate는 함수 구성 요소에서 상태 변수를 직접 선포 할 수있게합니다. 2) 후크 메커니즘을 통해 다시 렌더링하는 동안 상태를 기억합니다.

useUsestate () forlocalcomponentStateManagement; 고려 사항 forglobalstate, complexlogic, orperformanceissues.1) usestate () isidealforsimple, localstate.2) useglobalstatesolutionslikereduxorcontextforsharedstate.3) optforredooxtoolkitormobxcomcoccomcoccomcoccomcoccomcoccomcoccomcoccomcoccomporccomcoccomporccomcoccomport

reusablecomponentsinreacececodemainabenabilityandefficiency는 hallowingesamecomponentacrossdifferentpartsofanapplicationorprojects.1) 그들을 retuduceredundancyandsimplifyupdates.2) theyseconsistencyinuserexperience.3) theyquireoptim


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경
