Reputation:
I have the following HTML:
<div class="columns clearfix">
<div class="xl float-left gutter-right"
data-ng-show="modal.data.createdDate">
<span class="label">Created</span>
<input class="full-width" type="text" value="{{modal.data.createdDate }}" />
</div>
<div class="xl float-left"
data-ng-show="modal.data.modifiedDate">
<span class="label">Modified</span>
<input class="full-width" type="text" value="{{modal.data.modifiedDate }}"/>
</div>
</div>
I am looking for a way to simplify this HTML with some CSS. Can someone tell me how I could remove the gutter-right and inline and make it so that this is introduced with a class in the top-level <div>
? Somehow I want to specify gutter-right but just have it for the first inside <div>
. Note I am using IE9 browsers and above. Also if it's possible I would like to have it so I don't need to specify the span.label
and the input.full-width
.
Note the reason I am trying to do this is because I have many fields set up like that with two fields on a row and a label above each field.
CSS:
.float-left {
float: left;
}
.gutter-right {
margin-right: 2rem;
}
.form label, .form .label {
display: block;
margin-bottom: 0.5rem;
}
.full-width {
box-sizing: border-box;
width: 100%;
}
Upvotes: 1
Views: 109
Reputation: 3255
Instead of a rule for .gutter-right
, go for .xl:first-child
:
.xl:first-child {
margin-right: 2rem;
}
Upvotes: 0
Reputation: 15609
Just use element:nth-child(1){ /*whatever*/ }
or element:first-child { /*whatever*/ }
You can also use element:nth-of-type(1){ /*whatever*/ }
Upvotes: 3
Reputation: 8171
You can just use E:first-child
css selector.
The :first-child
selector is used to select the specified selector, only if it is the first child of its parent.
Upvotes: 0