Home > Blockchain >  How to rotate a background image (URL) statically without affecting the content within?
How to rotate a background image (URL) statically without affecting the content within?

Time:08-24

I have a custom drop down arrow for a element in my project. I'd like to rotate it 180 degrees, without flipping the actual content.

Static, not animated. I just want to have it flipped upside down, and I can't seem to figure out how to. Below is an example of the problem I'm trying to solve

.JForm__menustyle {
    height: min-content;
    font-weight: 700;
    font-size: 20px;
    padding: 5px 15px;
    border-radius: 18px;
    transition: background-color 0.2s ease, max-height 0.5s ease;
    cursor: pointer;
    overflow: hidden;
    user-select: none;
    border: none;
    appearance: none;
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 200px
}


.JForm-mobile {
    display: block;
    background: url("data:image/svg xml;utf8,<svg viewBox='0 0 140 140' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><g><path d='m121.3,34.6c-1.6-1.6-4.2-1.6-5.8,0l-51,51.1-51.1-51.1c-1.6-1.6-4.2-1.6-5.8,0-1.6,1.6-1.6,4.2 0,5.8l53.9,53.9c0.8,0.8 1.8,1.2 2.9,1.2 1,0 2.1-0.4 2.9-1.2l53.9-53.9c1.7-1.6 1.7-4.2 0.1-5.8z' fill='white'/></g></svg>") no-repeat;
    background-position: right 10px top 45%;
    background-size: 15px;
}
<select 
     
    style="background-color: #e07046; color: #FFD670
            " name="test" id="test"
>
    <option id="test" value="1">1</option>
    <option id="test" value="2">2</option>
    <option id="test" value="3">3</option>
</select>

CodePudding user response:

you probably can't rotate a background image. but you can rotate an image. i tried with pseudo-element but this is not allowed so you'll have to use another image element (and a wrapping div)

.JForm__menustyle {
  height: min-content;
  font-weight: 700;
  font-size: 20px;
  padding: 5px 15px;
  border-radius: 18px;
  transition: background-color 0.2s ease, max-height 0.5s ease;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  border: none;
  appearance: none;
  width: 200px;
}

.JForm-mobile {
  display: block;
  background-position: right 10px top 45%;
  background-size: 15px;
}

.my-select {
  position: relative;
  display: inline-block;
}

.arrow {
  position: absolute;
  right: 10px;
  top: 5px;
  transform: rotateX(180deg);
  pointer-events: none;
}
<div >
  <select  style="background-color: #e07046; color: #FFD670
            " name="test" id="test">
    <option id="test" value="1">1</option>
    <option id="test" value="2">2</option>
    <option id="test" value="3">3</option>
  </select>
  <img  src="data:image/svg xml;utf8,<svg viewBox='0 0 140 140' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><g><path d='m121.3,34.6c-1.6-1.6-4.2-1.6-5.8,0l-51,51.1-51.1-51.1c-1.6-1.6-4.2-1.6-5.8,0-1.6,1.6-1.6,4.2 0,5.8l53.9,53.9c0.8,0.8 1.8,1.2 2.9,1.2 1,0 2.1-0.4 2.9-1.2l53.9-53.9c1.7-1.6 1.7-4.2 0.1-5.8z' fill='white'/></g></svg>">
</div>

  • Related