亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    html網(wǎng)頁中如何實現(xiàn)居中效果(代碼分享)

    之前的文章《學習中值得了解html網(wǎng)頁的基本結構(總結)》中,給大家介紹了一個html基本結構具體非常清楚,有了這個保證你不會顛三倒四。下面下篇文章給大家分享一下html網(wǎng)頁中如何實現(xiàn)居中效果,有需要的朋友可以參考一下。

    html網(wǎng)頁中如何實現(xiàn)居中效果(代碼分享)

    html居中的元素可以分類為【行內】-【塊狀】-【行內塊狀】

    常用的塊狀元素:<div> <p> <h1>.....<h6> <ol> <ul> <dl> <table> <address> <blockquote> <form>

    常用的行內元素:<a> <span> <br> <i> <em> <strong> <label> <q> <cite> <code> <var>

    常用的行內塊狀元素:<img> <input>

    塊級元素指定:使用text-align:center就無效了。

    如果需要設置居中,通過設置左右兩邊的margin值為“auto”來實現(xiàn)。

    所以左右兩邊元素剩余區(qū)域各自均分,也就是元素兩側的區(qū)域各占50%,那么元素就左右居中了。

    寬度不固定的塊級元素

    通常有三種方式來實現(xiàn)居中

    1、通過table元素來實現(xiàn);

    2、設置 display: inline方法,將顯示類型設為行內元素;

    3、設置position:relative利用相對定位的方式,將元素向左偏移 50%來實現(xiàn)居中。

    <h1>標簽讓標題居中

    <p align="center">關關和鳴的雎鳩,棲息在河中的小洲</p>

    代碼效果

    html網(wǎng)頁中如何實現(xiàn)居中效果(代碼分享)

    img圖片居中的方法

    一般來說可以用CSS中的“text-align:center屬性,margin:0 auto或定位屬性”就可以居中。

    img定義一個父標簽,讓這個父標簽里面的內容居中,那么img自然就居中

    <p align="center">img……</p>

    input輸入框居中的方法

    style="text-align:center; "

    input外面嵌套div,設置div內部元素居中的方法

    <div align="center"> <input value="帳號"size="20"> </div>

    html網(wǎng)頁中如何實現(xiàn)居中效果代碼示例

    <!DOCTYPE html>  <html>  <head>  <meta charset="utf-8" />  <title>網(wǎng)頁制作</title>  <style>  *{padding: 0;margin: 0;}  .news{width: 1080px;height: 200px;margin: 0 auto;}  .left_1{width: 200px;height: 150px;float: left;padding: 10px;}  .left_2{width: 200px;height: 150px;float: left;margin-top: 10px;}  .center{width: 200px;height: 150px;float: left;padding: 10px;}  .right_1{width: 200px;height: 150px;float: left;margin-top: 10px;}  .right_2{width: 200px;height: 150px;float: left;padding: 10px;}  a{ display: block; text-align: center;}  a:hover{color:#00FF00;text-decoration: underline;} input.text{text-align:center;padding:10px 20px;width:300px;}  </style>  </head>  <body> <style  type="text/css"> .mydiv{ 	width:100%; 	height:500px; 	 	text-align:center;  }  </style>  <div style="width:960px; margin:0 auto; height:auto:">  <p style="text-align:center;"><img src="487.jpg" /></p>  </div>  <div class="mydiv"> <div class="reserch">                 <div input style="text-align:center;"><input type="text";></div>                 <button style="height:22px;width: 80px;text-align:center;">php搜一下</button>             </div>  <div class="news">  <div class="left_1">  <a href="http://www.php.cn/" target="_blank"><img src="5454.jpg"height="150" width="200" /></a>     <a href="http://www.php.cn/" target="_blank">圖片鏈接</a>  </div>  <div class="left_2">  <a href="http://www.php.cn/" target="_blank"><img src="78.jpg"height="150" width="200" /></a>      <a href="http://www.php.cn/" target="_blank">圖片鏈接</a>  </div>  <div class="center">  <a href="http://www.php.cn/" target="_blank"><img src="79.jpg"height="150" width="200" /></a>      <a href="http://www.php.cn/" target="_blank">圖片鏈接</a>  </div>  <div class="right_1">  <a href="http://www.php.cn/" target="_blank"><img src="89.jpg"height="150" width="200" /></a>      <a href="http://www.php.cn/" target="_blank">圖片鏈接</a>  </div>  <div class="right_2">  <a href="http://www.php.cn/" target="_blank"><img src="877.jpg"height="150" width="200" /></a>      <a href="http://www.php.cn/" target="_blank">圖片鏈接</a>  </div>  </div>  </body>  </html>

    代碼效果圖

    html網(wǎng)頁中如何實現(xiàn)居中效果(代碼分享)

    想要單純用html語言的話,那選擇就是<center> </center> 如果你是搞網(wǎng)頁設計的話,建議你使用css語言來修飾網(wǎng)頁。

    推薦學習:Html視頻教程

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號