是否可以使带有 inline-block 的 DIV 的行为与带有align=left 的IMG 完全相同?

发布于 2024-12-22 17:17:46 字数 663 浏览 1 评论 0原文

在下面的示例中,使 DIV inline-block 关闭 valign 效果。是否可以像下一行的 IMG 一样将其带回来?

<table border="1">
<tr>
    <td height="50" valign="top">

        <div style="display:inline-block; width:65px; height:40px; background-color: yellow; text-align: left;"></div>
        <input type="button" value="button">

         Some text

    </td>
</tr>

<tr>
    <td height="50" valign="top">

        <img src="images/spacer.gif" width="65" height="40" align="left" border="1">
        <input type="button" value="button">

         Some text

    </td>
</tr>

</table>

In the following example making DIV inline-block turns off valign effect. Is it possible to bring it back as with IMG in next row?

<table border="1">
<tr>
    <td height="50" valign="top">

        <div style="display:inline-block; width:65px; height:40px; background-color: yellow; text-align: left;"></div>
        <input type="button" value="button">

         Some text

    </td>
</tr>

<tr>
    <td height="50" valign="top">

        <img src="images/spacer.gif" width="65" height="40" align="left" border="1">
        <input type="button" value="button">

         Some text

    </td>
</tr>

</table>

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

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

发布评论

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

评论(2

ぺ禁宫浮华殁 2024-12-29 17:17:46

vertical-align: top; 添加到

中。

<div style="display:inline-block; width:65px; height:40px; background-color: yellow; text-align: left;border: 1px solid black;vertical-align:top;"></div>

演示:http://jsfiddle.net/ThinkingStiff/xvpYF/

HTML:

<table border="1">
<tr>
<td height="50" valign="top">
    <div style="display:inline-block; width:65px; height:40px; background-color: yellow; text-align: left;border: 1px solid black;vertical-align:top;"></div>
    <input type="button" value="button">
     Some text
</td>
</tr>
<tr>
<td height="50" valign="top">
    <img src="images/spacer.gif" width="65" height="40" align="left" border="1">
    <input type="button" value="button">
     Some text
</td>
</tr>
</table>

输出:

在此处输入图像描述

Add vertical-align: top; to your <div>.

<div style="display:inline-block; width:65px; height:40px; background-color: yellow; text-align: left;border: 1px solid black;vertical-align:top;"></div>

Demo: http://jsfiddle.net/ThinkingStiff/xvpYF/

HTML:

<table border="1">
<tr>
<td height="50" valign="top">
    <div style="display:inline-block; width:65px; height:40px; background-color: yellow; text-align: left;border: 1px solid black;vertical-align:top;"></div>
    <input type="button" value="button">
     Some text
</td>
</tr>
<tr>
<td height="50" valign="top">
    <img src="images/spacer.gif" width="65" height="40" align="left" border="1">
    <input type="button" value="button">
     Some text
</td>
</tr>
</table>

Output:

enter image description here

赏烟花じ飞满天 2024-12-29 17:17:46

尝试将其置于 float:left

http://jsfiddle.net/pixelass/XDNe6/

<table border="1">
<tr>
    <td height="50" valign="top">

        <div style="display:inline-block;float:left; width:65px; height:40px; background-color: yellow; text-align: left;"></div>
        <input type="button" value="button">

         Some text

    </td>
</tr>

<tr>
    <td height="50" valign="top">

        <img src="images/spacer.gif" width="65" height="40" align="left" border="1">
        <input type="button" value="button">

         Some text

    </td>
</tr>

</table>

try putting it to float:left

http://jsfiddle.net/pixelass/XDNe6/

<table border="1">
<tr>
    <td height="50" valign="top">

        <div style="display:inline-block;float:left; width:65px; height:40px; background-color: yellow; text-align: left;"></div>
        <input type="button" value="button">

         Some text

    </td>
</tr>

<tr>
    <td height="50" valign="top">

        <img src="images/spacer.gif" width="65" height="40" align="left" border="1">
        <input type="button" value="button">

         Some text

    </td>
</tr>

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