skip to Main Content

I’m trying to modify this code so that the actions button has a little padding that does not highlight on hover below the button.

I was trying to use my action-blank class by sandwiching the button between 2 blank lines but the blank lines were getting highlighted.

Ideally, the ACTIONS button is present on all sections without needing to click them to appear

.vertical-menu {
  width: 100%;
  height: 150px;
  position: relative;
}

.trend-button:hover {
  background: linear-gradient(to right, transparent 2.5%, #f0f0f0 2.5%, #f0f0f0 97.5%, transparent 97.5%);
  align-items: center;
}


/* Exclude blank line and blank element from hover effect */

.button-label-line>div:hover,
.actions-container>.action-blank {
  background: none;
}


/* Style for the blank element */

.action-blank {
  height: 0.5em;
  /* Adjust height as needed */
}

.button-label-divider {
  height: 5px;
}

.actions-container>.action-blank {
  background: none;
}


/* Style for the blank element */

.action-blank {
  height: 0.5em;
  /* Adjust height as needed */
}

.vertical-menu input[type="radio"] {
  position: absolute;
  left: -9999px;
}

.vertical-menu label {
  background-color: #eee;
  color: black;
  display: block;
  padding: 12px;
  height: 100%;
  margin: 0;
  text-decoration: none;
  cursor: pointer;
}

.vertical-menu label:hover {
  background-color: #ccc;
}

.vertical-menu input[type="radio"]:checked+label {
  background-color: #04AA6D;
  color: white;
}

.vertical-menu .trend-button {
  display: none;
  background-color: #04AA6D;
}

.vertical-menu input[type="radio"]:checked+label+.trend-button {
  display: block;
  text-align: center;
  margin-top: -1px;
  /* Adjust the margin to remove white space */
}

.vertical-menu input[type="radio"]:checked+label+.trend-button button {
  width: 100%;
  background-color: #04AA6D;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
}
<div class="vertical-menu" id="menu">
  <input type="radio" id="option1" name="menu-option" checked>
  <label for="option1">#H1#<div class="subtitle">#S1#</div></label>
  <div class="trend-button">
    #ACTIONS#
  </div>

  <input type="radio" id="option2" name="menu-option">
  <label for="option2">#H2#<div class="subtitle">#S2#</div></label>
  <div class="trend-button">
    #ACTIONS#
  </div>

  <input type="radio" id="option3" name="menu-option">
  <label for="option3">#H3#<div class="subtitle">#S3#</div></label>
  <div class="trend-button">
    #ACTIONS#
  </div>

  <input type="radio" id="option4" name="menu-option">
  <label for="option4">#H4#<div class="subtitle">#S4#</div></label>
  <div class="trend-button">
    #ACTIONS#
  </div>
</div>

For context something like this

When one section is selected:
enter image description here
When hovering on button:
enter image description here

2

Answers


  1. I’ve made some modifications to your code. Perhaps these changes could be beneficial for you. You can find the updated code here: https://play.tailwindcss.com/moSic3xHZM.

    Login or Signup to reply.
  2. Adjust the bottom property for more space below the button.

    document.addEventListener("DOMContentLoaded", () => {
    
    const qs = (el) => document.querySelector(el);
    const qsAll = (el) => document.querySelectorAll(el);
    
    qsAll(".section").forEach(($section) => {
      $section.addEventListener("click", (e) => {
        qs(".section.selected").classList.remove("selected");
        e.target.closest('.section').classList.add("selected");
      });
    });
    
    
    });
    .section {
      padding-bottom: 40px;
    }
    
    .section:hover {
      background: #eee;
      cursor: pointer;
    }
    .section:hover button.actions {
      background: #eee;
    }
    
    .section.selected {
      background: #04AA6D;
    }
    
    button.actions {
      position: absolute;
      bottom: 15px;
      left: 10px;
      right: 10px;
      border: none;
      background: #fff;
    }
    
    button.actions:hover {
      background: #fff !important;
    }
    
    
    
    .section.selected button.actions {
      background: #04AA6D;
    }
    
    .relative {
      position: relative;
    }
    <div class="container">
      <div class="section relative selected">
        <div class="">#H1#</div>
        <div class="">#S1#</div>
        <button class="actions">#ACTIONS#</button>
      </div>
       <div class="section relative">
        <div class="">#H2#</div>
        <div class="">#S2#</div>
        <button class="actions">#ACTIONS#</button>
      </div>
       <div class="section relative">
        <div class="">#H3#</div>
        <div class="">#S3#</div>
        <button class="actions">#ACTIONS#</button>
      </div>
       <div class="section relative">
        <div class="">#H4#</div>
        <div class="">#S4#</div>
        <button class="actions">#ACTIONS#</button>
      </div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search