超碰免费人人操|国产视频二区久久艹人人操|欧美激情第一页在线|久热最新无码中文视频|91精品国际成人|亚洲成人精品在线视频青青草|久草免费高清完整在线观看|你懂的AV在线日本黄网页|国产黄色AV日韩女同网|欧美成人色区导航片av

html元素水平居中的方法

時間:2025-09-30 04:29:36 網(wǎng)頁設(shè)計 我要投稿

html元素水平居中的方法

  html元素有哪些?水平居中于其父級元素的方法你是否知道呢?就讓小編來告訴你們哦!

  方法1:

  代碼如下:

  <p class="wrap">

  <p class="left-right-middle1">左右居中方法1</p>

  </p>

  代碼如下:

  html,body,p{

  margin:0;

  padding:0;

  height:100%;

  position:relative;

  }

  .wrap{

  width:400px;

  height:300px;

  margin:10px;

  border:1px solid #000;

  }

  .left-right-middle1{

  width:200px;

  background-color:#69F;

  margin:0 auto;

  }

  方法2:

  代碼如下:

  <p class="wrap">

  <p class="left-right-middle2">左右居中方法2</p>

  </p>

  代碼如下:

  html,body,p{

  margin:0;

  padding:0;

  height:100%;

  position:relative;

  }

  .wrap{

  width:400px;

  height:300px;

  margin:10px;

  border:1px solid #000;

  }

  .left-right-middle2{

  width:200px;

  background-color:#69F;

  left:50%;

  margin-left:-100px;

  }

  html元素 垂直居中 于 其父級元素的方法:

  代碼如下:

  <p class="wrap">

  <p class="top-bottom-middle">上下居中</p>

  </p>

  代碼如下:

  html,body,p{

  margin:0;

  padding:0;

  height:100%;

  position:relative;

  }

  .wrap{

  width:400px;

  height:300px;

  margin:10px;

  border:1px solid #000;

  }

  .top-bottom-middle{

  height:200px;

  background-color:#69F;

  top:50%;

  margin-top:-100px;

  }

  html元素 水平垂直居中 于 其父級元素的方法:

  方法1:

  代碼如下:

  <p class="wrap">

  <p class="all-middle1">上下左右居中方法1</p>

  </p>

  代碼如下:

  html,body,p{

  margin:0;

  padding:0;

  height:100%;

  position:relative;

  }

  .wrap{

  width:400px;

  height:300px;

  margin:10px;

  border:1px solid #000;

  }

  .all-middle1{

  width:200px;

  height:200px;

  background-color:#69F;

  top:50%;

  margin:-100px auto 0;

  }

  方法2:

  代碼如下:

  <p class="wrap">

  <p class="all-middle2">上下左右居中方法2</p>

  </p>

  代碼如下:

  html,body,p{

  margin:0;

  padding:0;

  height:100%;

  position:relative;

  }

  .wrap{

  width:400px;

  height:300px;

  margin:10px;

  border:1px solid #000;

  }

  .all-middle2{

  width:200px;

  height:200px;

  background-color:#69F;

  top:50%;

  left:50%;

  margin:-100px 0 0 -100px;

  }

  完整代碼:

  代碼如下:

  <!DOCTYPE html PUBLIC "-/pic/pic/pic/pic/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="/pic/1999/xhtml">

  <head>

  <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />

  <title>p Middle</title>

  <style type="text/css">

  html,body,p{

  margin:0;

  padding:0;

  height:100%;

  position:relative;

  }

  .wrap{

  width:400px;

  height:300px;

  margin:10px;

  border:1px solid #000;

  }

  .left-right-middle1{

  width:200px;

  background-color:#69F;

  margin:0 auto;

  }

  .left-right-middle2{

  width:200px;

  background-color:#69F;

  left:50%;

  margin-left:-100px;

【html元素水平居中的方法】相關(guān)文章:

CSS居中浮動元素的使用方法11-28

div水平垂直居中顯示01-19

CSS 如何使p層水平居中02-03

用CSS讓DIV層水平居中實例12-13

用CSS讓p層水平居中實例10-08

php過濾危險html代碼的方法11-23

html5的canvas方法使用01-19

HTML5學習方法11-11

學習HTML5方法09-29

  • 相關(guān)推薦