Bronzato
Bronzato

Reputation: 9362

Defining a width for my label

How can I define a width for the label Quantity (see below)? I would like a CSS solution without defining a style on the span but directly on the label.

Something like:

span label[for=Quantity] 
{ 
    width: 200px;
}

But the above css doesn't work.

enter image description here

Upvotes: 1

Views: 99

Answers (3)

Niloofar
Niloofar

Reputation: 751

you can make label a block element and set float to left so you can put other controls next to it

label {
    display: block;
    float: left;
    width: 180px;
}

Upvotes: 0

MA9H
MA9H

Reputation: 1909

using the inline-block is better because it doesn't force the remaining elements and/or controls to be drawn in a new line

.label {
  width:200px;
  display: inline-block;
}

Upvotes: 0

Dennis Fagan
Dennis Fagan

Reputation: 551

Your adding width to an inline element they wont accept that.

span label[for=Quantity] 
{ 
  width: 200px;
  display: block;
}

Upvotes: 5

Related Questions