开发者

css formatting for values

开发者 https://www.devze.com 2023-04-04 05:59 出处:网络
I\'m trying to align the values. The code is, <section class=\"message success\"> Variable1: Value1<br/>

I'm trying to align the values. The code is,

<section class="message success">
      Variable1: Value1<br/>
      Variable2 : Value2<br/>  
</section>

.message.success {
border开发者_运维知识库: 1px solid #b8c97b;
background-color: #e5edc4;
background-image: -o-linear-gradient(top,  #e5edc4,  #d9e4ac);
background-image: -ms-linear-gradient(top,  #e5edc4,  #d9e4ac);
background-image: -moz-linear-gradient(top,  #e5edc4,  #d9e4ac);
background-image: -webkit-gradient(linear, left top, left bottom, from(#e5edc4), to(#d9e4ac));
background-image: -webkit-linear-gradient(top,  #e5edc4,  #d9e4ac);
background-image: linear-gradient(top,  #e5edc4,  #d9e4ac);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#e5edc4', endColorstr='#d9e4ac');
color: #3f7227;
text-shadow: 0 1px 1px #fff;
}

I want the values to be aligned properly like this,

Variable1    :     Value1
Variable2    :     Value2

Thanks.


Best off using a table as so:

<table class="message success">
    <tr>
        <td class="var">Variable1</td>
        <td class="sem">:</td>
        <td class="val">Value1</td>
    </tr>
    <tr>
        <td class="var">Variable2</td>
        <td class="sem">:</td>
        <td class="val">Value2</td>
    </tr>
</table>

and then using css you can align as so:

.val {width:100px;}
.sem {width:40px;}
.var {width:100px;}

See live example: http://jsfiddle.net/nayish/uenzN/2/


CSS :

.variable { margin-right : 40px; display: inline-block; width: 120px; }
.value { margin-left : 40px; display: inline-block; width: 120px; }

PHP Code :

echo '<span class="variable">'.$variable1.'</span>:<span class="value">'.$value1.'</span><br />';
echo '<span class="variable">'.$variable1.'</span>:<span class="value">'.$value1.'</span><br />';

... and so on ...

You can also work with CSS3 pseudo classes as :

span { display: inline-block; width: 120px; }
span:nth-child(odd) { margin-right : 40px;}
span:nth-child(even) { margin-left : 40px;}

In that case, your PHP code is lighter :

echo '<span>'.$variable1.'</span>:<span>'.$value1.'</span><br />';
echo '<span>'.$variable2.'</span>:<span>'.$value2.'</span><br />';

... and so on ...


Actually I cannot understand what you are wanting to do, but maybe you should use tables:

<table border="0">
<tr><td>Variable1:</td> <td>Value1</td></tr>
<tr><td>Variable2:</td> <td>Value2</td></tr>
</table>


I'd use a definition list if you're outputting key-value pairs. Your mark-up would like as follows:

<dl>
  <dt>Variable 1</dt> <dd>Value 1</dd>
  <dt>Variable 2</dt> <dd>Value 2</dd>
</dl>

You can then use CSS to style this list:

dt {
    display: block;
    float: left;
    clear: left;
}
dd {
    margin-left: 5em; /* this will line up the values */
}
dd:before {
    content: ':';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号