表組み表現でのテーブルは現在、px単位での指定となっています。 また、それぞれのth,tdタグに対して指定がされています。
しかし、tableタグに対しての指定方法が皆無で、またパーセント指定ができません。
昨今、スマートフォンによる利用者が出てきており、画面幅がPCとくらべて狭いユーザがいます。 そういったユーザーに対して可変的に対応できるパーセント指定は便利なものだと考えています。
従来の記述方法 (セル単位のpx)
|500|c | 幅500pxにしたいテーブルセル |
この提案の記述方法 (テーブル単位の%)
| |c50 | 幅50%にしたいテーブル |
function &Factory_Table(&$root, $text) { - if (!preg_match('/^\|(.+)\|([hHfFcC]?)$/', $text, $out)) { + if (!preg_match('/^\|(.+)\|(([hHfF]|[cC](\d+)?)?)$/', $text, $out)) {
if ($is_template && is_numeric($text)) { $this->style['width'] = 'width:'.$text.'px;'; } + if ($is_template && substr($text,-1) == '%' && is_numeric(substr($text,0,-1))) { + $this->style['width'] = 'width:'.$text.';'; + }
if ($this->types[$nrow] == 'c') { $stylerow = &$row; - } + } else if(substr($this->types[$nrow],0,1) == 'c'){ + $stylerow = &$row; + $_table_width = (is_numeric(substr($this->type,1))) ? substr($this->type,1) : ""; + }
} $string .= $this->wrap($part_string, $part); } + $_table_width = $_table_width ? $_table_width.'%' : ''; - $string = $this->wrap($string, 'table', ' class="style_table" cellspacing="1" border="0"'); + $string = $this->wrap($string, 'table', ' class="style_table" cellspacing="1" border="0" style="width:'.$_table_width.';"');
@media screen and max-width(XXpx) { .style_table { min-width: 100%; } }とかすれば、この仕組みが入ってもレスポンシブなスキンは書けるかな…。 -- bee 2016-12-04 (日) 11:18:51