0

How do I identify in my CSS file classes of an id.

So in my html file I create a basic label and textbox.

<div id="User">
    <div>
        <div class="left">
            <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
        </div>
        <div class="right">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </div>
    </div>
</div>

But how can I access class left and right in my CSS file, this is what I had.

#User
{
    .left {
        width: 30%;
        float: left;
        text-align: right;
    }
    .right {
        width: 65%;
        margin-left: 10px;
        float:left;
    }
}

3 Answers 3

3

Don't nest your selectors like that. This should work

#User .left {
  width: 30%;
  float: left;
  text-align: right;
}
#User .right {
  width: 65%;
  margin-left: 10px;
  float:left;
}
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for Don't nest your selectors like that. The OP might want to brush up on their CSS skills a bit as this is very basic.
1

You don't need the #User part. The following is sufficient

.left 
{
 width: 30%;
 float: left;
 text-align: right;
}

.right 
{
 width: 65%;
 margin-left: 10px;
 float:left;
}

The only reason why you would add the #User part is to distinguish between other div's that might have the class of .left and .right for example if you wanted to do that then you would go

#User .left {  background-color: blue; }
#User .right { /** CSS Code in here **/ }

<div id="User">
    <div class="left">Testing Left</div>
    <div class="right">Testing Right</div>
</div>
<br />
<br />
<div id="User2">
    <div class="left">Testing Left2</div>
    <div class="right">Testing Right2</div>
</div>

In this case only the first .left will have a blue background.

3 Comments

Not sure how you can say that he doesn't need to include #User in his rule.
@MVCKarl I did need to specify an id to ensure it remains separate to other CSS definitions in my file.
@ultranaut I was pointing out that his CSS syntax was incorrect. Without seeing the rest of his code, I shouldn't assume that he is trying to distinguish between Id's.
0
#user.left and #user.right 

should work. you can do the same with tags like td.left will only target td elements with the class left.

EDIT: and yes dont nest like MVCKarl said

1 Comment

You can't have multiple IDs!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.