0

On a drop down menu I want to move one of the blocks. Is it possible to target this specific ul by using the span class name Riding and Racing? Without effecting any of the other menus.

<ul class="gm-links">
  <li class="gm-item gm-heading">
    <a class="gm-target js-no-transition">
      <span class="gm-text">Riding and Racing</span>
    </a>
  </li>
</ul>

CSS:

.gm-links ??? {
}
3
  • Are you looking for this: .gm-links span { } Commented Apr 30, 2021 at 4:08
  • @VorganHaze, I'm wanting to only add CSS to .gm-links which has this: <span class="gm-text">Riding and Racing</span>. I don't want the CSS to effect any other menu tied to .gm-links. Commented Apr 30, 2021 at 4:10
  • CSS cannot target the content of an element. The closest you can get in your example is: .gm-links .gm-text { }. This will target all gm-text classes inside gm-links classes. Commented Apr 30, 2021 at 4:20

2 Answers 2

1

You will need help from Javascript to achieve this. You can get the textContent of the element while running the nodeList or HTML collection through a loop.

const gmText = document.querySelectorAll('.gm-text')

gmText.forEach(li => li.textContent === 'Riding and Racing' ? li.classList.add('format') : '')
.format {
  background-color: black;
  color: white;
  border-radius: 5px;
  padding: 5px 8px;
  line-height: 2rem;
}

.format::after {
  content: ' - so much fun';
  color: #F76F76;
}
<ul class="gm-links">
  <li class="gm-item gm-heading">
    <a class="gm-target js-no-transition">
      <span class="gm-text">Riding and Racing</span>
    </a>
  </li>
  <li class="gm-item gm-heading">
    <a class="gm-target js-no-transition">
      <span class="gm-text">Camping and Fishing</span>
    </a>
  </li>
   <li class="gm-item gm-heading">
    <a class="gm-target js-no-transition">
      <span class="gm-text">Sleeping and Dreaming</span>
    </a>
  </li>
</ul>

Sign up to request clarification or add additional context in comments.

Comments

0

From your comments it seems that you want to add css to ul.gm-links. You can do that with jquery as below. As a sample adding new css class to expected .gm-links.

$(document).ready(function() {
    // get span under ul.gm-links with text containing "Riding and Racing"
    let span = $('ul.gm-links span:contains("Riding and Racing")');
    // get parent ul.gm-links for selected span.
    let ul = span.closest('ul.gm-links');
    // add class to ul
    ul.addClass("test");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.