1

Trying to copy some front end mentor challenges I am right now styling input field. I want to do 3 things right now.

  1. I want to display the button inside the input field (even though I made it inside it is not perfect fit)
  2. display the error icon inside the input field.
  3. display the message "please provide a valid Email" below the textbox.

Right now it displays like this

enter image description here

.left button {
  background-image: linear-gradient(135deg, hsl(0, 80%, 86%), hsl(0, 74%, 74%));
  border: none;
  border-radius: 50px;
  width: 100px;
  margin-left: -104px;
  margin-top: -30px;
  height: 48px;
}

.left input {
  background-color: transparent;
  border: 1px solid hsl(0, 36%, 70%);
  border-radius: 15px;
  padding: 13px;
  width: 60%;
}

.left .error {}
<form action="#">
  <input type="text" placeholder="Email Address">
  <img src="https://stackoverflow.com/images/icon-error.svg" alt="" class="error">
  <button type="submit"><img src="https://stackoverflow.com/images/icon-arrow.svg " ></button>
  <small>please provide a valid Email</small>
</form>

1
  • Can you add the svg as a data-uri or upload it to imgur Commented Aug 27, 2022 at 11:36

2 Answers 2

0

They have different border radius - the button and the input. How could they be perfect match? Also different height. As for the "hint" line, just place it under in it's own div. I've tweaked a little your example using float:left and some adjustments. It's not perfect implementation but looks ok. Note height + padding = 48px.

.my-input-group {
  position: relative;
}

.left input {
  background-color: transparent;
  border: 1px solid hsl(0, 36%, 70%);
  border-radius: 15px;
  padding: 13px;
  padding-right: 113px;
  width: 60%;
  height: 22px;
  float: left;

}

.left button {
  background-image: linear-gradient(135deg, hsl(0, 80%, 86%), hsl(0, 74%, 74%));
  border: 1px solid transparent;
  border-radius: 15px;
  width: 100px;
  height: 48px;
  float: left;
  position: relative;
  left: -101px;
  top: 1px;
}

.left .error {}

my-input-group
<form action="#" class="left">
  <div class="my-input-group">
    <input type="text" placeholder="Email Address">

    <button type="submit"><img src="https://stackoverflow.com/images/icon-arrow.svg "></button>
    <div style="clear:both"></div>
    <div class="error">
      <small>please provide a valid Email</small>
    </div>
  </div>
</form>

<img src="https://stackoverflow.com/images/icon-error.svg" alt="" class="error">

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the solution.it worked. just a correction that i increased the height of inpult field from 22px to 50px.so it matches the height of button
0

Just a simple use of css display: flex will solve your problem, also I have made a container to store your input, button & image and gave that container a border so now it visually looks like they are inside the input box.

.container {
  border: 1px solid hsl(0, 36%, 70%);
  display: flex;
  height: 30px;
  background-color: transparent;
  border-radius: 15px;
  padding: 5px;
  width: 50%;
  justify-content: space-evenly;
  align-items: center;
}

button {
  background-image: linear-gradient(135deg, hsl(0, 80%, 86%), hsl(0, 74%, 74%));
  border: none;
  border-radius: 50px;
  width: 80px;
  height: calc(100% + 5px);
  cursor: pointer;
}

input {
  border: none;
  outline: none;
  height: 100%;
}

img {
  height: calc(100% + 5px);
}

button img {
  height: 100%;
  filter: invert();
}

small {
  margin-left: 10px;
}
<form action="#">
  <div class="container">
    <input type="text" placeholder="Email Address">
    <button type="submit">
    <img src="https://cdn-icons-png.flaticon.com/512/2989/2989988.png" >
    </button>
    <img src="https://cdn-icons-png.flaticon.com/512/7068/7068033.png" alt="image" class="error">
  </div>
  <small>please provide a valid Email</small>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.