GVKun编程网logo

html – nth-of-type(x)(带有媒体查询)在Safari 9.1.1中无法正常工作(媒体查询就是查询出当前浏览器的名称和版本号)

1

如果您对html–nth-of-type(x)(带有媒体查询)在Safari9.1.1中无法正常工作和媒体查询就是查询出当前浏览器的名称和版本号感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解h

如果您对html – nth-of-type(x)(带有媒体查询)在Safari 9.1.1中无法正常工作媒体查询就是查询出当前浏览器的名称和版本号感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解html – nth-of-type(x)(带有媒体查询)在Safari 9.1.1中无法正常工作的各种细节,并对媒体查询就是查询出当前浏览器的名称和版本号进行深入的分析,此外还有关于7.nth-of-type | nth-child?【CSS】、:nth-child和:nth-of-type的区别、 带有媒体查询,如何让它工作?、cannot convert t (type interface {}) to type string: need type assertion的实用技巧。

本文目录一览:

html – nth-of-type(x)(带有媒体查询)在Safari 9.1.1中无法正常工作(媒体查询就是查询出当前浏览器的名称和版本号)

html – nth-of-type(x)(带有媒体查询)在Safari 9.1.1中无法正常工作(媒体查询就是查询出当前浏览器的名称和版本号)

我有以下代码在Chrome中完美运行但在Safari中无法运行.

HTML

irst line

CSS

@media (min-width: 800px) {
#info span { display:  inline; }
#info span:nth-of-type(2) {display: none; }
}

@media (max-width: 800px) {
#info span { display:  none; }
#info span:nth-of-type(2) {display: table-column;}
}

我最初使用nth-child(x)对此进行了编码,但我读到了Safari不支持这一点.我用nth-of-type(x)替换它但它仍然无法正常工作.

如果你从一个’小’列宽开始,然后使它位,它就可以工作.如果再次缩小它,那就是Safari失败的地方.

检查Safari下的页面我可以看到CSS属性display:none;应用但似乎留下了剩余的东西或者……

这是一个jsfiddle与它,在Chrome上工作但在Safari:https://jsfiddle.net/auhbrmzg/2/上没有

只需“缩小”结果列宽度即可查看它的实际效果.

提前感谢您的意见.

干杯.

最佳答案
选择器正在工作.如果您检查Safari内部的元素,您会发现它正在添加样式“display:none”.问题是“display:none”对break标记没有影响.基本上,即使样式设置为“display:none;”,标签仍然存在.

这是你所拥有的替代品:

HTML:

irst line

CSS:

@media (min-width: 800px) {
    #info span { display:  inline; }
}

@media (max-width: 800px) {
    #info span {display:block;}
    #info span:nth-child(2) { display:  none; }
}

小提琴:
https://jsfiddle.net/fyqx97zo/9/

7.nth-of-type | nth-child?【CSS】

7.nth-of-type | nth-child?【CSS】

举例说明: 
<ul> <p>111</p> <span>222</span> <li>1</li> <li>2</li> <li>3</li> </ul> 
li:nth-of-type(2):表示ul下的第二个li元素 
li:nth-child(2):表示既是li元素又是在ul下的第二个元素(找不到)。 
建议一般使用nth-of-type,不容易出问题。

:nth-child和:nth-of-type的区别

:nth-child和:nth-of-type的区别

  nth-child和nth-of-type都是CSS3中新增的伪类选择器,平心而论,平时使用nth-child比较多,有时碰到些出乎意料的情况,也是改完就算了,并没有深入研究,以至于在今天之前,我还蠢蠢的以为nth-of-type比nth-child要严格,毕竟人家有个type。 
       大写的囧…. 
       好吧,我为自己的不求甚解惭愧下…

      网上关于nth-child和nth-of-type区别的内容并不多,能查到的也不是很满意,可能大家都跟我一样不求甚解,也有可能是因为大家觉得这个知识点并不重要,因此就没有再深入研究。 
      合抱之木,生于毫末;九层之台,起于累土;千里之行,始于足下。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>

        <style>
            .box{
                width: 50%;margin: auto;
            }
            ul,li{list-style: none;}
            .box div,p{
                border: 1px solid #008000;height: 30px;line-height:30px;text-indent: 10px;
            }
            .box div{
                margin: 10px auto;
            }
        </style>
    </head>
    <body>
        <div>
            <p>ppp</p>
            <p>ppp</p>
            <div>div</div>
            <div>div</div>
            <article>article</article>
            <div>div</div>
            <div>div</div>
            <div>div</div>
            <ul>
                <li>ul中的li标签</li>
            </ul>
            <p><span>p标签里面的span标签</span></p>
            <span>span</span>
        </div>
    </body>
</html>

