jquery - jQuery datepicker css 格式化
问题描述
我正在尝试实现 Jquery 日期选择器,使其看起来如附图所示。但我最终得到的是附加的图像(实际)
1)第一个问题是我如何让绿色和红色框与那些文本框(文本框的一部分)左对齐,如果我调整窗口大小或使用不同的分辨率,因为它是 2 个不同的组件,它会失去对齐(如所见在附件中。
2) 如何在日历图标和文本条目之间添加分隔线?
3) 为文本框添加与预期图像框中相同的边框。
代码: HTML
<span class="input-color">
<div class="color-box-green"> </div>
</span>
<div>
<input type="text" id="greenDate" [ngModel]="data.approvedDate | date:'MM/dd/yyyy'" class="datepickerIconIn" size="10" >
</div>
$(".datepickerIconIn").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'mm/dd/yy'
})
CSS
input.datepickerIconIn
{
background-image : url('/assets/img/calender.png');
background-size: 20px;
background-Position : 98% center;
background-Repeat :no-repeat;
cursor:pointer;
}
.input-color .color-box-green {
width: 6px;
height: 20px;
position: left;
background-color: green;
float: left;
}
解决方案
来自评论:«当我调整窗口大小时,颜色框和日期框显示为 2 行。»
首先,a<div>
中的 a<span>
是无效标记。
我建议如下:
input.datepickerIconIn{
background-image : url('/assets/img/calender.png'); /* This obviously doesn't show here */
background-size: 20px;
background-position : 98% center;
background-repeat :no-repeat;
cursor:pointer;
}
.colored-input{
margin:0 0 0 0.4em; /* the left margin has to be the same has the .color left position offset. */
}
.input-color {
position:absolute;
top:0.5em;
left:0.4em; /* Left offset */
width: 0.5em;
height: 1.3em;
}
.input-color.green {
background-color:green;
}
.input-color.red {
background-color:red;
}
/* And so on with the colors */
<div class="colored-input">
<span class="input-color green"></span><input type="text" id="greenDate" [ngModel]="data.approvedDate | date:'MM/dd/yyyy'" class="datepickerIconIn" size="10" >
</div>
在codePen上也是如此,您可以在其中调整视口的大小以及实例化日期选择器的位置。您会注意到颜色“标记”将在调整大小时保留输入。
您只需在输入前添加一个具有适当颜色类的空范围。整体必须在里面.colored-input
。
(是的,我在这里稍微重命名了......我强烈建议您为元素使用真正有意义的类名。从长远来看,它会有所帮助。)
推荐阅读
- amazon-web-services - 使用 AWS CLI 删除 S3 存储桶中的多个子文件夹
- angular - routerLink 有时不会路由到默认路由
- php - 从 ContentEditable 元素输出 UTF-8
- c# - 调用我的方法时如何解决此错误?
- r - 数字日期变量到实际日期变量
- python-3.x - 使用 wsgi 脚本托管的带有聊天机器人的烧瓶应用程序 [sqlite3.OperationalError) 无法打开数据库文件]
- odbc - ODBC DataStage 从 SQL Server 错误读取 nvarchar
- visual-studio-code - 在 Visual Studio Code 中执行 Python 脚本时,是否可以配置隐藏活动栏的设置?
- android - 添加 admob 依赖项 17.1.1 后构建时出现 Android 错误
- sql - SQL 正则表达式函数返回错误的结果