HTML 中的 valign 与 text-align

发布于 2024-12-25 15:33:32 字数 797 浏览 7 评论 0原文

我无法通过以下代码找出 HTML 中 valign 与 text-align 之间的区别:

    <table width="500" border="0">
  <tr>
        <td colspan="2" style="background-color:#FFA500;">
   <h1>Main Title of Web Page</h1>
   </td>
      </tr>

  <tr valign="top">
      <td style="background-color:#FFD700;width:100px;text-align:top;">
      <b>Menu</b><br />
    HTML<br />
      CSS<br />
  JavaScript
     </td>
   <td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">
      Content goes here</td>
    </tr>

   <tr>
     <td colspan="2" style="background-color:#FFA500;text-align:center;">
     Copyright © 2012</td>
   </tr>
   </table>

I can't figure out the difference between valign vs text-align in HTML in context with the following code:

    <table width="500" border="0">
  <tr>
        <td colspan="2" style="background-color:#FFA500;">
   <h1>Main Title of Web Page</h1>
   </td>
      </tr>

  <tr valign="top">
      <td style="background-color:#FFD700;width:100px;text-align:top;">
      <b>Menu</b><br />
    HTML<br />
      CSS<br />
  JavaScript
     </td>
   <td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">
      Content goes here</td>
    </tr>

   <tr>
     <td colspan="2" style="background-color:#FFA500;text-align:center;">
     Copyright © 2012</td>
   </tr>
   </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

无所的.畏惧 2025-01-01 15:33:32

valign(html属性)相当于css中的vertical-align

align(html属性)相当于text-align

html 属性版本已弃用,取而代之的是 css

vertical-align 将块元素(例如 div)垂直放置在其他块元素内

< code>text-align 定位内联元素(例如span,默认文本)水平位于块元素内

valign (html attribute) is equivalent of vertical-align in css

align (html attribute) is equivalent of text-align in css

html attribute versions are deprecated in favour of css

vertical-align positions block elements (e.g. div) vertically inside other block elements

text-align positions inline elements (e.g. span, default text) inside block elements horizontally

黑寡妇 2025-01-01 15:33:32

text-align 的正确值是 left|right|center|justify,因为它是水平的,而 valign 是垂直的,所以它是 top|middle|bottom|baseline。您还可以对两者使用继承。

另外,text-align 是 css,而 valign 是 html 属性。我认为align是html相当于text-align,而vertical-align相当于valign。

http://www.w3schools.com/cssref/pr_text_text-align.asp

http://www.w3schools.com/tags/att_td_valign.asp

如果您将文本对齐切换为“底部”,您会发现它不会移动,因为底部没有移动对于文本对齐有效。默认(我认为)是顶部。如果你输入“vertical-align:bottom”,它将到达底部。

只需进行简单的网络搜索即可找到这些答案...

The proper values for text-align are left|right|center|justify as it is horizontal, while the valign is vertical so it's top|middle|bottom|baseline. You can also use inherit on both.

Plus, text-align is css while valign is an html attribute. I think align is the html equivalent to text-align, while vertical-align is equivalent to valign.

http://www.w3schools.com/cssref/pr_text_text-align.asp

http://www.w3schools.com/tags/att_td_valign.asp

If you switch text-align to "bottom", you'll notice it doesn't move as bottom isn't valid for text-align. The default (i think) is top. If you put "vertical-align:bottom" though, it will go to the bottom.

A simple web search will find you these answers...

迷雾森÷林ヴ 2025-01-01 15:33:32

text-align 用于 CSS 和样式中的水平对齐,其中 vertical-align 用于垂直对齐。然后我们有 align="center" valign="top" 是 HTML 中用于相同目的的相应属性。

详细了解 HTMLCSS,这是我的建议。

The text-align is for horizontal aligning in CSS and styles, where vertical-align is for vertical alignment. Then we have align="center" valign="top" are the correspondant attributes in the HTML for the same purpose.

Read more about HTML and CSS, this is my suggestion.

温暖的光 2025-01-01 15:33:32

valign 会垂直对齐所有元素,而 text-align 专门针对文本。

valign will vertically align all elements, whereas text-align is specifically for text.

浸婚纱 2025-01-01 15:33:32

不支持 text-aligntop 值(left | center | right | justify | start | end)..所以它不会做你期望的事情...

文本对齐 MDN docs 属性用于水平对齐。

您在示例中看到的垂直对齐是由于 tr 元素的 valign="top" 属性造成的。

http://jsfiddle.net/gaby/PvtAU 查看没有 valign 的示例/ 你会注意到这一点。

valign 仅对 tr 有效 < super>MDN 文档td MDN docs 元素,在 html 4.01 中已弃用,在 html5 中已过时。
使用 vertical-align MDN 文档< /a> 相反..

A value of top for text-align is not supported (only left | center | right | justify | start | end).. so it does not do what you expect it ...

The text-align MDN docs property is for horizontal align.

The vertical align you witness in your example is because of the valign="top" property of the tr element.

Look at your example without the valign at http://jsfiddle.net/gaby/PvtAU/ and you will notice this.

valign is only valid for tr MDN docs and td MDN docs elements, and is deprecated in html 4.01 and obsolete in html5.
Use vertical-align MDN docs instead..

萌无敌 2025-01-01 15:33:32

text-align: top; 的值不是有效的 css,text-align 是水平的而不是垂直的。这就是 valign="top" 发挥作用的地方。输入 valign="left" 无效,与 text-align: top; 无效相同。 valign 是垂直的。

The value of text-align: top; is not valid css, text-align is horizontal not vertical. This is where valign="top" comes into play. Putting in valign="left" is not valid the same as text-align: top; is not valid. valign is vertical.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文