簡體   English   中英

相同的 css 在不同的瀏覽器中定位不同的結果

[英]same css position different results in diff browsers

當在這 3 個差異中看到時,表單中文本字段的垂直位置怎么可能有 3 px 的差異。 瀏覽器?

我快瘋了。 試圖在 CSS 中修復它是不好的,因為如果我改變它,它在一個中很好,但在其他中則不然。

#pricefromR 

{width:75px;
position:relative;
right:40px;
top: 50px;
}

#pricetoR 

{width:75px;
position:relative;
right:-45px;
top: 24px;
}

所以這對應於兩個應該平行的 texfields,它們彼此處於同一級別,但它們不在不同的瀏覽器中,相差 3 px,並且與其他對都在 LI 中的情況相同

<li>
        <input type ="text" id = "areafromR" placeholder="area from" name = "areafrom" maxlength = "5">&nbsp;
        <input type ="text" id = "areatoR" placeholder="area to" name = "areato" maxlength = "5">
    </li>

所有瀏覽器都不同,它們有不同的默認值,以及不同的 wu=idths/heights。 我所知道的最好方法是使用百分比,但這可能會變得復雜。 您可以為不同的瀏覽器制作單獨的 CSS。 例如...... 那是為Internet Explorer

你應該嘗試重置你的 CSS

如果您不知道,每個瀏覽器都有自己的默認“用戶代理”樣式表,它用來使無樣式的網站看起來更清晰。 例如,大多數瀏覽器默認將鏈接設為藍色,將訪問鏈接設為紫色,為表格提供一定量的邊框和內邊距,將可變字體大小應用於 H1、H2、H3 等,並對幾乎所有內容應用一定量的內邊距。 有沒有想過為什么提交按鈕在每個瀏覽器中看起來都不一樣? 它限制了瀏覽器之間的差異

使用 CSS 重置,您可以強制每個瀏覽器將其所有樣式重置為 null,從而減少跨瀏覽器差異

使用此代碼:

/**
* Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
* http://cssreset.com
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

通常的做法是將其放在另一個 CSS 文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM