简体   繁体   English

jQuery&secton没有隐藏我的徽标div ID

[英]Jquery & secton is not hiding my logo div id

I'm trying to hide my logo only on one div and show it on another. 我正在尝试仅在一个div上隐藏我的徽标,而在另一个div上显示它。 In one of my sections, I have a video so I do not need to show my logo. 在我的部分内容中,我有一个视频,因此不需要显示徽标。 I cant however do it at all. 但是我根本做不到。 It either just hides forever or just does not want to hide at all. 它要么永远隐藏,要么根本不想隐藏。

I have tried both style="" inside the div and jquery. 我在div和jquery中都尝试了style =“”。 None of which works. 都不起作用。

My HTML structure: 我的HTML结构:

<!-- HEADER -->
<header id="header" class="header-left">        
    <div class="header-inner clearfix">

        <!-- LOGO -->
        <div id="logo" class="logo-left">
            <a href="index.html">
                     <img id="dark-logo" src="files/uploads/logo_dark.png" srcset="files/uploads/logo_dark.png 1x, files/uploads/logo_dark@2x.png 2x" alt="Logo Dark">
                     <img id="light-logo" src="files/uploads/logo_light.png" srcset="files/uploads/logo_light@2x.png 1x, files/uploads/logo_light@2x.png 2x" alt="Logo Light">
            </a>
        </div>

        <!-- MAIN NAVIGATION -->
        <div id="menu" class="clearfix">            

            <div class="menu-actions">
                <div class="menu-toggle"><span class="hamburger"></span></div>
            </div> <!-- END .menu-actions -->

            <div id="menu-inner">
                <nav id="main-nav">
                    <ul>
                        <li><a href="index.html">xxx</a>
                        </li>
                        <li><a href="#">xxx</a>
                        <ul class="sub-menu">
                        <li><a href="xxx.html">xxx</a></li>
                        <li><a href="xxx.html">xxxx</a></li>
                        <li><a href="xxx.html">xxx</a></li>
                        </ul>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
     </div>
    <span class="pseudo-close header-close"></span>
</header>

Ok so before I show the source, here is what works : 好吧,在显示源代码之前,这是可行的

 <style>#logo img{opacity:0;visibility:hidden;}</style>

Pretty standard right? 很标准吧? So I tried hiding the logo in this same way into a section and it did not work . 因此,我尝试以相同的方式将徽标隐藏到一个部分中, 但它不起作用 Example: 例:

<section id="page-body" class="fullwidth-section text-dark" style="#logo img{opacity:0;visibility:hidden;}">

....

</section>

I then tried jQuery to hide the logo as a test. 然后,我尝试使用jQuery隐藏徽标作为测试。 This did not work at all. 这根本没有用 Example: 例:

<script src="files/js/jquery-1.12.4.min.js"></script>

<script>

$(document).ready(function(){


$("#logo").css({
display: "none",
visibility: "hidden"
});

$("#logo").hide();

</script>

What I was hoping to do is hide the logo in a single div then show it for the rest of the page. 我希望做的是将徽标隐藏在一个div中,然后在页面的其余部分显示它。 I had an idea to do this with jQuery or a section. 我有一个想法用jQuery或某一部分来做到这一点。 Anyone have any ideas on how to do this? 有人对如何执行此操作有任何想法吗?

style="#logo img{opacity:0;visibility:hidden;}"

This is not a valid HTML style attribute. 这不是有效的HTML style属性。 It's a selector for CSS that should be nested under the HTML's <style> tag. 它是CSS的选择器,应嵌套在HTML的<style>标记下。

When setting an element's style attribute, you only need to write the style properties. 设置元素的style属性时,只需编写样式属性。 This is how it should look: 它应该是这样的:

style="opacity:0;visibility:hidden;"

Your jQuery attempt to hide the logo should work when you remove the logo element's style tag. 当您删除logo元素的style标签时,您尝试隐藏徽标的jQuery尝试应该起作用。 Doing $('#logo').hide(); $('#logo').hide(); should work and is enough. 应该工作并且足够。

A few notes: 一些注意事项:

  1. Using opacity:0; 使用opacity:0; with visibility:hidden; 具有visibility:hidden; doesn't make sense. 没有道理。 Use either one of them, both make the element invisible. 使用它们之一,都使该元素不可见。
  2. You can just write $('#logo').hide(); 您可以只写$('#logo').hide(); , no need to the whole $("#logo").css({ section. ,不需要整个$("#logo").css({部分。
  3. You can shorthand $(document).ready(function(){ to just $(function() { 您可以将$(document).ready(function(){$(function() {
  4. Keep in mind using visibility:hidden; 请注意使用visibility:hidden; keeps the element inline the page, but invisible. 使元素保持页面内嵌,但不可见。 If you want to make it disappear completely, use display:none; 如果要使其完全消失,请使用display:none;

You can't write inline style to another element.Inline styles are applicable to the element itself. 您不能将内联样式写入另一个元素。内联样式适用于元素本身。

This is the right way 这是正确的方法

<style>#logo img{opacity:0;visibility:hidden;}</style>

This is not possible 这是不可能的

<section id="page-body" class="fullwidth-section text-dark" style="#logo img{opacity:0;visibility:hidden;}">

....

</section>

Try 尝试

section #logo img{opacity:0;visibility:hidden;}

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

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