You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何缩小Bootstrap Datepicker的文本输入框宽度?

Fixing Overly Wide Bootstrap Datepicker

Got it, let's tackle that too-wide datepicker issue you're facing! Here are a few simple, Bootstrap-friendly ways to shrink its width while keeping things responsive:

1. Use Bootstrap's Built-in Grid Classes

Bootstrap's grid system is perfect for controlling element widths without custom CSS. Just add a column class (like col-md-6 or col-sm-8) to your datepicker container. This will make it take up a portion of the screen width instead of the full width:

<!---DatePicker ----> 
<div class="d-flex justify-content-start"> 
  <div class="col-md-6 col-sm-8 input-daterange input-group" id="datepicker"> 
    <input type="text" class="input-sm form-control" name="from" placeholder="startdate"/> 
    <span class="input-group-addon">To</span> 
    <input type="text" class= "input-sm form-control" placeholder="enddate"/> 
  </div> 
</div><br>
  • col-md-6 means the datepicker will take half the screen width on medium and larger screens.
  • col-sm-8 adjusts it to take 8/12 of the width on small screens, keeping it from feeling cramped.

2. Add Custom CSS for Precise Control

If you need more exact width control, create a custom class and apply it to the datepicker container. This lets you set a maximum width while keeping it responsive on smaller screens:

First, add the custom class to your HTML:

<!---DatePicker ----> 
<div class="d-flex justify-content-start"> 
  <div class="custom-datepicker input-daterange input-group" id="datepicker"> 
    <input type="text" class="input-sm form-control" name="from" placeholder="startdate"/> 
    <span class="input-group-addon">To</span> 
    <input type="text" class= "input-sm form-control" placeholder="enddate"/> 
  </div> 
</div><br>

Then add this CSS (make sure it comes after Bootstrap's CSS file so it overrides defaults):

.custom-datepicker {
  max-width: 400px; /* Adjust this value to your desired width */
  width: 100%; /* Ensures it shrinks on smaller screens */
}

3. Narrow the Individual Input Fields (Optional)

If the main issue is the input fields themselves being too wide, you can use Bootstrap's width utility classes (like w-75) on the inputs. Note: This might affect the spacing around the "To" separator, so test it out:

<input type="text" class="input-sm form-control w-75" name="from" placeholder="startdate"/>
<input type="text" class= "input-sm form-control w-75" placeholder="enddate"/>

Pick the method that fits your layout best—all of them play nicely with Bootstrap's existing styling!

内容的提问来源于stack exchange,提问作者Gcobani2019

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:54:55