Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 确定正在使用的浏览器,然后根据该浏览器设置类的样式_Javascript_Html_Css - Fatal编程技术网

Javascript 确定正在使用的浏览器,然后根据该浏览器设置类的样式

Javascript 确定正在使用的浏览器,然后根据该浏览器设置类的样式,javascript,html,css,Javascript,Html,Css,有没有一种方法可以检查站点在哪个浏览器中被查看,然后根据该方法更改CSS类中的某些元素,使其在所有浏览器上看起来都相同 在CSS中有没有这样做的方法 编辑: 好的,我现在已经让它在IE和firefox中工作了,但是在chrome中它看起来有点不对劲……是否有一些Javascript可以检测我是否在使用chrome,然后基于此更改类的页边空白底部#titleAreaBox?您可以对Internet Explorer使用条件注释,例如: <!--[if IE 6]> // IE6

有没有一种方法可以检查站点在哪个浏览器中被查看,然后根据该方法更改CSS类中的某些元素,使其在所有浏览器上看起来都相同

在CSS中有没有这样做的方法

编辑:


好的,我现在已经让它在IE和firefox中工作了,但是在chrome中它看起来有点不对劲……是否有一些Javascript可以检测我是否在使用chrome,然后基于此更改类的页边空白底部#titleAreaBox?

您可以对Internet Explorer使用条件注释,例如:

<!--[if IE 6]>
    // IE6
<![endif]-->
<!--[if lte IE 8]>
    // IE8 or below
<![endif]-->


对于其他浏览器,您必须使用JavaScript。(提示:请尝试使用
navigator.userAgent
,它在我的计算机上是
“Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/27.0.1453.110 Safari/537.36”
,以获取更多信息。

您可以通过条件注释为Internet Explorer执行此操作,例如:

<!--[if IE 6]>
    // IE6
<![endif]-->
<!--[if lte IE 8]>
    // IE8 or below
<![endif]-->


对于其他浏览器,您必须使用JavaScript。(提示:尝试使用
navigator.userAgent
,在我的计算机上是
“Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/27.0.1453.110 Safari/537.36”
)了解更多信息,.

您需要此对象

您需要此对象

您可以使用以下方法逐步增强CSS:

Modernizer是一个检测HTML5和CSS3特性的JavaScript库 在用户的浏览器中


您可以通过以下方式逐步增强CSS:

Modernizer是一个检测HTML5和CSS3特性的JavaScript库 在用户的浏览器中

使用如何

它运行在服务器端,允许您在CSS代码中添加条件 以下是该项目网站上的一个示例:

body {
    font: 90%/1.45em "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
    background-color: #fff;
}

body, html {
    height: 100%;
    width: 100%;
}

.container {
    text-align: center;
    font-size: 3em;
}

[if IE].container {
    height: 100%;
    width: 100%;
    text-align: center;
    line-height: 2em;

    [if gte IE 7]background: url('ie7.png') no-repeat center center;
    [if lte IE 6]background: url('ie.jpg') no-repeat center center;
}

[if Webkit].container {
    position: absolute;
    top: 50%;
    left: 50%;
    height: 70px;
    width: 400px;
    margin-top: -125px;
    margin-left: -200px;
    padding-top: 180px;

    -webkit-border-radius: 30px;
    -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.5);

    background: url('webkit.png') no-repeat center 30px;
    background-color: #eee;

    -webkit-text-stroke: 1px #555;
    text-shadow: 5px 5px 5px rgba(0, 0, 0, 0.5);
}

[if Opera].container {
    position: absolute;
    top: 50%;
    height: 60px;
    width: 100%;
    margin-top: -100px;
    padding-top: 140px;

    background: url('opera.png') no-repeat center 10px;
    background-color: #ccc;
}

[if Gecko].container {
    position: absolute;
    top: 0;
    left: 50%;
    height: 100%;
    width: 300px;
    margin-left: -150px;

    font-size: 32px;
    line-height: 2em;

    background: url('moz.png') no-repeat center center;
    background-color: #ddddff;
}
使用如何

