/    Sign up×
Community /Pin to ProfileBookmark

Defining Individual Elements

I need some help coding individual elements in CSS. If I wanted to have my first HR line to have no top margin and my second HR to have a top margin of 15px, how would I code that? Thank you.

to post a comment
CSS

15 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyJul 21.2005 — I would use [URL=http://www.w3schools.com/css/css_pseudo_classes.asp]pseudo classes[/URL]
[CODE]
hr {
margin-top: 15px;
}
hr:first-child {
margin-top:0;
}
[/CODE]
Copy linkTweet thisAlerts:
@stimpy1authorJul 21.2005 — Thank you. It worked nicely.
Copy linkTweet thisAlerts:
@NogDogJul 21.2005 — CSS:
<i>
</i>hr#top {
margin-top: 0;
}
hr#bottom {
margin-top: 15px;
}

HTML:
<i>
</i>&lt;hr id="top"&gt;
.
.
.
&lt;hr id="bottom"&gt;
Copy linkTweet thisAlerts:
@bathurst_guyJul 21.2005 — Why not use pseudo classes?
Copy linkTweet thisAlerts:
@NogDogJul 21.2005 — Why not use pseudo classes?[/QUOTE]
Why use them?
Copy linkTweet thisAlerts:
@bathurst_guyJul 21.2005 — Thats what they are meant for. And you save adding ids to all hr's
Copy linkTweet thisAlerts:
@NogDogJul 21.2005 — I'll grant you that, but what if there's a <p>...</p> before the first <hr>, so that the <p> is the first-child of the containing element? Assuming I understand it correctly (possibly an incorrect assumption), then it wouldn't work, would it?
Copy linkTweet thisAlerts:
@bathurst_guyJul 21.2005 — Nah it wouldnt. So yeh it would depend on your situation i spose.

There should be a :first-element-of-this-type or something like that...
Copy linkTweet thisAlerts:
@drhowarddrfineJul 21.2005 — Well the hr is depreciated. [/QUOTE]
Since when? I don't believe so.
Copy linkTweet thisAlerts:
@stimpy1authorJul 21.2005 — CSS:
<i>
</i>hr#top {
margin-top: 0;
}
hr#bottom {
margin-top: 15px;
}

HTML:
<i>
</i>&lt;hr id="top"&gt;
.
.
.
&lt;hr id="bottom"&gt;
[/QUOTE]


So how would you use this for multiple hr's, say 3 or 4? And could you use the same thing for h1, h2, and other elements?
Copy linkTweet thisAlerts:
@SanimJul 21.2005 — If you wanted more than two..

CSS:
<i>
</i>hr#first {
margin-top: 0;
}
hr.next {
margin-top: 15px;
}

HTML:
<i>
</i>&lt;hr id="first"&gt;
.
.
.
&lt;hr class="next"&gt;
.
.
.
&lt;hr class="next"&gt;

And yes, I think you can do it with h1, h2, etc.
Copy linkTweet thisAlerts:
@NogDogJul 21.2005 — You can do the following if most HR's will look one way, a few (class) will look another way, and a specific one (ID) will look yet another way:
<i>
</i>.
.
.
&lt;style type="text/css"&gt;
hr {
margin: 10px 20px;
}
hr.some {
margin-top: 15px;
}
hr#one {
margin-top: 0;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;hr id="one"&gt;
&lt;hr&gt;
&lt;hr class="some"&gt;
&lt;hr&gt;
&lt;hr class="some"&gt;
&lt;hr&gt;
.
.
.
Copy linkTweet thisAlerts:
@stimpy1authorJul 22.2005 — Thanks, you've all been really helpful. I started out just doing basic html to build my first website, and now I'm incorporating css. I'm looking forward to learning more.
Copy linkTweet thisAlerts:
@proutonJul 22.2005 — Perhaps the reason to not use the child and sibling pseudo-class selectors is that [i]IE doesn't support them[/i]. I'm not a fan of using IE, but given the installed base you can't ignore its limitations.
Copy linkTweet thisAlerts:
@davidbrentJul 22.2005 — Remember people, classes can't override IDs.
×

Success!

Help @stimpy1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...