2011-10-18 47 views
3

沒有從這不起作用。當我輸入大文本表格時,會出現右側橫向導航。HAML:表格的寬度不起作用

index.haml

%table{:border => 1, :width => "100%"} 
    %tr 
    %th{:width => "200"} Name 
    %th.edit Edit 

    - @wallpapers.each do |wallpaper| 
    %tr 
     %td.name= wallpaper.name 
     %td= link_to (image_tag wallpaper.thumb.url(:thumb)), edit_wallpaper_path(wallpaper) 
     %td= button_to 'Delete', wallpaper_path(wallpaper), :confirm => 'Are you sure you want to delete this wallpaper?', :method => :delete 

的style.css

th.edit {width:20%;} 
td.name {width:20%;} 

回答

3

你真的要設置的風格,而不是HTML屬性

試試這個:

%table{:style=>"border: 1px; width: 100%"} 

你實際上創造的是:

<table border="1" width="100%"> 

,你應該創建:

<table style="border: 1px; width: 100%"> 
當然

,使用類和CSS效果會更好,但是這將解決殺到。

+0

這是因爲我用過這樣的東西__%table.classname {:cellpadding => 5,:cellspacing => 5,:border =>'1'} __。你知道cellpadding和cellpacing不是CSS的一部分。 但是,無論如何,你的解決方案不適合我:(表列仍然是廣泛的。我做了 **%th {:style =>「width:200px」;} Name ** and nothing。 – TiSer

+0

這是正確的方法在Haml中這樣做你的問題現在在CSS中 –

+0

所以新手錯誤:(我有測試文本例如「aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ...」沒有任何空格,並且因爲它橫向導航appeaps。謝謝Jesse!:) – TiSer