用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>

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

相关推荐
henry10101023 分钟前
通过GitHub Page服务免费部署静态Web网站
前端·html·github·html5
tod1132 天前
Redis 数据类型与 C++ 客户端实践指南(redis-plus-plus)
前端·c++·redis·bootstrap·html
henry1010102 天前
Deepseek辅助生成的HTML5网页版抄经典《弟子规》
前端·javascript·css·html·html5
想睡好2 天前
标签的ref属性
前端·javascript·html
henry1010102 天前
HTML5小游戏 - 数字消除 · 合并2048
前端·游戏·html·html5
杨超越luckly2 天前
HTML应用指南:利用GET请求获取中国邮政网点位置信息
前端·python·arcgis·html·php·数据可视化
Go_Zezhou2 天前
render网站保存历史记录错误解决
开发语言·git·python·html
CappuccinoRose2 天前
HTML语法学习文档(三)
前端·学习·html·html5·标签·实体字符
小九今天不码代码2 天前
HTML + CSS 实现鼠标悬停触发的全景动画效果
html·css动画·网页特效·前端交互·纯css效果·鼠标悬停动画·全景滑动效果
星火开发设计3 天前
类模板:实现通用数据结构的基础
java·开发语言·数据结构·c++·html·知识