【问题标题】:HAML: table column's width not workingHAML:表格列的宽度不起作用
【发布时间】:2011-10-18 14:27:03
【问题描述】:

没有什么不工作的。当我输入大文本表时,会出现向右深处并出现水平导航。

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%;}

【问题讨论】:

    标签: ruby-on-rails css ruby haml markup


    【解决方案1】:

    你真的想设置样式,而不是 html 属性

    试试这个:

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

    您实际创建的是:

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

    你应该创造:

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

    当然,使用类和 CSS 会更好,但这会解决眼前的问题。

    【讨论】:

    • 因为我用了%table.classname{:cellpadding=>5,:cellspacing=>5,:border=>'1'}这样的东西。正如你所知,cellpadding 和 cellspacing 不是 CSS 部分。但无论如何你的解决方案对我不起作用:(表格列仍然很宽。我做了 %th{ :style => "width:200px"; } Name 什么都没有。
    • 这是在 Haml 中执行此操作的正确方法。你的问题现在在 CSS 中。
    • 所以新手错误:(我有测试文本,例如“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...“因为它水平导航出现。谢谢杰西!:)
    猜你喜欢
    • 2013-11-17
    • 2011-01-18
    • 1970-01-01
    • 2012-06-09
    • 2012-12-08
    • 2018-10-08
    • 2014-10-27
    • 2017-06-23
    • 1970-01-01
    相关资源
    最近更新 更多