开发者

specified size of td

<table class="data-table">
    <tr>

        <th style="width: 200px;">
            DescriptionDescription <%--in this case <td> is resized--%>
        </th>
    </tr>
<% foreach (var item in Model) { %>

    <tr>
        <td style="width: 200px;">
            <%= Html.Encode(item.Description) %>
        </td>
    </tr>
  <% } %>
</table>

browser html:

    <table class="data-table"> 
        <tr> 
          <th style="width: 200px;"> 
            Description
          </th> 
        </tr> 
        <tr> 
          <td > 
           This is description
          <开发者_如何学编程;/td>    
    </tr> 
   </table> 

Why this td size is not to apply on View page? In Design view on VS 2008 td size is applied, but after run project in my browser not have specified size


I tried the following code and it renders as expected:

<table class="data-table">
    <tr>

        <th style="width: 200px;">
            Description
        </th>
    </tr>
<% foreach (var item in Model) { %>

    <tr>
        <td style="width: 200px;">
            <%= Html.Encode(item.Description) %>
        </td>
    </tr>
<% } %>   
</table>  

Which outputs the following HTML:

<table class="data-table">
    <tr>

        <th style="width: 200px;">
            Description
        </th>
    </tr>
    <tr>
        <td style="width: 200px;">
            1
        </td>
    </tr>
</table>  

If this is the code you actually have and it's not rendering the style tag then I've no idea why it's not working. As I've shown above, what you have provided in your question works perfectly with the brace correct positioned (even though the brace positioning should just cause bad HTML instead of removing a style element...).

EDIT:

Sounds more to me like you're not looking at the correct website, or you're not closing and reopening the browser source window. The code itself doesn't appear to have any problems, unless of course the code you've provided isn't for the view output you're looking at.


Not sure why the style attribute is removed. But as an alternative you could use css:

<style>
table.data-table td{width:200px;background-color:red;}
</style>
<table class="data-table"> 
        <tr> 
          <th style="width: 200px;"> 
            Description
          </th> 
        </tr> 
        <tr> 
          <td > 
           This is description
          </td>    
    </tr> 
</table> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