HTML CSS 文本对齐

发布于 2024-10-10 14:10:59 字数 1299 浏览 5 评论 0原文

附上一张图片。

我正在尝试获取如右图所示的文本格式-最结束。即在缩略图的高度(36px)内,名称、时间、日期必须垂直对齐显示。我在显示文本垂直对齐时遇到问题。这是我的代码 -

<div id="sresults" style="position:absolute;top:120px; left:36%;">
    <div id="0" style="width:500px;padding:5px;cursor:pointer;clear:both;">
        <div id="content0" style="float:left; font-size:13px;">"Hey dude how are you doing?"</div>
        <div id="meta0" style="float:right;">
           <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts'></img>
           <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter"></img>
           <div id='name' style="float:right; font-size:11px">Peter</div>
           <div id='time' style="float:right;font-size:11px;">19:23</div>
           <div id='date' style="float:right;font-size:11px;">23 Dec'10</div>
        </div>
    </div>

准确地说,我希望 div id '名称','时间','日期' 像图像中那样对齐。如何?

另请注意,id="0" 的 div 是结果之一,页面中将有 10 个这样的 div,全部位于

attached is an image.

I am trying to get the text format as shown at the right-most end. i.e. within the height of the thumbnail (36px) name, time, date have to be shown vertically aligned. I am having problem showing the text vertically aligned. Here's my code -

<div id="sresults" style="position:absolute;top:120px; left:36%;">
    <div id="0" style="width:500px;padding:5px;cursor:pointer;clear:both;">
        <div id="content0" style="float:left; font-size:13px;">"Hey dude how are you doing?"</div>
        <div id="meta0" style="float:right;">
           <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts'></img>
           <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter"></img>
           <div id='name' style="float:right; font-size:11px">Peter</div>
           <div id='time' style="float:right;font-size:11px;">19:23</div>
           <div id='date' style="float:right;font-size:11px;">23 Dec'10</div>
        </div>
    </div>

To be accurate, I want the div ids 'name', 'time', 'date' to be aligned like in the image. how?

Also note that the div with id="0" is one of the results, there'll be 10 such in a page all under <div id="sresults">

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

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

发布评论

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

评论(2

对你再特殊 2024-10-17 14:10:59

这就是您想要的:http://www.bravegnuworld.com/rjune/test.html

注意将名称等封装在浮动的 div 中吗?你有三个 div(块元素,它们会自动堆叠)。将它们放入另一个 div 中,现在您就拥有了一个块元素,其中包含三个堆叠的块。您可以使用“float:right”或“display:inline-block”使div显示在同一水平上。与该行的其余部分一样。

<div id="sresults" style="position:absolute;top:120px; left:36%; background:yellow">
  <div id="0" style="width:500px;padding:5px;cursor:pointer;clear:both; background:red">
    <div id="content0" style="float:left; font-size:13px; background:blue">"Hey dude how are you doing?"</div>
    <div id="meta0" style="float:right; background:green">
     <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts'></img>
     <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter"></img>
      <div style="float:right">
        <div id='name' style="font-size:11px">Peter</div>
        <div id='time' style="font-size:11px;">19:23</div>
        <div id='date' style="font-size:11px;">23 Dec'10</div>
      </div>
    </div>
</div>

Here's what you want: http://www.bravegnuworld.com/rjune/test.html

Notice encapsulating the name, etc in a div that is floated right? You have three divs(block elements, they'll automatically stack). Put those inside another div, and you now have a block element with three stacked blocks inside it. You can either use "float:right" or "display:inline-block" to make the div display on the same level. as the rest of the line.

<div id="sresults" style="position:absolute;top:120px; left:36%; background:yellow">
  <div id="0" style="width:500px;padding:5px;cursor:pointer;clear:both; background:red">
    <div id="content0" style="float:left; font-size:13px; background:blue">"Hey dude how are you doing?"</div>
    <div id="meta0" style="float:right; background:green">
     <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts'></img>
     <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter"></img>
      <div style="float:right">
        <div id='name' style="font-size:11px">Peter</div>
        <div id='time' style="font-size:11px;">19:23</div>
        <div id='date' style="font-size:11px;">23 Dec'10</div>
      </div>
    </div>
</div>
乱了心跳 2024-10-17 14:10:59

您可以使用 table 而不是 div 这对我来说似乎更合逻辑:

<div id="sresults" style="position:absolute;top:120px; left:36%;">
    <div id="0" style="width:500px;padding:5px;cursor:pointer;clear:both;">
        <div id="content0" style="float:left; font-size:13px;">"Hey dude how are you doing?"</div>
        <table id="meta0" style="float:right;">
            <tr>
                <td>
                    <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts'/>
                    <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter"/>
                </td>
                <td style="text-align:right;">
                   <div id='name' style="font-size:11px">Peter</div>
                   <div id='time' style="font-size:11px;">19:23</div>
                   <div id='date' style="font-size:11px;">23 Dec'10</div>
                </td>
            </tr>
        </table>
    </div>
</div>

UPD

这是带有 div 的代码:

<div id="sresults" style="position:absolute;top:120px; left:36%;">
    <div id="id0" style="width:500px;padding:5px;cursor:pointer;clear:both;">
        <div id="content0" style="float:left; font-size:13px;">"Hey dude how are you doing?"</div>
        <div id="meta0" style="float:right;">
            <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts' style="float: left;"/>
            <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter" style="float: left;"/>
            <div style="text-align:right; float:right">
                   <div id='name' style="font-size:11px">Peter</div>
                   <div id='time' style="font-size:11px;">19:23</div>
                   <div id='date' style="font-size:11px;">23 Dec'10</div>
            </div>
        </div>
    </div>
</div>

You can use table instead of div it's seems more logical to me:

<div id="sresults" style="position:absolute;top:120px; left:36%;">
    <div id="0" style="width:500px;padding:5px;cursor:pointer;clear:both;">
        <div id="content0" style="float:left; font-size:13px;">"Hey dude how are you doing?"</div>
        <table id="meta0" style="float:right;">
            <tr>
                <td>
                    <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts'/>
                    <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter"/>
                </td>
                <td style="text-align:right;">
                   <div id='name' style="font-size:11px">Peter</div>
                   <div id='time' style="font-size:11px;">19:23</div>
                   <div id='date' style="font-size:11px;">23 Dec'10</div>
                </td>
            </tr>
        </table>
    </div>
</div>

UPD

Here is code with divs:

<div id="sresults" style="position:absolute;top:120px; left:36%;">
    <div id="id0" style="width:500px;padding:5px;cursor:pointer;clear:both;">
        <div id="content0" style="float:left; font-size:13px;">"Hey dude how are you doing?"</div>
        <div id="meta0" style="float:right;">
            <img src="http://www.mnducksvolunteer.org/_/rsrc/1262377955090/services/Google-Contacts-32.png" width="36px" title='Google Contacts' style="float: left;"/>
            <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs455.snc4/49881_1146922913_477096_q.jpg" width="36" title="peter" style="float: left;"/>
            <div style="text-align:right; float:right">
                   <div id='name' style="font-size:11px">Peter</div>
                   <div id='time' style="font-size:11px;">19:23</div>
                   <div id='date' style="font-size:11px;">23 Dec'10</div>
            </div>
        </div>
    </div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文