将HTML输入日期选择器向右对齐

时间:2019-01-23 10:12:12

标签: html css html5

我无法将日期选择器与输入元素enter link description here右侧的输入type =“ datetime-local”对齐

input{
  width:400px;
}
<input type="datetime-local" class="dateTime" name="starttime" id="startTime" step="2">
这是当前视图:

This is the current  view

我的要求是不使用javascript将datepicker正方形放置在右侧

预期结果如下:

enter image description here

4 个答案:

答案 0 :(得分:1)

使用此代码将为您提供帮助。.我仅使用CSS作为输入:text-align:right。

input{
  width:400px;
  text-align:right;
}
<input type="datetime-local" class="dateTime" name="starttime" id="startTime" step="2">

答案 1 :(得分:0)

您可以使用div标记,以便datetime-local可以根据需要位于页面的右侧。

所以您的代码将是:

<div align="right">
<input type="datetime-local" step="2">
</div>

答案 2 :(得分:0)

如果要将输入的内容对齐到右侧,只需在CSS中使用text-align: right;。 我认为无法将日历向右对齐...但是我还建议您使用一些js datetimepicker,因为here in the camel docs

答案 3 :(得分:0)

您无法实现这一点,因为您正在尝试更改默认浏览器属性,并且每个浏览器都有针对不同输入类型的自定义CSS。

因此,如果您想使用自定义日期选择器,则可以按照自己的意愿进行操作,然后将其对齐到任何地方。

Here you have some examples