Reputation: 8765
How can I create hanging section numbers with CSS? In other words,
Probably the best example to illustrate this is browser's rendering of numbered lists:
Heading 1
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
Heading 2
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
Is there any sane way to do this in CSS with numbers before heading tags (for all levels)?
Simple example HTML to modify:
<html>
<body>
<h1>First h1 heading</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
<h2>First h2 heading</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
</body>
</html>
Upvotes: 4
Views: 1217
Reputation: 14010
h1 { margin-left: -10px; }
will work until your header goes to two lines.
How about this:
h1 { text-indent: -10px }
Upvotes: 0
Reputation: 8765
I've got this done. Essentially, every counter has to be floated to the left:
h1:before {
content: counter(chapter) ". ";
float:left;
width: 1.2cm;
}
and every heading has to get a margin and a left
attribute:
h1 {
left: 1.2cm;
margin-left: -1.2cm;
}
Upvotes: 4
Reputation: 12091
Try this:
h1, h2, h3 {
text-align: left;
margin-left: -10px;
}
Upvotes: 0