我在 C#(Asp.net) 中的标签内动态创建了一个 div 标签,该标签将包含 3 个动态生成的按钮。我只希望当用户将鼠标悬停在表格单元格(td 标记)上时显示 div。我可以通过 .css 实现这一目标吗?
C# 中的动态生成如下所示:
HtmlTableCell cell = (HtmlTableCell)c;
HtmlInputButton PopupAddButton = new HtmlInputButton();
PopupAddButton.ID = "PBA" + c.ID.ToString();
PopupAddButton.Value = "Add";
PopupAddButton.Style["Height"] = "14px";
PopupAddButton.Style["Width"] = "40px";
PopupAddButton.Style.Add(HtmlTextWriterStyle.Top, "-100");
PopupAddButton.Style["right"] = "0";
PopupAddButton.Style["float"] = "left";
PopupAddButton.Style["vertical-align"] = "top";
PopupAddButton.Style["font-size"] = "9px";
HtmlInputButton PopupEditButton = new HtmlInputButton();
PopupEditButton.ID = "PBE" + c.ID.ToString();
PopupEditButton.Value = "Edit";
PopupEditButton.Style["Height"] = "14px";
PopupEditButton.Style["Width"] = "40px";
PopupEditButton.Style["top"] = "0";
PopupEditButton.Style["right"] = "0";
PopupEditButton.Style["float"] = "left";
PopupEditButton.Style["vertical-align"] = "top";
PopupEditButton.Style["font-size"] = "9px";
HtmlInputButton PopupDeleteButton = new HtmlInputButton();
PopupDeleteButton.ID = "PBD" + c.ID.ToString();
PopupDeleteButton.Value = "Delete";
PopupDeleteButton.Style["Height"] = "14px";
PopupDeleteButton.Style["Width"] = "40px";
PopupDeleteButton.Style["top"] = "0";
PopupDeleteButton.Style["right"] = "0";
PopupDeleteButton.Style["float"] = "left";
PopupDeleteButton.Style["font-size"] = "9px";
PopupDeleteButton.Style.Add(HtmlTextWriterStyle.VerticalAlign, "top");
PopupAddButton.Attributes.Add("onClick", "AddPopupControlToTableCell('" + cell.ClientID + "', '" + cell.Height.ToString() + "', '" + g_PopupControlId + "');");
PopupEditButton.Attributes.Add("onClick", "EditPopupControlToTableCell('" + cell.ClientID + "', '" + cell.Height.ToString() + "', '" + g_PopupControlId + "');");
PopupDeleteButton.Attributes.Add("onClick", "DeletePopupControlToTableCell('" + cell.ClientID + "', '" + cell.Height.ToString() + "', '" + g_PopupControlId + "');");
HtmlGenericControl ButtonDiv = new HtmlGenericControl("div");
ButtonDiv.ID = "buttonBlock" + c.ID.ToString();
ButtonDiv.Attributes.Add("class", "buttonBlock");
ButtonDiv.Controls.Add(PopupAddButton);
ButtonDiv.Controls.Add(PopupEditButton);
ButtonDiv.Controls.Add(PopupDeleteButton);
cell.Controls.Add(ButtonDiv);
我的 .css 目前看起来像这样
.buttonBlock input{
display:none;
}
td:hover #buttonBlock input{
display:inline;
}
但是,这不起作用。我做错了什么?