1

Is there a way to change parent width when ONLY input is target, not button.

I have tried :focus-within it works perfectly but when I click on button it also changes width because its within parent.

I also tried setting pointer-events: none on button.

What I want: When I first click on button don't resize parent width, only when input is in target, or only when I start typing, whatever.

I also tried with :placeholder-shown

.search-wrapper {
  position: relative;
  width:40%;
  transition: width .5s ease-in;
}

.search-input {
  border: 2px solid blue;
  width: 100%;
  height:40px;
}

.search-button {
  position: absolute;
  top:50%;
  right: 0;
  transform: translateY(-50%);
}

/*Make this to work*/
.search-wrapper:focus-within {
  width: 60%;
}
<div class="search-wrapper">
  <input class="search-input" type="text" placeholder="search ....">
  <button class="search-button">
    Button
  </button>
</div>

2

1 Answer 1

1

You can achieve this by doing following tweaks. Although not the exact solution you are searching for since there is no parent selector to style parent based on child selector but it may help you out there.

.search-wrapper { position: relative; width:60%; transition: width .5s ease-in; } .search-input { border: 2px solid blue; width: 100%; height:40px; } 
.search-button { 
display:inline-block;
position:relative;
left: -55px;
top: 9px;
transform: translateY(-50%); } /*Make this to work*/ 
.input-wrapper{ width: 50%;
display:inline-block;
transition: width .5s ease-in;}
.input-wrapper:focus-within { width: 70%; }
<div class="search-wrapper">
  <div class="input-wrapper">
    <input class="search-input" type="text" placeholder="search       ....">
  </div>
  <button class="search-button">
    Button
  </button>
</div>

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

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.