简体   繁体   English

css样式,仅更改一种图像样式

[英]css styling, change one image styling, not all of them

I'm really new to CSS and I have a sticky header menu with our company's logo in it where the menu and the image shrink to 48 pixels high once the user scrolls down. 我真的是CSS新手,并且有一个带有我们公司徽标的粘性标题菜单,一旦用户向下滚动,菜单和图像就会缩小到48像素高。 My code I use to shrink the logo is below, but how can I change just the logo image and include the .sticky to the logo image without changing all the images like I've done below with img {} ? 我用来缩小徽标的代码如下,但是如何更改徽标图像并将.sticky包含在徽标图像中,而又不像在img {}所做的那样更改所有图像呢?

   img {
        height: 100%;
        width: 50%;
        margin: 0;
        padding: 0;
        -webkit-transition: all 0.4s ease;
        transition: all 0.4s ease;
    }
    img.sticky {
        height: 100%;
        width: 25%;
        float: left;
        margin-left: 50px;
    }

I am a bit confused by your question. 你的问题让我有些困惑。 Would you like to apply the sticky class to only one img? 您是否要将粘性类仅应用于一个img? If so you could achieve this by simply creating the sticky class, and disassociating it with the img tag. 如果是这样,您可以通过简单地创建粘滞类并将其与img标签解除关联来实现。

So create a CSS class: 因此,创建一个CSS类:

.sticky {
   height: 100%;
   width: 25%;
   float: left;
   margin-left: 50px;
}

Then use some jQuery to add that class to the desired image when the scroll event fires: 然后,在滚动事件触发时,使用一些jQuery将此类添加到所需的图像中:

$( window ).scroll(function() {
   $('img:pseudo-selector').addClass("sticky");
});

OR 要么

Depending where the element is located, you could accomplish the same task with varying types of pseudo-classes: CodePen 根据元素所在的位置,您可以使用不同类型的伪类来完成相同的任务: CodePen

See Pseudo-Classes 参见伪类

I don't know if this is what you're looking for exactly, but maybe this could be of help. 我不知道这是否正是您要寻找的东西,但这也许会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM