我的盒子向右扩展,如何让它向左扩展?
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
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;
}
input[type=text]:focus {
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<form>
<input type="text" name="search" placeholder="Search..">
</form>Run Code Online (Sandbox Code Playgroud)
squ*_*age 10
只需将其对齐到其容器元素的右侧即可.将display属性更改为block并将右边距和左边距设置为0和auto,或将其保留为内联元素并应用于text-align: right容器块.
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
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;
}
input[type=text]:focus {
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<form>
<input type="text" name="search" placeholder="Search..">
</form>Run Code Online (Sandbox Code Playgroud)