效果如下: 
这里写图片描述

    后面的例子中,始终以此代码为标准,只增加CSS样式,DOM部分不变。

    现在我们开始以实例来看不同伪类选择器所展现出来的效果:

1、:nth-child

<style>
    ...
    .box :nth-child(2){
        background: yellow;
    }
</style>

效果如下: 
这里写图片描述

我们在使用nth-child时,并没有在其前面指定类型,现在选中的是.box下的第二个子元素。

2、:nth-of-type.

<style>
    ...
    .box :nth-of-type(2){
        background: yellow;
    }
</style>

效果如下: 
这里写图片描述

选中的是第二P标签和第二个div标签。 
结论1:在不指定类型时,nth-child(n)选中的是父元素下的第N个子元素。nth-of-type(n)选中的是父元素下的不同类型标签的第N个。

3、div:nth-chiid.

<style>
    ...
    .box div:nth-child(2){
        background:yellow;
    }
</style>

效果如下: 
这里写图片描述 

<style>
    ...
    .box p:nth-child(2){
        background:yellow;
    }
</style>


没有元素被选中。

在试试看p:nth-child(2);

效果如下: 
这里写图片描述

选中的是.box的第二个子元素,这个子元素的标签是P。

4、div:nth-chiid.

<style>
    ...
    .box div:nth-of-type(2){
        background:pink;
    }
</style>

 

这里写图片描述

选中的是.box下的div标签的第二个子元素

结论2:ele:nth-child(n)要求不仅仅是第n个子元素,并且这个子元素的标签是ele。ele:nth-of-type(n)选择的是父元素下ele标签的第二个

5、nth-last-child(n)和nth-last-of-type(n)的用法和nth-child(n),nth-of-type(n)用法相同,唯一的区别是:nth-last-child(n)是倒数第n个元素.nth-last-of-type(n)是倒数第n个标签。

6、last-child

<style>
    ...
    .box p:last-child{
        background: yellow;
    }
</style>

效果如下: 
这里写图片描述 
没有选中任何元素,因为父元素下最后一个子节点都不是P标签.

如果不指定元素类型:

<style>
    ...
    .box :last-child{
        background: yellow;
    }
</style>

效果如下: 
这里写图片描述 
有三个元素被选中,因为这三个元素都是其上一层父元素下的最后一个子元素.

6、last-of-type

<style>
    ...
    .box p:last-of-type{
        background: pink;
    }
</style>

 

效果如下:

这里写图片描述

选中了父元素下P标签的最后一个。

<style>
    ...
    .box :last-of-type{
        background: pink;
    }
</style>

 

效果如下:

这里写图片描述 
选中了父元素下不同类型标签的最后一个。

结论3:ele:last-child选中父元素下最后一个子元素,并且该子元素的标签必须为ele,否则一个都不选中。ele:last-of-type选中父元素下ele标签的最后一个.

<img> 带有媒体查询,如何让它工作?

带有媒体查询,如何让它工作?

如何解决<img> 带有媒体查询,如何让它工作?

有人可以帮我解决以下代码(不起作用)

  1. .image2{ display: none; }
  2. @media only screen and (max-width: 500px){
  3. .image1{ display: none; }
  4. .image2{ display: block; } }
  1. <img src="images/slider/4.gif" class="image1" title="#slider-direction-1"/>
  2. <img src="images/slider/4_m.gif" class="image2" title="#slider-direction-1"/>

我们的想法是获得响应式图像。谢谢!

解决方法

试试这个:

  1. <picture>
  2. <source media="(max-width:500px)" srcset="images/slider/4_m.gif"> <!-- img2 (mobile) -->
  3. <img src="images/slider/4.gif"> <!--img1 -->
  4. </picture>

cannot convert t (type interface {}) to type string: need type assertion

cannot convert t (type interface {}) to type string: need type assertion

问题:
在使用interface表示任何类型时,如果要将interface转为某一类型,直接强制转换是不行的,例如:

var t interface{} = "abc"

s := string(t)

cannot convert t(type interface {}) to type string: need type assertion

这样是不行的,需要进行type assertion类型断言,具体使用方法请参考:
golang 任何类型interface{}

更多信息:
http://www.jb51.cc/article/p-amhitjiw-bnz.html

今天的关于html – nth-of-type(x)(带有媒体查询)在Safari 9.1.1中无法正常工作媒体查询就是查询出当前浏览器的名称和版本号的分享已经结束,谢谢您的关注,如果想了解更多关于7.nth-of-type | nth-child?【CSS】、:nth-child和:nth-of-type的区别、 带有媒体查询,如何让它工作?、cannot convert t (type interface {}) to type string: need type assertion的相关知识,请在本站进行查询。

本文标签:

上一篇html – 如何通过Ctrl F搜索图像(html中搜索)

下一篇html – CSS多维数据集中的RotateX无法正常工作