Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· openaiHugging Face Suzhen/CodeChat

I'm thinking on how to make this "<label for="switch">Energy saving nightmode…

  1. User

    I'm thinking on how to make this "Energy saving nightmode layer" not to cover things when flag is triggered and content shown... because this "nightmode layer" should cover the whole area when activated but it don't allow to select text behind it.

    .switch-container label:before { content: ""; position: absolute; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.3s ease-out; }

    .switch-container input[type="checkbox"]:checked ~ label:before { opacity: 1; }

    body, html { margin: 0; padding: 0; height: 100%; line-height: 1.6; background-color: #f7f7f7; }

    header { background-color: #4CAF50; color: #FFF; padding: 16px 0px 0px 0px; text-align: center; position: relative; }

    h1, h2, h3, h4, h5, h6 { margin: 0 auto; display: flex; justify-content: space-between; align-items: center; font-size: 18px; width: 90%; height: 1%;

    }

    .left, .right { position: relative; }

    .left::before, .right::before { content: ''; position: absolute; top: 50%; border-bottom: 1px dashed #FFF; width: 40%; }

    .left::before { right: 100%; margin-right: 20px; }

    .right::before { left: 100%; margin-left: 20px; }

    .flags-container { position: fixed; top: 0; left: 0; right: 0; --padding: 3px 0; background-color: white; display: flex; justify-content: center; align-items: center; --box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); z-index: 10; }

    .flag-radio { display: none; }

    .flag-label { cursor: pointer; margin: 0 10px; transition: 0.3s; opacity: 0.6; font-size: 24px; }

    .flag-label:hover { opacity: 1; }

    .language-option { position: run-in; top: 0; left: 0; right: 0; bottom: 0; display: none; justify-content: center; align-items: center; padding-top: 0px; /* language-option container text from top height */ }

    #english-flag:checked ~ #english, #hindi-flag:checked ~ #hindi, #hebrew-flag:checked ~ #hebrew, #chinese-flag:checked ~ #chinese, #french-flag:checked ~ #french, #spanish-flag:checked ~ #spanish { display: block; }

  2. Assistant

    To prevent the nightmode layer from blocking the selection of text behind it, you can add pointer-events: none; to the label:before CSS rule. This will prevent the layer from receiving any pointer events like mouse clicks.

    Replace the switch-container label:before CSS rule with the following:

    .switch-container label:before {
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.5);
      opacity: 0;
      transition: opacity 0.3s ease-out;
      pointer-events: none;
    }
    

    Here's the updated code with the pointer-events: none applied:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>CSS-only Multilingual eco-friendly site</title>
    <style>
      .switch-container input[type="checkbox"] {
    width: 18px;
    height: 18px;
    }
    
    .switch-container label:before {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease-out;
    pointer-events: none;
    }
    
    .switch-container input[type="checkbox"]:checked ~ label:before {
    opacity: 1;
    }
      
      body, html {
      margin: 0;
      padding: 0;
      height: 100%;
        line-height: 1.6;
    background-color: #f7f7f7;
    }
      
      header {
      background-color: #4CAF50;
      color: #FFF;
      padding: 16px 0px 0px 0px;
      text-align: center;
          position: relative;
    }
    
    h1, h2, h3, h4, h5, h6 {
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 18px;
        width: 90%;
      height: 1%;
    
    }
    
    .left, .right {
      position: relative;
    }
    
    .left::before, .right::before {
      content: '';
      position: absolute;
      top: 50%;
      border-bottom: 1px dashed #FFF;
      width: 40%;
    }
    
    .left::before {
      right: 100%;
      margin-right: 20px;
    }
    
    .right::before {
      left: 100%;
      margin-left: 20px;
    }
      
    .flags-container {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      --padding: 3px 0;
      background-color: white;
      display: flex;
      justify-content: center;
      align-items: center;
      --box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      z-index: 10;
    }
    
    .flag-radio {
      display: none;
    }
    
    .flag-label {
      cursor: pointer;
      margin: 0 10px;
      transition: 0.3s;
      opacity: 0.6;
      font-size: 24px;
    }
    
    .flag-label:hover {
      opacity: 1;
    }
    
    .language-option {
      position: run-in;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      display: none;
      justify-content: center;
      align-items: center;
      padding-top: 0px; /* language-option container text from top height */
    }
    
    #english-flag:checked ~ #english,
    #hindi-flag:checked ~ #hindi,
    #hebrew-flag:checked ~ #hebrew,
    #chinese-flag:checked ~ #chinese,
    #french-flag:checked ~ #french,
    #spanish-flag:checked ~ #spanish {
      display: block;
    }
    
    </style>
    </head>
    <body>  
      <input id="english-flag" type="radio" name="flags" class="flag-radio">
      <input id="hindi-flag" type="radio" name="flags" class="flag-radio">
      <input id="hebrew-flag" type="radio" name="flags" class="flag-radio">
      <input id="chinese-flag" type="radio" name="flags" class="flag-radio">
      <input id="french-flag" type="radio" name="flags" class="flag-radio">
      <input id="spanish-flag" type="radio" name="flags" class="flag-radio">
      
    <div class="flags-container">
      <label for="english-flag" class="flag-label">🇬🇧</label>  
      <label for="hindi-flag" class="flag-label">🇮🇳</label>
      <label for="hebrew-flag" class="flag-label">🇮🇱</label>
      <label for="chinese-flag" class="flag-label">🇨🇳</label>
      <label for="french-flag" class="flag-label">🇫🇷</label>
      <label for="spanish-flag" class="flag-label">🇪🇸</label>
    </div><br>
    
    <header>
      <h1>
        <span class="left">EcoWare</span>
        <span class="right">Earthwise</span>
      </h1>
    </header>
      <div class="switch-container">
        <input type="checkbox" id="switch">
      <label for="switch">Energy saving nightmode layer</label>
    </div>
      
    <div id="english" class="language-option">
    <p>english details going here</p>
    </div>
    
    <div id="hindi" class="language-option">
      <p>hindi details going here</p>
    </div>
    
    <div id="hebrew" class="language-option">
      <p>hebrew details going here</p>
    </div>
    
    <div id="chinese" class="language-option">
      <p>chinese details going here</p>
    </div>
    
    <div id="french" class="language-option">
      <p>french details going here</p>
    </div>
    
    <div id="spanish" class="language-option">
      <p>spanish details going here</p>
    </div>
    </body>
    </html>
    

    Now, you can select the text behind the nightmode layer when the flag is triggered and the content is shown.

  3. User

    I know that there’s many ways to implement nightmodes but I want this to be css+html only variant properly working and non-blocking any text selection. need it function that way: user clicks nightmode, whole page got covered in shade with selectable text behind it. when use unchecks this nightmode it disappears and still allow the user to select things as text and else behind it being transparent.

  4. Assistant

    To achieve this functionality using only CSS and HTML, you can apply a night mode by placing an additional element on top of the content and adjust its z-index property. Here's a working example:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>CSS-only Multilingual eco-friendly site</title>
    <style>
      .switch-container input[type="checkbox"] {
    width: 18px;
    height: 18px;
    }
    
    .nightmode-background {
      content: "";
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: rgba(0, 0, 0, 0.5);
      opacity: 0;
      z-index: -1; /* Keep shade below content */
      transition: opacity 0.3s ease-out;
      pointer-events: none; /* Allow text selection */
    }
    
    .switch-container input[type="checkbox"]:checked ~ .nightmode-background {
    opacity: 1;
    }
      
      body, html {
      margin: 0;
      padding: 0;
      height: 100%;
        line-height: 1.6;
    background-color: #f7f7f7;
    }
    
    
    html {
      position: relative; /* Add position:relative to html */
      z-index: 0; /* Set z-index of html to 0 */
    }
      
      header {
      background-color: #4CAF50;
      color: #FFF;
      padding: 16px 0px 0px 0px;
      text-align: center;
          position: relative;
    }
    
    h1, h2, h3, h4, h5, h6 {
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 18px;
        width: 90%;
      height: 1%;
    
    }
    
    .left, .right {
      position: relative;
    }
    
    .left::before, .right::before {
      content: '';
      position: absolute;
      top: 50%;
      border-bottom: 1px dashed #FFF;
      width: 40%;
    }
    
    .left::before {
      right: 100%;
      margin-right: 20px;
    }
    
    .right::before {
      left: 100%;
      margin-left: 20px;
    }
      
    .flags-container {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      --padding: 3px 0;
      background-color: white;
      display: flex;
      justify-content: center;
      align-items: center;
      --box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      z-index: 1;
    }
    
    .flag-radio {
      display: none;
    }
    
    .flag-label {
      cursor: pointer;
      margin: 0 10px;
      transition: 0.3s;
      opacity: 0.6;
      font-size: 24px;
    }
    
    .flag-label:hover {
      opacity: 1;
    }
    
    .language-option {
      position: run-in;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      display: none;
      justify-content: center;
      align-items: center;
      padding-top: 0px;
    }
    
    #english-flag:checked ~ #english,
    #hindi-flag:checked ~ #hindi,
    #hebrew-flag:checked ~ #hebrew,
    #chinese-flag:checked ~ #chinese,
    #french-flag:checked ~ #french,
    #spanish-flag:checked ~ #spanish {
      display: block;
    }
    
    </style>
    </head>
    <body>  
      <input id="english-flag" type="radio" name="flags" class="flag-radio">
      <input id="hindi-flag" type="radio" name="flags" class="flag-radio">
      <input id="hebrew-flag" type="radio" name="flags" class="flag-radio">
      <input id="chinese-flag" type="radio" name="flags" class="flag-radio">
      <input id="french-flag" type="radio" name="flags" class="flag-radio">
      <input id="spanish-flag" type="radio" name="flags" class="flag-radio">
      
    <div class="flags-container">
      <label for="english-flag" class="flag-label">🇬🇧</label>  
      <label for="hindi-flag" class="flag-label">🇮🇳</label>
      <label for="hebrew-flag" class="flag-label">🇮🇱</label>
      <label for="chinese-flag" class="flag-label">🇨🇳</label>
      <label for="french-flag" class="flag-label">🇫🇷</label>
      <label for="spanish-flag" class="flag-label">🇪🇸</label>
    </div><br>
    
    <header>
      <h1>
        <span class="left">EcoWare</span>
        <span class="right">Earthwise</span>
      </h1>
    </header>
      <div class="switch-container">
        <input type="checkbox" id="switch">
      <label for="switch">Energy saving nightmode layer</label>
    </div>
    
    <div class="nightmode-background"></div>
      
    <div id="english" class="language-option">
    <p>english details going here</p>
    </div>
    
    <div id="hindi" class="language-option">
      <p>hindi details going here</p>
    </div>
    
    <div id="hebrew" class="language-option">
      <p>hebrew details going here</p>
    </div>
    
    <div id="chinese" class="language-option">
      <p>chinese details going here</p>
    </div>
    
    <div id="french" class="language-option">
      <p>french details going here</p>
    </div>
    
    <div id="spanish" class="language-option">
      <p>spanish details going here</p>
    </div>
    </body>
    </html>
    

    This solution adds a new <div> element with the class nightmode-background and sets its z-index to -1. When the nightmode is enabled, textual content behind it is still selectable, and when disabled, the content remains accessible.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.