如何解决顺风css的样式问题?
谁能告诉我为什么searchbox input
和autocomplete条目ul
的大小不同?这是我的代码,两个类都是w-full。
<div className="sticky top-20 z-40 w-full px-1 sm:p-5 md:p-10">
<div className="gap-1">
<form onSubmit={handleSearchClick} className="">
{/* <SearchDropdown /> */}
<input
enterKeyHint="search"
type="search"
className={`w-full bg-white px-4 py-2 text-gray-700 ${
autoResults.length > 0
? "rounded-tl-3xl rounded-tr-3xl"
: "rounded-full"
} z-10 border focus:border-blue-400 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-40`}
placeholder="🔍 Search for products"
onChange={handleInput}
onClick={() => {
setAutoResults(searchInput.length > 0 ? trackResults : []);
}}
value={searchInput}
/>
{autoResults.length > 0 && (
<ul className="absolute w-full rounded-bl-3xl rounded-br-3xl border-r border-l border-b bg-white focus:border-blue-400 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-40">
{autoResults.map((result: any) => {
return (
<li
className=" cursor-pointer border-gray-300 p-2 px-4 text-gray-700 hover:bg-blue-400"
key={result._id}
// onClick={() => setSearchInput(result._id)}
onClick={() => handleSelect(result._id)}
// value={result._id}
>
{result._id}
</li>
);
})}
</ul>
)}
</form>
</div>
</div>
1条答案
按热度按时间yhived7q1#
要将
ul
与overflowing
分开,请尝试将relative
类添加到form
容器中,以便相对于form
放置ul
。顺便说一句,也许可以考虑在
ul
中添加一个overflow-hidden
,以便其背景色包含在圆形边框中。下面是一个最小化的示例,没有任何功能,只有样式:stackblitz
示例:
希望这会有帮助。