I am trying to add an svg and another span element container an svg to the far right of an input however, with my current setting they are overlapping:
I have a structure like this:
/* How can I fix this such that the red will be aligned before the arrows? Currently my css is: */
svg,
#mySvg {
cursor: pointer;
position: absolute;
display: inline-block;
opacity: 0.8;
right: 0;
position: relative;
margin-left: -25px;
z-index: 9999 !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex align-items-center input-fields">
<input class="form-control textInput" type="text">
<svg></svg>
<span id="mySvg"></span>
</div>
2
Answers
When you using absolute position for elements you can not control overlaping them.
The only thing you can do is that add more right offset to one of them to prevent overlaping.
Example:
Here is a simple example that I managed to work on for this purpose. You can change your HTML like this:
and for the CSS part, you do like this:
I have wrapped both the icons with div that is positioned as absolute and it’s display property is set to flex.
Here is the example in full in CodePen. https://codepen.io/ahmadkarimi2009/pen/ExgpLbe
Note: I haven’t used Bootstrap for tackling this issue.