Display Listbox On Textbox Hover By CSS - css

I am not able to display listbox on mouse hover on textbox as below
<table id="Search">
<tr>
<td>
<asp:TextBox runat="server" ID="topics" CssClass="TT"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="LstBox" CssClass="LB" runat="server" >
<asp:ListItem Text="Mahesh" Value="1"></asp:ListItem>
<asp:ListItem Text="Mahendra" Value="2"></asp:ListItem>
<asp:ListItem Text="Kirti" Value="3"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
CSS
td .LB
{
display:none;
position:relative;
}
td TT:hover .LB
{
display:block;
position:absolute;
}
How to display listbox on mouse hover on textbox?.

You can do it like this.
HTML
<table id="Search">
<tr>
<td>
<asp:TextBox runat="server" ID="topics" CssClass="TT"></asp:TextBox>
<asp:ListBox ID="LstBox" CssClass="LB" runat="server" >
<asp:ListItem Text="Mahesh" Value="1"></asp:ListItem>
<asp:ListItem Text="Mahendra" Value="2"></asp:ListItem>
<asp:ListItem Text="Kirti" Value="3"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
CSS
table tr td{
position:relative;
}
.TT{
/*It's optional to provide it these three property.*/
position:absolute;
left:0; /*Change values according to your adjustments*/
top:0; /*Change values according to your adjustments*/
}
.LB{
position:absolute;
left:0; /*Change values according to your adjustments*/
top:0; /*Change values according to your adjustments*/
display:none;
}
/*If you want to keep it visible, better use on :focus Pseudo class*/
table td:focus .LB,table td:hover .LB
{
display:block;
}
OR better option
JQUERY
/This will work directly with your textbox. Don't forget to add jQuery latest version./
<script>
$(document).ready(function () {
$(".TT").hover(
function () {
$('.LB').css('display','block');
}, function () {
$('.LB').css('display', 'none');
}
);
});
</script>

try this
td .TT:hover .LB
{
display:block;
position:absolute;
}
References: Use :hover to modify the css of another class?

Related

CSS affecting AJAX Controls

Having an issue trying to figure out why this is affecting the AJAX control the way it is.
When I remove the CSS file it displays correctly.
CSS File
.tdMain
{
width:452px;
font-family:Arial;
font:bold,small;
}
.tdInput
{
width:324px;
font-family:Arial;
}
.center
{
margin-left:auto;
margin-right:auto;
width:50%;
}
table
{
border-collapse: separate;
border-spacing: 0;
border: 0;
width:752px;
}
ASPX
<tr>
<td class="tdMain">Date:</td>
<td>
<asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>
<asp:ImageButton ID="imgPopupDate" ImageUrl="~/Images/calendar.png" ImageAlign="Bottom" runat="server" />
<ajaxToolkit:CalendarExtender ID="cDate" PopupButtonID="imgPopupDate" runat="server" TargetControlID="txtDate" Format="MM/dd/yyyy"/>
</td>
</tr>
The CalendarExtender generates a table. You are setting all tables on your page to a width of 752px including the one generated by the CalendarExtender.
table
{
...
width:752px;
}
you need to be more specific with your css selectors. Give the table that you wish to have a set width a class or id and use that as a selector.
table.myTable
{
...
width:752px;
}
or
table#myTable
{
...
width:752px;
}

How to decrease the space between vertical radiobuttonlist

