简体   繁体   English

使用CSS向下移动一段文字

[英]shifting a piece of text down using CSS

I want to shift a text label down by about 6px I am attaching the style: 我想将文字标签下移约6像素,然后附加样式:

.price-label{
    font-family:Arial, Helvetica, sans-serif;
    font-size:small;
    position:relative;
    bottom:-6px;
    vertical-align:bottom;
}

The HTML is: HTML是:

<table border="0" cellspacing="1" cellpadding="0">
    <tr>
        <td height="45" colspan="2" align="center"><p><span class="text">Name</span><span class="name-label"></span></p></td>
        </tr>
            <tr>
                    <td>&nbsp;</td>
                    <td class="price-label">54.67</td>
                  </tr>
                  <tr>
                    <td width="28" bgcolor="#CCCCCC">&nbsp;</td>
                    <td height="45">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="28" bgcolor="#CC3300">&nbsp;</td>
                    <td height="112">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="28" bgcolor="#CCCCCC">&nbsp;</td>
                    <td height="22">&nbsp;</td>
                  </tr>
                </table>

Visually I want the 54.67 label to appear horizontally parallel - to the gap where the grey cell (top one) and red cell (second from top) meet. 视觉上,我希望54.67标签水平平行显示-与灰色单元格(顶部一个)和红色单元格(顶部第二个)相交的间隙。 As the number represents that point in the bar to the left. 数字代表左侧栏中的那个点。

So if some other technqiue is better, please let me know, maybe I should be using DIVs would that give me more control? 因此,如果其他技术更好,请让我知道,也许我应该使用DIV,这样可以给我更多控制权吗?

If you want to shift it down , you need to shift it a positive 6px, not a negative 6px, and set the top property, not bottom 如果你想转移下来 ,你需要转移是一个积极 6个像素,而不是负6像素,并设置top属性,而不是底部

position: relative;
top: 6px;

If I'm reading this correctly, then you're trying to straddle the border between two table cells which won't work. 如果我正确地读这篇文章,那么你想跨越这将不起作用双表格单元格之间的边界。 You'll need to consolidate the first two cells in the right column and then rowspan="2" the new cell with the number in it. 您需要合并右列中的前两个单元格,然后将新单元格中的数字合并为rowpan =“ 2”。 Then top or bottom vertically align the text in the cell and add some padding-top until it's aligned properly. 然后,顶部或底部垂直对齐单元格中的文本,并添加一些填充顶,直到它的正确对齐。

Label is an inline element, margin/padding would only work when you make it a block (inline-block, block or float). Label是一个内联元素,仅当您将其设为块(inline-block,block或float)时,边距/填充才起作用。 Try this: 尝试这个:

.price-label {
        padding:6px 0 0;
    display: inline-block;
    display: -moz-inline-box;
    -moz-box-orient: vertical;
    vertical-align: top;
    zoom: 1;
    *display: inline; }

You might be better off using: 使用以下方法可能会更好:

.price-label { margin-top: 6px; }

It's difficult to know more without some context of what else is around that table cell though. 但是,如果不了解该表单元格周围的其他内容,就很难了解更多信息。

Use padding-top:6px; 使用padding-top:6px; instead of positioning, which can get very messy with relation to sibling elements etc.. and has other-side effects. 而不是定位,这可能会使同级元素等的关系变得非常混乱。并具有其他副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM