Adjusting arrow rotation based on select box activation using CSS

After completing the design aspect of creating a custom select box using CSS, I encountered some difficulties while attempting to add the "before" and "active" options. The goal was for the "arrow" and "menu" to change when the select box is active. However, when I added "active" to the class name in the browser, the arrow was supposed to rotate but nothing happened instead.
HTML

<div class="custom_select_box_1_index">

            <ul id="DefaultCategoryIndex"class="default_option_category_index">
              <li>
                <div class="option_allcategories">
                    <p>All Categories</p>
                    <i id="ArrowCategoryIndex" class="fa fa-chevron-up"></i>
                </div>
              </li>
            </ul>
            <ul id="OptionsCategoryIndex" class="select_option_category_index">
              <li>
                <div id="CategoryObjects" class="option objects">
                  <div class="icon"><i id="icon" class="fas fa-cube"></i></div>
                    <p class="category_text">Objects</p>
                </div>
              </li>

              <li>
                <div id="CategoryVehicules" class="option vehicules">
                  <div class="icon"><i id="icon" class="fas fa-car"></i></div>
                    <p class="category_text">Vehicles</p>
                </div>
              </li>

              <li>
                <div id="CategoryTechnology" class="option technology">
                  <div class="icon"><i id="icon" class="fas fa-mobile"></i></div>
                    <p class="category_text">Technology</p>
                </div>
              </li>

              <li>
                <div id="CategoryBooks" class="option books">
                  <div class="icon"><i id="icon" class="fas fa-book"></i></div>
                    <p class="category_text">Books</p>
                </div>
              </li>

              <li>
                <div id="CategoryGaming" class="option gaming">
                  <div class="icon"><i id="icon" class="fas fa-gamepad"></i></div>
                    <p class="category_text">Gaming</p>
                </div>
              </li>

              <li>
                <div id="CategoryOther" class="option other">
                  <div class="icon"><i id="icon" class="fas fa-ellipsis-h"></i></div>
                    <p class="category_text">Other...</p>
                </div>
              </li>
            </ul>
            </div>

CSS:

    .custom_select_box_1_index{
      font-family: Helvetica;
      font-size: 19px;
      color: var(--second-black);
      box-sizing: content-box;
      width: 250px;
      height: 50px;
    }
    
    .custom_select_box_1_index > ul li{
      list-style: none;
      }
    
    .custom_select_box_1_index .default_option_category_index:before{
      content: "";
      padding-top: 1px;
      padding-bottom: 1px;
      border-radius: 10px;
      background-color: var(--white);
      box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.05);
      cursor: pointer;
      transform: rotate(180deg);
      color: var(--black);
      position: absolute;
      margin-left: 170px;
      margin-top: -39px;
      cursor: pointer;
    }
    
    .custom_select_box_1_index .select_option_category_index{
      background-color: var(--white);
      border-radius: 10px;
      box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.05);
      z-index: 1;
      display: none
    }
    
    .select_option_category_index li{
      position: relative;
      margin-left: -38px;
      background-color: var(--white);
      border-radius: 10px;
      width: 230px;
      padding: 3px 8px;
      cursor: pointer;
    }
    
    .custom_select_box_1_index .select_option_category_index li:hover{
      background: var(--grey);
    }
    
    .category_text{
      position: relative;
      left: 30px;
    }
    
    .custom_select_box_1_index .option{
      display: flex;
      align-items: center;
    }
    
    .icon{
      display: flex;
      align-items: center;
      margin-left: 15px;
    }
    
    #icon{
      color: var(--black);
    }
    
    .custom_select_box_1_index:active .select_option_category_index{
      display: block;
    }
    
    .custom_select_box_1_index:active .default_option_category_index:before{
  transform: rotate(0deg);
}

I am aiming for the arrow to rotate back to 0 degrees when the select bar is active (avoiding the use of JavaScript).

Answer №1

One way to enhance your design is by utilizing the CSS adjacent sibling selector +:

.custom_select_box_1_index {
  font-family: Helvetica;
  font-size: 19px;
  color: var(--second-black);
  box-sizing: content-box;
  width: 250px;
  height: 50px;
}

