Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在按钮旁边放置液体/弹性文本框?_Html_Css_Xhtml_Stylesheet - Fatal编程技术网

Html 如何在按钮旁边放置液体/弹性文本框?

Html 如何在按钮旁边放置液体/弹性文本框?,html,css,xhtml,stylesheet,Html,Css,Xhtml,Stylesheet,我想以“弹性”或“液体”的方式(正确的术语是什么?)将文本框和按钮放置在彼此相邻的位置,如下所示: (来源:) 当放置在任意宽度的容器中(包括调整浏览器窗口大小)时,按钮应右对齐并占据所需的宽度,而文本框应使用剩余的宽度。不幸的是,按钮的宽度在CSS中无法固定,因为它取决于标题(不同的动作、语言等) 对于以上内容,跨浏览器工作的好解决方案是什么?我能够在一个表中工作(我知道,但它可以工作),在该表中,它可以正确处理页面大小调整以及按钮更改的值: <table class="elastic

我想以“弹性”或“液体”的方式(正确的术语是什么?)将文本框和按钮放置在彼此相邻的位置,如下所示:


(来源:)

当放置在任意宽度的容器中(包括调整浏览器窗口大小)时,按钮应右对齐并占据所需的宽度,而文本框应使用剩余的宽度。不幸的是,按钮的宽度在CSS中无法固定,因为它取决于标题(不同的动作、语言等)


对于以上内容,跨浏览器工作的好解决方案是什么?

我能够在一个表中工作(我知道,但它可以工作),在该表中,它可以正确处理页面大小调整以及按钮更改的值:

<table class="elastic">
    <tr>
        <td><input class="textbox" type="text"></td>
        <td class="button"><input type="button" value="Test Button"></td>
    </tr>
</table>

在没有看到一些代码的情况下,很难给出一个明确的答案,但下面的内容将通过旁边的按钮将输入的大小调整为浏览器宽度的50%

input {width:50%}

<input>
<button>save</button>
输入{宽度:50%}
拯救
HTML:

<div class="widebox">
  <input type="text" value="" />
  <button>Button</button>
</div>

按钮
jQuery:

<script type="text/javascript">
$(document).ready(function(){
  var w = $(".widebox");
  $(".widebox input:text").css({ width: (w.width - (w.children("button:first").width + 20)) });
});
</script>

$(文档).ready(函数(){
var w=$(“.widebox”);
$(“.widebox输入:text”).css({width:(w.width-(w.children(“按钮:第一”).width+20));
});

注意:请确保将jQuery库包含在文档中。为了提高速度,我建议使用Google托管的jQuery扩展:

这里是我根据NGJ Graphics的答案编写的jQuery扩展。它考虑了多个按钮,如确定/取消选项

(function($) {
  $.fn.extend({
    widebox: function() {
      var el = $(this);
      var width = 0;
      el.children("button").each(function() {
        width += $(this).outerWidth( true );
      });
      el.children("input:text").css({ width: (el.width() - (width + 40)) });
    }
  });
})(jQuery);

我试图避开桌子,但我想这是实现我想要的最好/唯一的方法。谢谢…但我希望文本框是“可用宽度的其余部分”,而不是brwoser宽度的固定百分比?
(function($) {
  $.fn.extend({
    widebox: function() {
      var el = $(this);
      var width = 0;
      el.children("button").each(function() {
        width += $(this).outerWidth( true );
      });
      el.children("input:text").css({ width: (el.width() - (width + 40)) });
    }
  });
})(jQuery);