html 清除flex,css如何重置flex项的'display'属性_css3_开发99编程知识库

我試圖將基於表和JS的舊布局轉換為新的Flexbox,並通過保持舊瀏覽器的表向後兼容。

問題是,沒有 display:flex-item 可以替代舊的display:table-cell 樣式。

我嘗試了不同的定義,比如 display:inherit,display:initial,但無法重置顯示定義以正常工作。

...
username, email, etc.

/* CSS Table Layout */

.layout { display: table; width: 100%; }

.layout>. picture { display: table-cell; width: 30%; }

.layout>. details { display: table-cell; width: auto; }

/* CSS Flexbox - ignored by browsers that does not support it */

/* just an example - should use all versions for best compatibility */

.layout { display: flex; }

.layout>. picture { display:???; flex: 0 1 30%; }

.layout>. details { display:???; flex: 1 1 auto; }

為 .details 顯示的任何內容都不能作為flex項目使用,並且不會增加,以填充剩餘的空間。

如何在不使用JS檢測瀏覽器版本和 switch 樣式的情況下重寫這一?

不過,我已經嘗試了搜索解決方案,但是大部分結果只是關於Flexbox的一般文章,只有類似的是 ,這隻是不解決逆向問題。

更新 1: 這是一個 JSFiddle演示插件,它是一個純Flexbox和Flexbox結合的table 布局。 如果調整結果窗口的大小,則純布局將與合併 table 和Flexbox的底部的布局不同。 注意:在 Chrome 中這個工作正常,在 Firefox 。IE 。Safari等中嘗試。

更新 2: Safari可以正確使用前綴定義。 更新JSFiddle演示程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以给你提供一个完整的餐饮网页的代码示例,包括登录注册页、首页、列表页和详情页。 HTML代码: ```html <!DOCTYPE html> <html> <head> <title>餐饮网页</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> </head> <body> <header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">菜单</a></li> <li><a href="#">关于我们</a></li> <li><a href="#">联系我们</a></li> <li><a href="#">登录</a></li> </ul> </nav> </header> <main> <section id="login"> <h2>登录</h2> <form> <label for="username">用户名:</label> <input type="text" id="username" name="username" required><br> <label for="password">密码:</label> <input type="password" id="password" name="password" required><br> <input type="submit" value="登录"> </form> <p>还没有账号?<a href="#register">点击注册</a></p> </section> <section id="register"> <h2>注册</h2> <form> <label for="username">用户名:</label> <input type="text" id="username" name="username" required><br> <label for="password">密码:</label> <input type="password" id="password" name="password" required><br> <label for="confirm_password">确认密码:</label> <input type="password" id="confirm_password" name="confirm_password" required><br> <input type="submit" value="注册"> </form> <p>已有账号?<a href="#login">点击登录</a></p> </section> <section id="home"> <h2>欢迎来到餐饮网站</h2> <div class="image-container"> <img src="images/food1.jpg"> <img src="images/food2.jpg"> <img src="images/food3.jpg"> </div> <p>这里有各种美食等你来品尝,快来看看吧!</p> </section> <section id="menu"> <h2>菜单</h2> <table> <thead> <tr> <th>名称</th> <th>价格</th> <th>描述</th> </tr> </thead> <tbody> <tr> <td>红烧肉</td> <td>30元</td> <td>传统的家常菜,口味浓郁。</td> </tr> <tr> <td>麻婆豆腐</td> <td>20元</td> <td>麻辣鲜香,回味无穷。</td> </tr> <tr> <td>水煮鱼</td> <td>40元</td> <td>鲜嫩可口,汤汁浓郁。</td> </tr> </tbody> </table> </section> <section id="details"> <h2>红烧肉</h2> <div class="dish-container"> <img src="images/food1.jpg"> <p>价格:30元</p> <p>描述:传统的家常菜,口味浓郁。</p> </div> </section> </main> <footer> <p>版权所有 © 2021 餐饮网页</p> </footer> <script src="script.js"></script> </body> </html> ``` CSS代码: ```css * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: Arial, Helvetica, sans-serif; font-size: 16px; line-height: 1.5; color: #333; } header { background-color: #333; color: #fff; padding: 10px; } nav ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: flex-end; } nav li { margin: 0 10px; } nav a { color: #fff; text-decoration: none; } main { max-width: 1200px; margin: 0 auto; padding: 20px; } section { margin-bottom: 20px; } h2 { font-size: 24px; margin-bottom: 10px; } form label { display: block; margin-bottom: 5px; } form input[type="text"], form input[type="password"] { width: 100%; padding: 5px; margin-bottom: 10px; border: none; border-radius: 5px; } form input[type="submit"] { background-color: #333; color: #fff; padding: 5px 10px; border: none; border-radius: 5px; cursor: pointer; } a { color: #333; text-decoration: none; } .image-container { display: flex; justify-content: space-between; margin-bottom: 10px; } .image-container img { width: 30%; border-radius: 5px; } table { width: 100%; border-collapse: collapse; margin-bottom: 10px; } th, td { padding: 5px; text-align: left; border: 1px solid #ddd; } th { background-color: #f2f2f2; } .dish-container { display: flex; justify-content: space-between; margin-bottom: 10px; } .dish-container img { width: 50%; border-radius: 5px; } @media (max-width: 768px) { nav ul { flex-direction: column; align-items: center; } nav li { margin: 10px 0; } .image-container { flex-direction: column; } .image-container img { width: 100%; margin-bottom: 10px; } .dish-container { flex-direction: column; } .dish-container img { width: 100%; margin-bottom: 10px; } } ``` JavaScript代码: ```javascript // 在这里编写JavaScript代码 // 可以使用数组、基础函数、对象、正则表达式等相关知识来实现一些交互效果或数据处理等功能 // 比如表单验证、图片轮播、数据存储等功能 ``` 在以上的代码中,我使用了HTMLCSS来创建了一个简单的餐饮网页,并在JavaScript代码中留下了一些空白来让你自己实现一些交互效果或数据处理等功能。你可以使用数组、基础函数、对象、正则表达式等相关知识来完成这些功能。同时,你也可以使用一些库或框架来加速开发,比如jQuery、React等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值