用HTML的原生语法实现两个div子元素在同一行中排列

代码如下:

html 复制代码
<div id="level1" style="display: flex;">
    <div id="level2-1" style="display: inline-block; padding: 10px; border: 1px solid #ccc; margin: 5px;">
        这是第一个元素。
    </div>
    <div id="level2-2" style="display: inline-block; padding: 10px; border: 1px solid #ccc; margin: 5px;">
        这是第二个元素。
    </div>
</div>

当外层的父元素的背景设为黑色,字体为白色的情况下,效果如下:

当然可以把边框去掉,去掉边框的代码如下:

html 复制代码
<div id="level1" style="display: flex;">
    <div id="level2-1" style="display: inline-block; padding: 10px; margin: 5px;">
        这是第一个元素。
    </div>
    <div id="level2-2" style="display: inline-block; padding: 10px; margin: 5px;">
        这是第二个元素。
    </div>
</div>

当外层的父元素的背景设为黑色,字体为白色的情况下,效果如下:

相关推荐
科雷软件测试17 小时前
推荐几个常用的校验yaml、json、xml、md等多种文件格式的在线网站
xml·html·md·yaml
Serendipity-Solitude18 小时前
HTML 五子棋实现方法
前端·html
研☆香20 小时前
html css js文件开发规范
javascript·css·html
王五周八20 小时前
html转化为base64编码的pdf文件
前端·pdf·html
Serendipity-Solitude21 小时前
使用HTML创建井字棋
前端·html
Jinuss1 天前
HTML页面http-equiv=“refresh“自动刷新原理详解
http·html
沉默璇年2 天前
如何通过python脚本下载高德离线底图瓦片并使用?
javascript·python·html
BianHuanShiZhe2 天前
swift计算文本高度
前端·javascript·html
23级二本计科2 天前
前端 HTML + CSS + JavaScript
前端·css·html
VekiSon2 天前
综合项目实战——电子商城信息查询系统
linux·c语言·网络·http·html·tcp·sqlite3