简体   繁体   English

在几个子元素中选择一个ID

[英]Selecting an id within several sub elements

I'm currently using Wordpress with a theme. 我目前正在将Wordpress用于主题。

I'm trying to edit the mobile view of the logo, however when you start to scroll down the page the navigation bar reduces even more in size and I'm having trouble making additional changes when it's in that state. 我正在尝试编辑徽标的移动视图,但是,当您开始向下滚动页面时,导航栏的尺寸会进一步减小,并且在该状态下无法进行其他更改。

<header id="site-header" class="" role="banner">
        <div id="header-wrapper">
            <div id="header-container" class="clearfix">
                <div id="site-logo">

When the navigation bar drops to a smaller size the first line becomes 当导航栏减小到较小的尺寸时,第一行变为

<header id="site-header" class="header-sticked" role="banner">

Is it possible to modify site-header only when 'header-sticked' is present? 仅当出现“粘贴标头上”时,才可以修改网站标 吗? I know I could edit the theme to add a class to site-logo but I'm interested to see if this is possible with only CSS. 我知道我可以编辑主题以将一个类添加到site-logo,但是我很想知道是否只有CSS才有可能。

For example (psuedo) something like 例如(psuedo)类似

.header-sticked#header-wrapper#header-container#site-logo {
//blah
}

I'm pretty sure you're looking for 我很确定你在找

#site-header.header-sticked #site-logo {
  // blah
}

You're therefore styling the logo only when it's nested inside the site header with the class .header-sticked 因此,仅当徽标嵌套在带有 .header-sticked类的网站标题中时,才可以对徽标进行样式设置

Your question isn't too clear, but if you want to address an element that has both id site-header and class header-sticked , then 您的问题不太清楚,但是如果要处理同时具有id site-header和class header-sticked的元素,则

#site-header.header-sticked {
  /* blah */
}

will do. 会做。

However, if you want to address the id site-logo within, you need this 但是,如果要在其中寻址id site-logo ,则需要此

#site-header.header-sticked #site-logo {
  /* blah */
}

Note the space before the #site-logo , and the fact that you don't need any intermediate ids. 请注意#site-logo之前的空格,以及您不需要任何中间ID的事实。

I'm not sure I understood your question but if you have : <header id="site-header" class="header-sticked" role="banner"> 我不确定我是否理解您的问题,但是如果您有: <header id="site-header" class="header-sticked" role="banner">

Then the following css will apply to the element 然后以下css将应用于元素

#site-header.header-sticked{
width: 100px;
height: 100px;
background: black;
}

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

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