设置最小宽度 - jQuery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9791379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:18:49  来源:igfitidea点击:

Setting min-width - jQuery

jqueryresize

提问by eozzy

This works great:

这很好用:

$(document).ready(function() {
    var previewwidth = ($(window).width() - ( $('.aside').width() + $('.results').width() + 110) ) ;
    $(".result-preview").width(previewwidth);
    $("footer").text(previewwidth);

});


$(window).resize(function() {
    var previewwidth = ($(window).width() - ( $('.aside').width() + $('.results').width() + 110) ) ;
    $(".result-preview").width(previewwidth);
    $("footer").text(previewwidth);
});

but I'm not sure how to set min and max width, so min-width to 338px and max-width to 500px.

但我不确定如何设置最小和最大宽度,所以最小宽度为 338 像素,最大宽度为 500 像素。

thanks!

谢谢!

回答by Engineer

 $(".result-preview").css({
     "min-width": "338px", 
     "max-width": "500px"
 });

回答by Babak Naffas

Building on @user1113426, due to the way jQuery handles the names, you might need to use camel casing instead of the hyphens.

基于 @user1113426,由于 jQuery 处理名称的方式,您可能需要使用驼峰式大小写而不是连字符。

 $(".result-preview").css({
     minWidth: "338px", 
     maxWidth: "500px"
 });