div 表格布局
内容 (Contents)
介绍 (Introduction)
This is a straightforward article demonstrating some very basic UI layout concepts using either DIV
or TABLE
elements. The impetus for this is simply that I often struggle with figuring out the nuances of how to position elements in the UI so I get both the look and behavior that I want. By look, I mean the positioning of sections of the UI and the elements within those sections, and by behavior, I mean how the UI behaves when the browser window is resized. I'm not covering things like device screen sizes or replacing a menu bar with a "triple bar" dropdown -- there are component libraries like Bootstrap to handle that.
这是一篇简单的文章,演示了使用DIV
或TABLE
元素的一些非常基本的UI布局概念。 这样做的动力很简单,就是我经常要弄清楚如何在UI中放置元素的细微差别,以便获得所需的外观和行为。 通过外观,我是指UI的各个部分的位置以及这些部分中的元素,并且通过行为,是指调整浏览器窗口大小时UI的行为。 我没有介绍设备屏幕尺寸或用“三栏”下拉菜单替换菜单栏的问题,而是通过Bootstrap这样的组件库来处理。
All of these examples can be coded in Visual Code and viewed side-by-side with Quick HTML Previewer, which of all the HTML preview plugins that I looked at is the only one that I found actually works.
所有这些示例都可以用Visual Code编码,并可以与Quick HTML Previewer并排查看,在我查看的所有HTML预览插件中,我发现这是唯一可以实际使用的插件。
基本布局 (Basic Layout )
Let's start with something basic -- two inline div
s. The HTML:
让我们从基本的东西开始-两个内联div
。 HTML:
<p>Two inline divs:</p>
<div class='border1 quarter inline'>Div 1</div>
<div class='border1 quarter inline m10'>Div 2</div>
And the CSS I'm using to define the border, width, margin, and inline styles:
我用来定义边框,宽度,边距和内联样式CSS:
.border1 {
border-style:solid;
border-width: 1px;
}
.quarter {
width: 25%;
}
.inline {
display: inline-block;
}
.m10 {
margin-left:10px;
}
Yielding:
屈服: