如何隐藏mui TextField标签?
P粉239164234
P粉239164234 2023-09-05 15:41:00
[CSS3讨论组]
<p>我正在开发一个 Nextjs 应用程序,我有一个用 mui 构建的仪表板导航栏,它包含一个通知 <code><IconButton></code> ,它打开通知框,后者是用常规 HTML 构建的和CSS。</p> <p><strong>dashboard-navbar.js:</strong></p> <pre class="brush:js;toolbar:false;">import NotificationBox from &quot;./notification-box/notification-box&quot;; //... export const DashboardNavbar = (props) =&gt; { const [down, setDown] = useState(false); const toggleDown = () =&gt; { setDown(!down); }; //... return ( &lt;&gt; &lt;NotificationBox down={down} notifications={props.notifications} /&gt; &lt;DashboardNavbarRoot&gt; &lt;div style={{ display: &quot;flex&quot;, gap: &quot;25px&quot; }}&gt; &lt;div style={{ transform: &quot;translate(0,18px)&quot; }}&gt; //... &lt;IconButton aria-label=&quot;more&quot; id=&quot;long-button&quot; onClick={toggleDown} style={{ transform: &quot;translate(20px,-15px)&quot; }} &gt; &lt;Badge badgeContent={0} color=&quot;primary&quot; variant=&quot;dot&quot;&gt; &lt;BellIcon fontSize=&quot;small&quot; /&gt; &lt;/Badge&gt; &lt;/IconButton&gt; &lt;/div&gt; //... &lt;/div&gt; &lt;/DashboardNavbarRoot&gt; &lt;/&gt; ); } </pre> <p><strong>notification-box.js:</strong></p> <pre class="brush:js;toolbar:false;">import classes from &quot;./notification-box.module.css&quot;; export const NotificationBox = ({ down, notifications }) =&gt; { var box = document.getElementById(&quot;box&quot;); if (down) { box.style.height = &quot;0px&quot;; box.style.opacity = 0; } else { box.style.height = &quot;510px&quot;; box.style.opacity = 1; } return ( &lt;div className={classes.notifiBox} id=&quot;box&quot;&gt; &lt;h2&gt; Notifications &lt;span&gt;{notifications.length}&lt;/span&gt; &lt;/h2&gt; {notifications.map((notification, index) =&gt; ( &lt;div key={index} className={classes.notifiItem}&gt; &lt;img src={notification.img} alt=&quot;img&quot; /&gt; &lt;div className={classes.text}&gt; &lt;h4&gt;{notification.title}&lt;/h4&gt; &lt;p&gt;{notification.content}&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; ))} &lt;/div&gt; ); }; </pre> <p><strong>notification-box.module.css:</strong></p> <pre class="brush:css;toolbar:false;"> .notifiBox { /* background-color: white; */ width: 300px; height: 0px; position: absolute; top: 63px; right: 35px; transition: 1s opacity, 250ms height; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); } .notifiItem { display: flex; border-bottom: 1px solid #eee; padding: 15px 5px; margin-bottom: 15px; cursor: pointer; } .notifiItem:hover { background-color: #eee; } .notifiBox h2 { font-size: 14px; padding: 10px; border-bottom: 1px solid #eee; color: #999; } .notifiBox h2 span { color: #f00; } .notifiItem img { display: block; width: 50px; margin-right: 10px; border-radius: 50%; } .notifiItem .text h4 { color: #777; font-size: 16px; margin-top: 10px; } .notifiItem .text p { color: #aaa; font-size: 12px; } </pre> <p><strong>结果:</strong>: </p> <p>我尝试将 <code>background-color</code> 属性添加到 <code>notifiBox</code> 类并将其设置为 <code>white</code>,得到了更好的结果,但仍然无法隐藏mui textField标签,无论如何都会显示:</p>
P粉239164234
P粉239164234

全部回复(1)
P粉022723606

Mui 文本字段的标签是z索引的。这就是它给人的印象是切断了输入边框线。

因此,如果您向 notifiBox 类添加更高的 z-index,它将隐藏标签。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号