.custom_select_box_1_index>ul li {
  list-style: none;
}

.custom_select_box_1_index .default_option_category_index:before {
  content: "";
  padding-top: 1px;
  padding-bottom: 1px;
  border-radius: 10px;
  background-color: var(--white);
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transform: rotate(180deg);
  color: var(--black);
  position: absolute;
  margin-left: 170px;
  margin-top: -39px;
  cursor: pointer;
}

.custom_select_box_1_index .select_option_category_index {
  background-color: var(--white);
  border-radius: 10px;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
  z-index: 1;
  display: none
}

.select_option_category_index li {
  position: relative;
  margin-left: -38px;
  background-color: var(--white);
  border-radius: 10px;
  width: 230px;
  padding: 3px 8px;
  cursor: pointer;
}

.custom_select_box_1_index .select_option_category_index li:hover {
  background: var(--grey);
}

.category_text {
  position: relative;
  left: 30px;
}

.custom_select_box_1_index .option {
  display: flex;
  align-items: center;
}

.icon {
  display: flex;
  align-items: center;
  margin-left: 15px;
}

#icon {
  color: var(--black);
}

.custom_select_box_1_index:active .select_option_category_index {
  display: block;
}

.custom_select_box_1_index:active .default_option_category_index:before {
  transform: rotate(90deg);
}

