我正在創建一個搜索條,它接受來自用戶的搜索條件。我插入了一個CSS轉換(它的寬度增加了點擊)。我面臨的問題是當我點擊提交按鈕時搜索欄的寬度減小。我不希望發生這種情況,搜索欄應保留其更改的寬度。 下面是HTML:如何控制css轉換?
<input type="text" placeholder=" search" id="search">
<button type="submit" id="submit" >submit </button>
</form>
這裏是CSS:
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid black;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url("http://icons.iconarchive.com/icons/ampeross/qetto-2/256/search-icon.png");
background-size:40px;
/*background-position: 10px 10px;*/
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
margin-left:7%;
}
input[type=text]:focus {
width: 75%;
}
這裏是鏈接到我的代碼,如果它有助於: https://codepen.io/ryoko1/pen/eRMYrg?editors=1111
這[教程](https://tympanus.net/codrops/2013/06/26/expanding-search-bar-deconstructed/)將幫助你很多瞭解並優化代碼概念...... – Momin