我设计了一个下拉日历,但如果我单击图像以显示下拉日历,我无法在文本框下方看到它。如何在文本框正下方显示此日历:
<table width=100%>
<tr align=center>
<td align=center>
<asp:Panel ID="Panel2" runat="server" GroupingText="Suche" >
<table width=100%>
<tr align=center>
<td align=center>
<asp:Label ID="Label4" runat="server" Text="Von :"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<img id="Calimg1" src="Images/cal.jpg" onclick="selectdate()" />
<div id="calblock1" class=calander >
<asp:Calendar OnSelectionChanged="Calendar1_SelectionChanged"
ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px"
DayNameFormat="Shortest" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="220px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True"
Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True"
Font-Size="9pt" ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
</div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="TextBox1"
ErrorMessage="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</td>
</tr>
......
CSS:
.calander
{
display:none;
position:absolute
}
以及我使用的 JavaScript:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#Calimg1').click(function () {
if (isAnyVisible()) return false;
$('#calblock1').slideToggle("slow");
});
$('#Img1').click(function () {
if (isAnyVisible()) return false;
$('#Div2').slideToggle("slow");
});
});
function isAnyVisible() {
if ($('#Calimg1').is(':visible') || $('#Img1').is(':visible')) {
return false;
}
return true;
}
最佳答案
您已指定position
为absolute
,这是正确的轨道。但是,您遗漏了一些东西。
首先,绝对元素的父元素应该有position:relative
。如果没有相对父级,当您指定 top
和 left
时,它将相对于整个文档。如果您使用的坐标是相对于容器的,则使用起来会容易得多。
接下来,嵌套表格很糟糕。使用 div,消除其中一些容器。 CSS 定位、 float 、边距和填充将实现相同的结果。
文档
- CSS
位置
在 MDN - https://developer.mozilla.org/en/CSS/position - 一篇关于 CSS 定位的文章 - http://www.alistapart.com/articles/css-positioning-101/
- 停止使用表格进行布局 @ Stack Overflow - Why not use tables for layout in HTML?
关于asp.net - 在文本框正下方显示日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11132836/