我正在尝试在一行中创建一个搜索栏以及一个页眉。当我专注于搜索栏时,我希望它展开全宽并隐藏标题。我可以展开搜索栏,但不能隐藏标题。我不知道什么是错的。这里的代码如何扩展搜索栏并同时隐藏其他元素?
<! DOCTYPE html>
<html>
<head>
<style>
.header, div, .search{
display: inline;
}
.search{
width: 150px;
transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
}
.search:focus{
width: 100%;
}
.search:focus .header{
display: none;
}
</style>
</head>
<body>
<h1 class="header">myWebsite</h1>
<div>
<input type="text" class="search" name="search" placeholder="search...">
</div>
</body>
</html>
所以请帮助我。
答案就在JavaScript中。似乎只有CSS不能实现它。我在onblur上使用show(),并在onclick上隐藏()。 –