它运行在服务器端,允许您在CSS代码中添加条件 以下是该项目网站上的一个示例:

body {
    font: 90%/1.45em "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
    background-color: #fff;
}

body, html {
    height: 100%;
    width: 100%;
}

.container {
    text-align: center;
    font-size: 3em;
}

[if IE].container {
    height: 100%;
    width: 100%;
    text-align: center;
    line-height: 2em;

    [if gte IE 7]background: url('ie7.png') no-repeat center center;
    [if lte IE 6]background: url('ie.jpg') no-repeat center center;
}

[if Webkit].container {
    position: absolute;
    top: 50%;
    left: 50%;
    height: 70px;
    width: 400px;
    margin-top: -125px;
    margin-left: -200px;
    padding-top: 180px;

    -webkit-border-radius: 30px;
    -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.5);

    background: url('webkit.png') no-repeat center 30px;
    background-color: #eee;

    -webkit-text-stroke: 1px #555;
    text-shadow: 5px 5px 5px rgba(0, 0, 0, 0.5);
}

[if Opera].container {
    position: absolute;
    top: 50%;
    height: 60px;
    width: 100%;
    margin-top: -100px;
    padding-top: 140px;

    background: url('opera.png') no-repeat center 10px;
    background-color: #ccc;
}

[if Gecko].container {
    position: absolute;
    top: 0;
    left: 50%;
    height: 100%;
    width: 300px;
    margin-left: -150px;

    font-size: 32px;
    line-height: 2em;

    background: url('moz.png') no-repeat center center;
    background-color: #ddddff;
}

对于Internet explorer,您可以在head html标记中添加以下内容:

<!--[if IE 6]>
...include IE6-specific stylesheet here...
<![endif]-->
<!--[if IE 7]>
...include IE7-specific stylesheet here...
<![endif]-->
<!--[if lte IE 8]>
    // IE8 or below
<![endif]-->

对于mozilla,您可以将其添加到样式表中,以仅为mozilla浏览器指定css代码

<style type="text/css">
@-moz-document url-prefix() {
    h1 {
        color: red;
    }
}

/***** Selecor Hacks ******/

/* IE6 and below */
* html #uno  { color: red }

/* IE7 */
*:first-child+html #dos { color: red } 

/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }

/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }

/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}

/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}

/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* Everything but IE6-8 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }



/***** Attribute Hacks ******/

/* IE6 */
#once { _color: blue }

/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }

/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }

/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */
</style>

@-moz文档url-前缀(){
h1{
颜色:红色;
}
}
/*****Selecor黑客******/
/*IE6及以下*/
*html#uno{颜色:红色}
/*IE7*/
*:first child+html#dos{color:red}
/*IE7、FF、Saf、Opera*/
html>body#tres{color:red}
/*IE8、FF、Saf、Opera(除IE 6、7外的所有内容)*/
html>/**/body#cuatro{颜色:红色}
/*Opera 9.27及以下版本,safari 2*/
html:first child#cinco{color:red}
/*狩猎2-3*/
html[xmlns*=“”]正文:最后一个子项#seis{color:red}
/*safari 3+、chrome 1+、opera9+、ff 3.5+*/
正文:第n个类型(1)#siete{颜色:红色}
/*safari 3+、chrome 1+、opera9+、ff 3.5+*/
正文:第一种#ocho{颜色:红色}
/*saf3+,chrome1+*/
@媒体屏幕和(-webkit最小设备像素比:0){
#diez{颜色:红色}
}
/*iPhone/mobile webkit*/
@媒体屏幕和屏幕(最大设备宽度:480px){
#纹理{颜色:红色}
}
/*狩猎2-3.1*/
html[xmlns*=“”]:根#树{颜色:红色}
/*Safari 2-3.1,Opera 9.25*/
*|html[xmlns*=“”]#catorce{color:red}
/*除了IE6-8之外的一切*/
:root*>#quince{颜色:红色}
/*IE7*/
*+html#dieciocho{颜色:红色}
/*仅限Firefox。1+ */
#Venticuatro,x:-moz任意链接{color:red}
/*Firefox 3.0+*/
#Venticinco,x:-moz任意链接,x:default{color:red}
/*****属性黑客******/
/*IE6*/
#一次{颜色:蓝色}
/*IE6,IE7*/
#文档{*颜色:蓝色;/*或#颜色:蓝色*/}
/*除了IE6什么都有*/
#颜色{color/**/:blue}
/*IE6,IE7,IE8*/
#diecinueve{color:blue\9;}
/*IE7,IE8*/
#颜色{color/*\**/:blue\9;}
/*IE6,IE7——充当一个!重要的*/
#veintesiete{color:blue!ie;}/*后面的字符串!什么都可以*/

