web h5常用代碼總結

來源:互聯網
上載者:User

標籤:doc   禁用   int   動畫   限制   顯示   vma   resize   javascrip   

注意:本文原創,轉載請說明出處

1.使圖片和文字水平置中,給圖片css樣式:vertical-align: middle;
vertical-align:middle的時候,是該元素的中心對齊周圍元素的中心。

2.給一個div透明背景,給div添加css: opacity:0.7; filter:alpha(opacity=70);

3.相容各個瀏覽器,添加css樣式:filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5;

4.如何通過css修改密碼框預設是黑點的樣式,比如想改成*星號,如何??
<input id="mima" onKeyUp="document.getElementById(‘a‘).value=this.value.replace(/./g,‘%‘);" />
那個%隨你改,改什麼顯示什麼。

js控制,input密碼顯示‘*‘的連結地址:http://www.xuebuyuan.com/1346201.html

5.相容 IE 和 FF 的換行 CSS 推薦樣式:word-wrap:break-word; overflow:hidden;(這個是最好的方式)

一般情況下只需要設定好寬度限制,比如這裡只設定最大寬度為300px(max-width:300px),然後對父級使用overflow:hidden隱藏溢出圖片,同時為了相容IE6我們設定個width:expression(this.width > 300 ? "300px" : this.width);解決即可。


下面的這種方法就可以解決背景透明,文字不透明的問題了:
div{background:rgba(0,0,0,0.2) none repeat scroll !important; /*實現FF背景透明,文字不透明*/
background:#000; filter:Alpha(opacity=20);/*實現IE背景透明*/
width:500px; height:500px; color:#F30; font-size:32px; font-weight:bold;}
div p{ position:relative;}/*實現IE文字不透明*/

6.去除chromeGoogle瀏覽器input內建邊框
在css中加入代碼:
1 input,button,select,textarea{outline:none}
2 textarea{resize:none}
不過在比較低版本的Google瀏覽器和360極速瀏覽器還是會出現了,最完美的還是更改這個邊框樣式,即把把邊框設為跟設計稿中的邊框大小顏色都一樣,即:border:#f7bed8 1px solid;

7.width: 90%;/*寫給不支援calc()的瀏覽器*/
width:-moz-calc(100% - (10px + 5px) * 2);
width:-webkit-calc(100% - (10px + 5px) * 2);
width: calc(100% - (10px + 5px) * 2);

8.CSS屬性 table 的 border-collapse 邊框合并 給table一個屬性 border-collapse:collapse;

9.在網站HTML檔案的開頭,增加viewport meta標籤告訴瀏覽器視口寬度等於裝置螢幕寬度,且不進行初始縮放。代碼如下:
<meta name="viewport" content="width=device-width, initial-scale=1" />   

webstrom 快速鍵:meta:vp 按tab鍵

10.在CSS檔案尾部增加針對不同螢幕解析度的規則。例如使用如下的代碼,可以讓螢幕寬度低於480像素的裝置(如iPhone等),網頁側欄隱藏中部內容欄寬度自動調節。以下代碼針對Z-Blog,WordPress相關標籤名稱只需修改一下即可。
@media screen and (max-device-width: 480px) {
#divMain{
float: none;
width:auto;
}
#divSidebar {
display:none;
}
}

11.頁面使用相對字型 在HTML頁面上不要使用絕對字型(px),而要使用相對字型(em),對於大多數瀏覽器來說,通常用 em = px/16 換算,例如16px就等於1em。

12.HTML禁止網頁文字複製,禁止查看原始碼
(1)禁止複製
放在任意位置
<script language=javascript>
window.onselectstart=function() {return false;} //禁用選擇
window.oncopy=function() {return false;} //禁止複製
</script>

(2)禁止查看原始碼
放在頭部
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>

13.WOW.js - 頁面滾動動畫展示 (WOW.js 能讓頁面滾動時顯示動畫,使頁面更有趣。)

[email protected] {
font-family: ‘方正卡通簡體Regular‘;
src: url(‘方正卡通簡體.eot‘);
src: local(‘方正卡通簡體 Regular‘),
local(‘方正卡通簡體‘),
url(‘方正卡通簡體.woff‘) format(‘woff‘),
url(‘方正卡通簡體.ttf‘) format(‘truetype‘),
url(‘方正卡通簡體.svg#方正卡通簡體‘) format(‘svg‘);
}


15.var width=($(window).width()-1100)/2;
$(‘.side-nav-wrap‘).css(‘left‘,width-152+‘px‘);

 

16.解決iOS手機上input的button按鈕顏色顯示問題
input[type=button], input[type=submit], input[type=file], button { cursor: pointer; -webkit-appearance: none; }

 

17.解決手機點擊input的text的時候,出現背景色
-webkit-tap-highlight-color:rgba(0,0,0,0);

 

18.解決1920px的圖片水平置中<div style="text-align:center; position:absolute;top:0;left:50%;width:1000px;height:420px;margin-top:0px;margin-left:-960px"></div>

 

19.文字上下左右全有陰影:text-shadow: 1px 1px 3px white,0 -1px 3px white,-1px 0px 3px white;

 

20.<input type="text" id="keywords" name="keywords" value="輸入搜尋關鍵詞" onfocus="JavaScript:if(this.value==‘輸入搜尋關鍵詞‘)this.value=‘‘;" onblur="javascript:if(this.value==‘‘)this.value=‘輸入搜尋關鍵詞‘;"/>


21.去掉textarea右下角預設三條灰色斜杠 resize:none;

 

web h5常用代碼總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.