Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                  <body>
    <header>
      <div class="site-branding">
        <div class="ast-site-identity" itemtype="https://schema.org/Organization" itemscope="itemscope">
          <span class="site-logo-img">
            <!-- This link will be overridden by JavaScript code. -->
            <a href="https://balistreetphotographer.com/" class="custom-logo-link" rel="home">
              <img
                src="https://balistreetphotographer.files.wordpress.com/2019/02/balistreetphotographer-logo-2-slashes-65.png"
                class="custom-logo" alt="cme dev logo white" width="80" height="80">
            </a>
          </span>
        </div>
      </div>
    </header>

    <section>
      <h1>Override the Logo &amp; Link for the Astra Theme Header</h1>
      
      <p><strong>Astra</strong> does not <em>respect</em> the header logo link when the default logo is swapped out via CSS. So, let's use some JavaScript to fix that.</p>
      
      <hr>

      <p>For medium-to-wide screens, let's display the <em>Bali Street Photographer</em> logo with the link to</p>
      <p><mark>https://balistreetphotographer.com/</mark></p> 

      <p>For mobile devices, we'll display the <em>Caught My Eye</em> logo with the link to</p>
      <p><mark>https://caughtmyeye.cc/</mark></p>
    </section>
    <footer>
      <p>This <em>use case</em> comes in handy when working with WordPress themes and you want a different logo link depending on the page or device size.</p>
    </footer>
  </body>
              
            
!

CSS

              
                :root {
  --accent-colour: ghostwhite;
}

body {
  background-color: #212326; /* Light black. */
  color: WhiteSmoke;
  font-family: Helvetica, Arial, san-serif;
  font-size: 18px;
  padding: 1% 5%;
}

h1, h2, h3 {
  font-weight: normal;
}

header {
  padding: 1%;
  border: 2px solid var(--accent-colour);
}

section {
  width: 95%;
}

@media screen and (min-width: 1024px) {
  section {
    width: 75%;
  }
}

mark {
  padding: 0.2% 1%;
}

footer {
  margin-top: 15%;
  border-top: 2px solid var(--accent-colour);
}
              
            
!

JS

              
                /*
 * Override the logo link for mobile.
 */

// Breakpoints
const mobBreak = '767.998px';

// Create the query list.
const mediaQueryList = window.matchMedia('(max-width: ' + mobBreak + ')');

// Define a callback function for the event listener.
function handleWindowSizeChange(mql) {

  let link = document.querySelector(".site-logo-img a");
  let img = document.querySelector(".site-logo-img a img");
  
  // Test the media query.
  if (mql.matches) {
    link.setAttribute("href", "https://caughtmyeye.cc");
    img.setAttribute("src", "https://marklchaves.files.wordpress.com/2020/03/cme-logo-white-clear-512x512-1.png");
    img.setAttribute("title", "Caught My Eye");
  } else {
    link.setAttribute("href", "https://balistreetphotographer.com");
    img.setAttribute("src", "https://balistreetphotographer.files.wordpress.com/2019/02/balistreetphotographer-logo-2-slashes-65.png");
    img.setAttribute("title", "Bali Street Photographer");
  }

}

// Run the window size change handler once.
handleWindowSizeChange(mediaQueryList);

// Add the callback function as a listener to the query list.
mediaQueryList.addListener(handleWindowSizeChange);

              
            
!
999px

Console