对于Internet explorer,您可以将其添加到头部html标记中:

<!--[if IE 6]>
...include IE6-specific stylesheet here...
<![endif]-->
<!--[if IE 7]>
...include IE7-specific stylesheet here...
<![endif]-->
<!--[if lte IE 8]>
    // IE8 or below
<![endif]-->

对于mozilla,您可以将其添加到样式表中,以仅为mozilla浏览器指定css代码

<style type="text/css">
@-moz-document url-prefix() {
    h1 {
        color: red;
    }
}

/***** Selecor Hacks ******/

/* IE6 and below */
* html #uno  { color: red }

/* IE7 */
*:first-child+html #dos { color: red } 

/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }

/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }

/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}

/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}

/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* Everything but IE6-8 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }



/***** Attribute Hacks ******/

/* IE6 */
#once { _color: blue }

/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }

/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }

/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */
</style>

@-moz文档url-前缀(){
h1{
颜色:红色;
}
}
/*****Selecor黑客******/
/*IE6及以下*/
*html#uno{颜色:红色}
/*IE7*/
*:first child+html#dos{color:red}
/*IE7、FF、Saf、Opera*/
html>body#tres{color:red}
/*IE8、FF、Saf、Opera(除IE 6、7外的所有内容)*/
html>/**/body#cuatro{颜色:红色}
/*Opera 9.27及以下版本,safari 2*/
html:first child#cinco{color:red}
/*狩猎2-3*/
html[xmlns*=“”]正文:最后一个子项#seis{color:red}
/*safari 3+、chrome 1+、opera9+、ff 3.5+*/
正文:第n个类型(1)#siete{颜色:红色}
/*safari 3+、chrome 1+、opera9+、ff 3.5+*/
正文:第一种#ocho{颜色:红色}
/*saf3+,chrome1+*/
@媒体屏幕和(-webkit最小设备像素比:0){
#diez{颜色:红色}
}
/*iPhone/mobile webkit*/
@媒体屏幕和屏幕(最大设备宽度:480px){
#纹理{颜色:红色}
}
/*狩猎2-3.1*/
html[xmlns*=“”]:根#树{颜色:红色}
/*Safari 2-3.1,Opera 9.25*/
*|html[xmlns*=“”]#catorce{color:red}
/*除了IE6-8之外的一切*/
:root*>#quince{颜色:红色}
/*IE7*/
*+html#dieciocho{颜色:红色}
/*仅限Firefox。1+ */
#Venticuatro,x:-moz任意链接{color:red}
/*Firefox 3.0+*/
#Venticinco,x:-moz任意链接,x:default{color:red}
/*****属性黑客******/
/*IE6*/
#一次{颜色:蓝色}
/*IE6,IE7*/
#文档{*颜色:蓝色;/*或#颜色:蓝色*/}
/*除了IE6什么都有*/
#颜色{color/**/:blue}
/*IE6,IE7,IE8*/
#diecinueve{color:blue\9;}
/*IE7,IE8*/
#颜色{color/*\**/:blue\9;}
/*IE6,IE7——充当一个!重要的*/
#veintesiete{color:blue!ie;}/*后面的字符串!什么都可以*/

您可以通过PHP使用$\u会话['HTTP\u USER\u AGENT']

也可以通过HTML以IE浏览器为目标: 尝试:


或在CSS文件中,请参见溢出问题:

您可以通过PHP使用$\u会话['HTTP\u USER\u AGENT'来完成此操作

也是