欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

網(wǎng)頁設(shè)計(jì)

html元素水平居中的方法

時(shí)間:2025-04-25 11:27:00 網(wǎng)頁設(shè)計(jì) 我要投稿
  • 相關(guān)推薦

html元素水平居中的方法

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

  方法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元素 垂直居中 于 其父級(jí)元素的方法:

  代碼如下:

  <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元素 水平垂直居中 于 其父級(jí)元素的方法:

  方法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 "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/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居中浮動(dòng)元素的使用方法05-31

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

CSS 如何使p層水平居中04-28

用CSS讓DIV層水平居中實(shí)例05-16

用CSS讓p層水平居中實(shí)例04-08

html5的canvas方法使用01-19

HTML5學(xué)習(xí)方法05-02

php過濾危險(xiǎn)html代碼的方法05-31

html5的學(xué)習(xí)方法指導(dǎo)03-01