skip to Main Content

I do turn off all the css attributes for a select item in Safari, but it will still not look at a plain select in in Safari, why?

enter image description here

enter image description here

I would have the first, I did try those, but not brings closer to the upper one:

style={{
    padding: '10px',
    boxSizing: 'border-box',
    fontSize: '15px',
    display: 'inline-block',
    appearance: 'auto',
}}

2

Answers


  1. I suggest you should create a custom dropdown to handle such request.

    /* Hide the default select element */
    select {
        opacity: 0;
        pointer-events: none;
    }
    
    /* Create a custom element to mimic the select */
    .custom-select {
        padding: 10px;
        box-sizing: border-box;
        font-size: 15px;
        display: inline-block;
        cursor: pointer; /* Indicate clickable behavior */
    
        /* Add custom styles here (e.g., background color, border) */
        background-color: #f5f5f5;
        border: 1px solid #ccc;
    }
    
    /* Style the dropdown options (requires additional HTML and JavaScript) */
    .custom-select-options {
        /* Styles for the dropdown list */
        display: none; /* Initially hidden */
        position: absolute; /* Positioned relative to the custom select */
        /* ... other styles for dropdown list */
    }
    

    This approach completely hides the default select element and creates a custom element (e.g., a <div>) with your desired styles. You’ll need additional HTML and JavaScript to manage the functionality of the dropdown list (opening, closing, selecting options).

    Login or Signup to reply.
  2. I will provide you with two approaches

    1. If you do not care about the drop down menu styling

    You can use appearance: none and set your styling that will work the same on all browsers

    like this

    .container {
      position: relative;
    }
    
    .arrow {
      background-color: black;
      border-radius: 99px;
      border: 1px solid black;
      height: 5px;
      width: 5px;
      position: absolute;
      right: 0.5rem;
      top: 50%;
      margin-top: -2px;
    }
    
    .sort_bar {
      cursor: pointer;
      appearance: none;
      width: 150px;
      /* border-radius: 8px; */
      background-color: #F0F2F2;
      border: 1px solid #D5D9D9;
      color: #0F1111;
      padding: 0.3rem 0.6rem;
      padding-right: 1rem;
      /*for caret*/
      font-size: 0.8rem;
      box-shadow: 0 2px 5px rgba(15, 17, 17, .15);
      -webkit-box-shadow: 0 2px 5px rgba(15, 17, 17, .15);
      -moz-box-shadow: 0 2px 5px rgba(15, 17, 17, .15);
    }
    <span class="container">
            <div class="arrow"></div>
            <select class="sort_bar">
                <option>Sort by: Featured</option>
            </select>
        </span>

    2. If you do care about the drop down menu styling
    you will need to create a drop down menu to hold your list, that can be toggled with javascript on click

    const select = document.querySelector(".sort_bar");
    select.addEventListener("click", () => {
      document.querySelector("ul").classList.toggle("hide");
    })
    
    const listItems = document.querySelector("ul");
    listItems.addEventListener("click", () => {
      document.querySelector("ul").classList.toggle("hide");
    })
    .arrow {
      background-color: black;
      border-radius: 99px;
      border: 1px solid black;
      height: 5px;
      width: 5px;
      position: absolute;
      right: 0.5rem;
      top: 50%;
      margin-top: -2px;
    }
    
    .isMenu {
      width: 150px;
      border-radius: 8px;
      background-color: #F0F2F2;
      border: 1px solid #D5D9D9;
      color: #0F1111;
      padding: 0.3rem 0.6rem;
      font-size: 0.8rem;
      box-shadow: 0 2px 5px rgba(15, 17, 17, .15);
      -webkit-box-shadow: 0 2px 5px rgba(15, 17, 17, .15);
      -moz-box-shadow: 0 2px 5px rgba(15, 17, 17, .15);
    }
    
    .sort_bar {
      position: relative;
      /*for caret*/
      appearance: none;
      cursor: pointer;
    }
    
    .allContainer {
      width: 150px;
      position: relative;
    }
    
    ul {
      list-style: none;
      background-color: #F0F2F2;
      border: 1px solid #D5D9D9;
      width: 150px;
      position: absolute;
      top: 1rem;
    }
    
    li {
      padding: 0.2rem 0;
      width: 100%;
      cursor: pointer;
    }
    
    li:not(.first) {
      border-top: 1px solid rgb(226, 226, 226);
    }
    
    .hide {
      display: none;
    }
    <span class="allContainer">
            <span class="container">
                <div class="sort_bar isMenu">
                Select
                    <div class="arrow"></div>
                </div>
            </span>
    
    <ul class="isMenu hide">
      <li class="first">Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
      <li>Item 4</li>
    </ul>
    </span>

    you can in both approaches insert a caret-icon to replace the dot of course. and toggle on it a class that will rotate it 180 degrees or something.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search