I have a vertical radiobuttonList sitting in a table.
How do I decrease the spacings between each of the listitems so that the total height of radiobuttonList is smaller?
I have tried using padding and margin but none seems to work.
Use CellPadding property of RadioButtonList, you can set 0 for minimum height
<asp:RadioButtonList ID="rdlst" runat="server" CellPadding="15" CellSpacing="0" ><asp:ListItem Value="1" Text="1"></asp:ListItem> <asp:ListItem Value="2" Text="2"></asp:ListItem></asp:RadioButtonList>
you can just add this inside the radiobuttonlist tag:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="300px">
radiobuttonList in a table so try cellspacing="0" cellpadding="0" and padding:0; for td also
Provided this w3schools demo demonstrates accurate markup, it looks like they're built in a table. Try this:
.someClassName td {
padding: 0;
margin: 0;
}
Replacing .someClassName with the CssClass of the RadioButtonList or some other wrapper object.
I changed the radiobuttonlist to use RepeatLayout="Flow" instead of RepeatLayout="Table"
eg:
<asp:RadioButtonList ID="radOrderBy" runat="server" AutoPostBack="True" RepeatLayout="Flow" >
<asp:ListItem Value="NAME" Text="Name" Selected="True" />
<asp:ListItem Value="NUMBER" Text="Number" />
</asp:RadioButtonList>

ASP.NET Form inside a Hidden Div won't work

I have a login FORM inside a Hidden DIV, this DIV is hidden using CSS display:none; when I click on some other DIV, I show this DIV using jquery .slideDown(), so I can be able to use this form.
When I click on the button, the OnClick="Login" doesn't seem to work,and when I removed this form from this hidden div to simply another place in the body, it worked. What's the problem?
ASP.NET:
<div id="userCPContainer">
<form id="loginForm" runat="server">
<asp:Label ID="Label1" runat="server" Text="Username" class="loginLabels"></asp:Label>
<br />
<asp:TextBox ID="usernameField" runat="server" MaxLength="50" class="loginFields"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Password" class="loginLabels"></asp:Label>
<br />
<asp:TextBox ID="passwordField" runat="server" MaxLength="50"
TextMode="Password" class="loginFields"></asp:TextBox>
<asp:Button ID="loginButton" runat="server" Text="Log in" onclick="Loginn" class="loginButton"/>
</form>
</div>
JQUERY:
function showUserCP() {
$("#userCPContainer").slideDown(200);
$(".userCPDiv").css("background-color", "#000000");
$(".userCPDiv").css("border-color", "#000000");
}
function hideUserCP() {
$(".userCPDiv").css("background-color", "rgb(43, 147, 206)");
$(".userCPDiv").css("border-color", "rgb(43, 147, 206)");
$("#userCPContainer").slideUp(200);
}
$(".userCPDiv").click(function (e) {
//Either way, hide Main Menu
hideMainMenu();
if ($("#userCPContainer").is(":visible")) {
hideUserCP();
}
else {
showUserCP();
}
e.stopPropagation();
});
CSS:
#userCPContainer
{
overflow:hidden;
border-style:solid;
border-top-style:none;
border-color:rgb(43,147,206);
border-width:2px;
position:absolute;
right:0px;
top:0px;
display:none;
z-index:1;
width:300px;
background-color: #000000;
}
Nothing really complicated...
When you use CSS display: none; the problem is that all that's inside that DIV gets removed completely from the HTML Document and that causes that ASP.NET does not recognize this element when you show it via jQuery. I see to possible solutions:
Use visibility: hidden instead of display: none;, if you do this you will probably have some problems with the DIV height because it will take the space needed to render but it will not be visible.
Use a ScriptManager and an UpdatePanel and put the div and the form inside those elements, so the server will know when you render the Button in the client. Also, make sure that you register your jQuery scripts inside the ScriptManager
Hope this helps you

Checkbox Label displayed in the next line if width of the label exceeds the limit of the Div tag