.option_allcategories p:active+.fa-chevron-up {
  transform: rotate(180deg);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="custom_select_box_1_index">

  <ul id="DefaultCategoryIndex" class="default_option_category_index">
    <li>
      <div class="option_allcategories">
        <p>All Categories</p>
        <i id="ArrowCategoryIndex" class="fa fa-chevron-up"></i>
      </div>
    </li>
  </ul>
  <ul id="OptionsCategoryIndex" class="select_option_category_index">
    <li>
      <div id="CategoryObjects" class="option objects">
        <div class="icon"><i id="icon" class="fas fa-cube"></i></div>
        <p class="category_text">Objects</p>
      </div>
    </li>

    <li>
      <div id="CategoryVehicules" class="option vehicules">
        <div class="icon"><i id="icon" class="fas fa-car"></i></div>
        <p class="category_text">Vehicles</p>
      </div>
    </li>

    <li>
      <div id="CategoryTechnology" class="option technology">
        <div class="icon"><i id="icon" class="fas fa-mobile"></i></div>
        <p class="category_text">Technology</p>
      </div>
    </li>

    <li>
      <div id="CategoryBooks" class="option books">
        <div class="icon"><i id="icon" class="fas fa-book"></i></div>
        <p class="category_text">Books</p>
      </div>
    </li>

    <li>
      <div id="CategoryGaming" class="option gaming">
        <div class="icon"><i id="icon" class="fas fa-gamepad"></i></div>
        <p class="category_text">Gaming</p>
      </div>
    </li>

    <li>
      <div id="CategoryOther" class="option other">
        <div class="icon"><i id="icon" class="fas fa-ellipsis-h"></i></div>
        <p class="category_text">Other...</p>
      </div>
    </li>
  </ul>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Launch a new window with the window.open() method and execute a function on the newly opened window

I am having trouble generating a barcode in a new window using the barcode generator script. Despite trying to use window.focus(), I can't get the barcode to appear in the new window. Any assistance on how to generate the barcode in a separate window ...

Adjusting the front size while utilizing the SideNav feature in Materialize

While creating a website using Symfony and Materialize, my client requested to have the menu displayed on the side. I followed the guidelines from and successfully implemented the side menu on the left. However, I am encountering two issues: The first ...

Tips for generating a JSON string with nested structure

Can someone assist me in generating a JSON based on the HTML elements provided below? { "AppName": "ERP", "ModuleDesc": [ { "Name": "Payroll", "AcCESSRIGHTS": [ { "Create": "Y", "Retrive": "Y", "U ...

Increment count using jQuery upon clicking

I've got an HTML snippet that looks like this: var useful, cool, funny; '<ul data-component-bound="true" class="voteset'+data[i]['review_id']+'">'+ '<li class="useful ufc-btn" id="1">'+ & ...

Employing jQuery to append a fresh hierarchy of parent divs

I'm just starting to learn jquery and I have a question about this scenario, <div id="parent"> <div class="child1">Child 1 Contents</div> <div class="child2">Child 2 Contents</div> </div> I am trying to crea ...

What's the best way to avoid global application of stylesheets imported for svelte carbon components?

My dilemma lies in wanting to utilize the DatePicker feature from carbon-components-svelte. Unfortunately, when I do so, the global application of styles from carbon-components ends up causing some conflicts with my own custom styles. As per the documenta ...

Identifying an Ajax Request in jQuery: A Guide to Detecting when a Page is Accessed by Ajax

Currently, I am developing a dynamic website using HTML/CSS/JavaScript without any server-side scripting. Some of the content on the site is loaded dynamically through AJAX requests from external HTML files. I want to restrict access to these HTML files ...

Receiving HTML codes through AJAX requests using .htaccess

retrieving html codes after ajax post request on the client side: $('#bgn').live('click',function(){ var data = {action:'today'}; $.post('inc/ajax-handler.php',data,function(response){ $('#result&a ...

What is the reason that padding is excluded from the height calculation of a display flex container?

.wrap { display: flex; flex-flow: column; } .row { display: flex; flex-flow: row wrap; background: yellow; } group label { padding: 1em; background: red; } <div class='wrap'> <h2> Header </h2> <div class=& ...

The latest div I inserted is not aligning to the bottom of the page

I'm facing an issue with my webpage design. I recently added a new div for the footer wrapper (class = main_foot), but it's stuck in the top left corner. Objective: Move the div beneath the div class="main_content" I have verified ...

Styling a PrimeFaces panelGrid within a data table using CSS

I am struggling to add a background color to a panelgrid within a datatable when a hover event occurs. Despite writing the necessary code and CSS, nothing seems to work. Any suggestions on how to address this issue? <p:dataTable id="movementsTable" var ...

JavaScript: Invoking a function within another function via an HTML document

I have a unique scenario where I have one function inside another and I am looking to call the inner function from an HTML document. <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="style.css"> ...

Can anyone help me determine the reason why my CSS is being displayed as struck-through in Google Chrome?

After successfully running my app on localhost, I encountered CSS issues when deploying it on Heroku. Some of the CSS appears as struck-through in Chrome. How can I identify what is overriding my styling? https://i.sstatic.net/U23fg.png ...

Card body alignment in the center (using Bootstrap)

I'm having a minor issue with aligning the columns in the card body to the center. In the image, you can see that it's slightly off to the left compared to the button. I've tried using various Bootstrap classes, but I haven't been able ...

Moving responsive table cell to a new line

Currently, I am faced with the challenge of embedding third-party content via dynamic means without any knowledge of Ajax or jQuery. My question is whether it's feasible to move a table cell onto a new line, essentially creating a new row. The embedd ...

Insert some padding above and below every line of text that is centered

I am looking to achieve a specific layout for my website. https://i.stack.imgur.com/dKT52.jpg Here is what I have attempted: <h2>Make search awesome using Open Source</h2> .banner .section_title h2 { font-family: "Oswald", Arial, sans- ...

In bootstrap, two overlapping DIVs are displayed below each other in mobile mode

I have a setup with two divs. The initial div consists of a header bar containing navigation links and a logo. Directly below is the second div, which features a hero image accompanied by some text. These divs are nested within a header tag, with the fir ...

Adaptable and scalable

Hello everyone, I could use some assistance in identifying where I may have made errors. Can you please help me with that? I am aiming to enhance the responsiveness of the following design for mobile devices. <section class="hero"> ...

What is the process of enabling scrolling on the main panel once scrolling on the sidebar has concluded?

How can I achieve a scrolling behavior similar to the one demonstrated here? When scrolling through the sidebar, I want it to continue scrolling until it reaches the end. After that, any further scrolling on the sidebar should scroll the main panel inste ...

Tips for handling Ajax urlencode in PHP

I'm facing an issue with a problem and need some assistance to resolve it. Currently, I am attempting to utilize Ajax urlencode in PHP, but the POST content is not being displayed by PHP as expected when HTML is sent directly to PHP. The following c ...