Hanging indentations

Hey together! I am trying to display references in a specific citation style, alongside a hanging indentation. Since the browser-support for text-indent: hanging is non-existent - MDN - I had to get creative with floating spacers and JS height calculations. I'm generally speaking quite happy with the visuals, I just don't like employing (probably terribly written) JS for such a "seeminly" simple thing. Here's a pen of it, would love to hear if someone has suggestions! https://codepen.io/Halbach_IO/pen/bGOWxBP Thanks a lot and cheers πŸ€“
text-indent - CSS: Cascading Style Sheets | MDN
The text-indent CSS property sets the length of empty space (indentation) that is put before lines of text in a block.
12 Replies
snxxwyy
snxxwyyβ€’15mo ago
if i'm not mistaken with what a hanging citation is, you can simply just target the desired lines you want to indent and give them a margin-left.
ml_hio
ml_hioOPβ€’15mo ago
Sounds good at first, yet indentation doesnt usually start on a certain element (like journal title, url or else). It might very well be within a single text element
ml_hio
ml_hioOPβ€’15mo ago
example:
No description
snxxwyy
snxxwyyβ€’15mo ago
if it's within the same element you can wrap the desired text in a span tag and give it a display: block; to put it on a new line and margin-left to indent it. For example-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <span>In tristique justo in nisl feugiat, id posuere nibh ullamcorper. Nam id orci massa.</span></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <span>In tristique justo in nisl feugiat, id posuere nibh ullamcorper. Nam id orci massa.</span></p>
span {
display: block;
margin-left: xyz;
}
span {
display: block;
margin-left: xyz;
}
ml_hio
ml_hioOPβ€’15mo ago
That concept would not work across screen sizes, since line breaks happen at different times
Chooβ™šπ•‚π•šπ•Ÿπ•˜
The indent can be done in pure CSS with a padding-left combined with negative text-indent.
snxxwyy
snxxwyyβ€’15mo ago
i've never used text indent before but there you go ^
ml_hio
ml_hioOPβ€’15mo ago
that's a cool solution!
snxxwyy
snxxwyyβ€’15mo ago
you would use chooking's one, however to answer your other message, mine would work on all screen sizes too, the display: block; always puts it on a new line, so when the text width shrinks it doesn't affect anything.
ml_hio
ml_hioOPβ€’15mo ago
Yeah that's the thing, it shouldnt break into a new line But yeah here i sat for an hour trying to break the box model and the guy just does it with a 2-liner ;D
snxxwyy
snxxwyyβ€’15mo ago
yeah man that's cool
Want results from more Discord servers?
Add your server