Home > Net >  How to place element in select?
How to place element in select?

Time:12-29

Trying to insert SVG image in select section like this: In FIGMA

Can't understand what is the mistake in my code.

.contacts__select {
  margin: 0;
  margin-top: 95px;
  margin-left: 64px;
  position: relative;
  height: 50px;
  width: 450px;
  background-color: #D6E7D2;
  border: none;
  box-shadow: 0px 4px 4px 0px #00000040;
  align-self: flex-start;

  -webkit-appearance: none;
  -moz-appearance: none;
  -ms-appearance: none;
  appearance: none;

  font-family: 'Inter';
  color: #717171;
  font-size: 20px;
  font-weight: 400;
  line-height: 40px;
  letter-spacing: 0.05em;
  text-align: left;
}

.contacts__select::after {
  position: absolute;
  content: '';
  background-image: url('./assets/img/svg/accordion_btn.svg');
  bottom: 0;
  right: 0;
}

I tried different combination if left/right top/bottom. Doesn't work anyway. my version

CodePudding user response:

You can do this with CSS Flex, its very powerful.

All we do is place the title and the SVG (children) within a display flex (parent) and then tell the children to align centre, and space them between each other

.dropdown {
    display: flex;
    justify-content: space-between;
    align-items: center;

    background-color: #d6e7d2;
    box-shadow: 0px 4px 4px 0px #00000040;
    height: 50px;
    padding: 0 16px;
}

.dropdown__title {
    font-family: 'Inter';
        color: #717171;
    font-size: 20px;
    font-weight: 400;
}

.dropdown__icon {
  width: 24px;
  height: 24px;
}
<div >
    <span >City</span>
    <span >
        <img src="/assets/img/svg/accordion_btn.svg" alt="icon">
    </span>
</div>

CodePudding user response:

You have to provide dimensions for the pseudo-element, e.g.

width: 20px;
height: 20px;

Since the content is empty, the dimensions are 0 by default.

CodePudding user response:

  .custom-select {
    position: relative;
    border: 1px solid #ccc;
    overflow: hidden;
    background-color: #fff;
  }

  .custom-select:before {
    content: "";
    width: 34px;
    height: 34px;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    background: url('data:image/svg xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"  viewBox="0 0 16 16"><path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z"/></svg>')
      no-repeat center;
  }

  .custom-select select {
    padding: 10px;
    width: 100%;
    border: none;
    box-shadow: none;
    appearance: none;
  }
<div >
  <select>
    <option value="">Select an option</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
  </select>
</div>

  • Related