2009-04-04 4 views
4

Je publie beaucoup de texte en ligne, et a même écrit un system pour mettre en forme HTML pour moi. Maintenant, j'ai un problème: je veux faire des sidenotes dans les pages HTML, tout comme les livres. Juste pour expliquer, sidenotes sont ces notes dans les marges juste à côté du corps du texte principal.Qu'est-ce qu'un moyen fiable de faire sidenotes en HTML?

Est-ce que quelqu'un connaît une bonne façon fiable de les faire - de préférence avec CSS simple plutôt que JavaScript. Merci!

Répondre

6

Ok, fait ce beaucoup navigateur plus convivial (FF3, IE7/8, Chrome):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html> 
<head> 
    <title>Layout</title> 
    <style type="text/css"> 
    html, body, #wrapper { height: 100%; margin: 0; padding: 0; } 
    body { background-color: #666; width: 100%; text-align: center; font-family: Arial, sans-serif; } 
    #wrapper { width: 960px; margin: 0 auto; background: white; padding: 20px 0; } 
    #page { width: 660px; margin: 0 auto; text-align: justify; } 
    div.sidenote-left { float: left; margin-left: -150px; } 
    div.sidenote-right { float: right; margin-right: -150px; } 
    div.sidenote-left, div.sidenote-right { width: 150px; text-align: left; } 
    div.sidenote-left div, div.sidenote-right div { margin: 0 10px; border: 1px solid #666; padding: 4px; } 
    </style> 
</head> 
<body> 
<div id="wrapper"> 
<div id="page"> 
<p>In the 90s we saw the rise of GUIs (yes I know Macs were around in the 80s but GUIs became the standard for everyone once Windows took hold). This transition had many casualties like Lotus 1-2-3 (which was basically killed by Excel on Windows) and Wordperfect (MS Word killed it). Now you can argue that MS had the inside track since they also produced Windows and you'd be right but beyond that I think MS adjusted to the change quicker than anyone else.</p> 
<p>Borland was still an agile little company back then. It adjusted and took its highly successful Turbo Pascal and created Delphi.</p> 
<div class="sidenote-left"><div>See Chapter 7 for further explanation</div></div> 
<p>Now truly compiled languages ruled the roost in the 1990s with the exception of one little upstart: Java, which was something basically new. It was sorta compiled, sorta interpreted (being compiled into machine-independent bytecode that ran on a virtual machine). I personally think that the rise of both Java and Netscape scared the absolute bejesus out of Microsoft in the late 90s.</p> 
<div class="sidenote-right"><div>See Chapter 9 for further explanation</div></div> 
<p>Borland adjusted reasonably well producing what was really the first really successful Java IDE in JBuilder.</p> 
<p>They were fending off a resurgent Microsoft who also produced successive versions of Visual Studio that (imho) were years ahead of their time in the late 90s. I can remember coding Visual C++ with MTS (microsoft Transaction Server) DCOM objects over 10 years ago and that was a precursor to the modern application server platform we have today. Remote debugging and the like were things that were (or at least seemed) light years ahead on Visual Studio.</p> 
</div> 
</div> 
</body> 
</html> 

Note: en réponse à la question de la sélection de texte, je l'ai essayé avec le positionnement absolu, ce que vous pouvez faire en changeant ce CSS:

div.sidenote-left { position: absolute; margin-left: -150px; } 
div.sidenote-right { position: absolute; margin-left: 660px; } 

mais il sélectionne toujours le texte. La seule manière que je vois autour de ceci est de changer votre page dans un format de colonne de 2/3 où les notes latérales sont dans d'autres colonnes. Le seul problème avec ceci est que vous perdez la capacité de déplacer les notes par rapport au texte. Ou au moins je ne peux pas penser à un moyen de contourner cela.

+0

Le seul problème est que lorsque vous sélectionnez plusieurs paragraphes avec le sidenote au milieu, vous obtenez également le sidenote. Je ne sais pas comment cela pourrait être guéri, sauf avec javascript, cependant. (Dans le dom-prêt, vous pouvez le sortir dans un objet absolument positionné.) –

+0

Wonderful! Comment puis-je l'adapter à une largeur de page Web flexible? –

-1

Si vous êtes paresseux, utilisez un framework CSS! L'un des frameworks les plus simples que vous pouvez utiliser est 960.gs. Cela vous aidera à accomplir exactement ce que vous essayez de faire en quelques minutes.

Questions connexes