I am working with CheckBoxList, the checkbox lables are displayed in the next line if the value exceeds the div tag width.
Is there a way by which i can allign the same on the same line?
<table id="Table1">
<tr>
<td width="250px">
<asp:Label ID="deleteLabel" runat="server" Text="Select "></asp:Label>
</td>
<td width="900px">
<div style="border-style: solid; border-color: inherit; border-width: thin; overflow: auto;
width: 356px; height: 100px" class="ccodes" runat="server" id="deletePanel1">
<asp:CheckBox ID="CheckBoxSelectAll" runat="server" Text="All" />
<asp:CheckBoxList ID="checkBoxListDeleteEntities" runat="server" RepeatDirection="Vertical"
Height="26px">
</asp:CheckBoxList>
</div>
</td>
</tr>
</table>
Values are displayed as shown below. (for third value if it exceeds the width of the div (356px))
[] test1
[] test2
[]
test test test test test test test test test test test test test
Any suggestion how to make the checkbox label inline with the checkbox?
Have you tried white-space: nowrap?
.nowrap_list tr td label
{
white-space:nowrap;
overflow:hidden;
}
<asp:CheckBoxList ID="checkBoxListDeleteEntities"
CssClass="nowrap_list"
runat="server" RepeatDirection="Vertical"
Height="26px">
</asp:CheckBoxList>

Style individual RadioButtonList ListItem

I know that you can assign a class to the generated table by using CssClass on the RadioButtonList but I need to be able to style the generated <td>'s individually.
Easy with JQuery but I'd much rather not have to resort to that.
Adding cssClass="myClass" to the ListItem results in the following broken HTML
<table id="myTable">
<tbody>
<tr>
<td>
<span cssclass="some_class"> // Well this is rubbish!
<input id="myRadioInput" type="radio" name="myRadioInput" value="myValue" >
<label for="myRadioInput">myLabel</label>
</span>
</td>
<td>
<input id="myRadioInput2" type="radio" name="myRadioInput2" value="myValue2">
<label for="myRadioInput2">myLabel2</label>
</td>
</tr>
</tbody>
</table>
So my question is: Is it actually posible to either assign a class or apply inline styling to the generated <td>'s INDIVIDUALLY?
PLEASE NOTE
This is a question about ASP.NET. Answers that simply tell me how to style HTML elements are not answering the question.
If you want to do it in code (e.g. if you need to dynamically adjust the style based on complicated logic) you can set the style attribute on the ListItem (setting the class attribute might work as well but if your ListItem is disabled, asp.net will override it with a special aspNetDisabled class):
item.Attributes["style"] = "color: lightgray; font-style: italic;";
To style all the td's you could add the CSS like so...
#myTable td{
color:Red;
}
Other than that (if you wanted different styles for each td) jQuery would be the only way to add classes to those generated td's.
$('#myTable td:eq(0)').addClass('td1');
$('#myTable td:eq(1)').addClass('td2');
...
OR
$.each($('#myTable td'), function(i){
$(this).addClass('td'+i);
});
This is one of the reasons I dislike ASP.NET controls with all the extra markup you have no control of through the properties panel.
You can do it as follows:
<table>
<tr>
<td class="yourcssclassname"></td>
<td class="yourcssclassname2></td>
</tr>
</table>
<style type="text/css">
.yourcssclassname
{
padding: 10px;
}
.yourcssclassname2
{
padding: 15px;
}
</style>
or you can
<table>
<tr>
<td style="padding:10px;"></td>
<td style="padding:15px;"></td>
</tr>
</table>
Hope this helps
You are so close to the solution. Add class attribute instead of cssclass on the items for individual styling. This will add a span tag surrendering the input and label tags with the right class.
<style>
.radiobuttonlist .red { display: block; background-color: red; }
</style>
<asp:RadioButtonList runat="server" CssClass="radiobuttonlist">
<asp:ListItem Text="Item1" Value="1" ></asp:ListItem>
<asp:ListItem Text="Item2" Value="2" class="red" ></asp:ListItem>
<asp:ListItem Text="Item3" Value="3" ></asp:ListItem>
</asp:RadioButtonList>
You can target the input elements and labels with:
input[type="radio"] { margin-right:10px; }
input[type="radio"] + label { color:red; }
If you had a class on the table, you could add that to be more explicit. Should be backwards compatible to IE7.

Resources