【问题标题】:How to apply to CSS styles to Drupal search form submit button?如何将 CSS 样式应用于 Drupal 搜索表单提交按钮?
【发布时间】:2011-03-18 02:47:10
【问题描述】:

我完全受够了这个。我已经尝试了一周尝试不同的代码,修改不同的值等。我根本无法为我的 Drupal (6) 的搜索提交按钮设置皮肤。

我希望能够将提交按钮换成悬停、活动等事件。最大的问题之一是我不知道如何更改 php 代码,因此这些 CSS 样式仅应用于搜索提交按钮,而不是网站上的所有其他按钮。

这是我目前半工作的代码。现在我面临的另一个问题是,span 标签一直显示大小仅为 45x16px,我已将宽度和高度属性应用为 54x28,但它并没有改变任何东西。

function phptemplate_button($element) {
  // Make sure not to overwrite classes.
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'] .' '. $element['#attributes']['class'];
  }
  else {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'];
  }

  // We here wrap the output with a couple span tags
  return '<span class="button"><span><input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'" ')  .'id="'. $element['#id'].'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']) ." /></span></span>\n";
}
span.button  {
    background-image: url('images/go-button.png');
    background-repeat: no-repeat;
    border: none;
    width: 53px;
    height: 28px;
}
span.button:hover {
    background-image: url('images/go-button-gifsmooth.gif');
    background-repeat: no-repeat;
    border: 0;
}
span.button:active {
    background-image: url('images/go-button-pressed.png');
    background-repeat: no-repeat;
    border: 0;
}
span.button span input {
    background: transparent;
    border: 0;
    color: transparent;
    padding: 0;
    cursor: pointer;
}

【问题讨论】:

    标签: css drupal button


    【解决方案1】:

    如果您想为网站主搜索页面 (www.example.com/search) 的搜索按钮设置主题,您可以在 template.php 中使用它:

    function phptemplate_button($element) {
      // Check that the buttons belongs to the site search page
      if ($element['#value'] == 'Search' && $element['#id'] == 'edit-submit') {
        // Make sure not to overwrite classes.
        if (isset($element['#attributes']['class'])) {
          $element['#attributes']['class'] = 'form-'. $element['#button_type'] .' '. $element['#attributes']['class'];
        }
        else {
          $element['#attributes']['class'] = 'form-'. $element['#button_type'];
        }
    
        // We here wrap the output with a couple span tags
        return '<span class="button"><span><input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'" ')  .'id="'. $element['#id'].'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']) ." /></span></span><div style='clear:both;'></div>\n";
      }
      else {
        return '<input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'" ')  .'id="'. $element['#id'].'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']) ." />\n";
      }
    }
    

    要更改标题或“搜索块”中“主题搜索”的按钮,您必须创建一个名为 search-theme-form.tpl.php 或 search-block-form.tpl.php 并将其放在您的主题目录中。然后插入类似这样的代码:

    // This is for the theme search... for search block, $search['search_block_form']
    <?php print $search['search_theme_form']; ?>
    <span class="button"><span><input type='submit' name='submit-form' value='TEST' class='this-submit'/></span></span>
    <?php print $search['hidden']; ?>
    

    为了使跨度显示为正确的大小,我通过将display: block; 添加到span.button 的样式来使其工作。它可能会稍微移动按钮,但使用更多 CSS,您可以在任何您喜欢的地方获得它。

    【讨论】:

    • 非常感谢您的回复。我的按钮现在显示良好,但是我发现我的代码存在问题......当您单击文本顶部的右侧时,该按钮只会将您带到链接。如果您单击按钮的最角落,它将不会链接到它。你可以在这里看到(我的实际站点):nside-elite.techiedesign.net/drupal6/user/… 我可以使用一些 jQuery 来为我的 template.php 文件中的按钮设置可点击区域吗?我在这里按照这个教程:teddy.fr/blog/beautify-your-drupal-forms我不知道如何插入它。
    • 如果我觉得我只是在找人为我编码,请原谅。我是网站设计的新手,我正在尝试尽可能多地学习。我最近为初学者购买了一本 Javascript 书籍,目前我正在慢慢地完成它。
    • 我不认为这是一个巨大的主要问题,因为我得到了实际显示的按钮背景图像。但这只会让网站感觉错误和平庸。我认为大多数人在点击按钮时都会点击文本,但这只是一个令人恼火的问题。
    • @Matt 我只能在屏幕右上角看到搜索,单击箭头什么也没做。至于使用 jQuery 来增强您的表单,是的,这是可能的。您需要选择您希望将事件处理程序添加到 (span) 但需要具体的元素。单击选定的跨度时,类似于$('SELECTOR').click(function() { $('SELECTOR OF FORM ID').submit(); }); 的内容将提交表单。查看 jQuery 文档以了解更多信息:docs.jquery.com/Tutorials。抱歉没有更具体,现在睡觉,但会在早上看看。祝你好运!
    猜你喜欢
    • 2014-06-02
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    相关资源
    最近更新 更多