issue145:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue145:inkscape [2019/06/10 08:33] – d52fr | issue145:inkscape [2019/06/13 16:29] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**A quick recap on where we got to last time: using CSS classes, we were able to toggle the style of a button by clicking on it. But it worked well only for a simple button with no content. If you clicked on the text inside the button, the toggle wouldn’t work. And you were still able to select the text, which is less than ideal for a button. What we really want to do is to group together several objects, and have a click on any of them act as a trigger for the button. And, with a little more CSS, we can deal with the selectable text issue, too. So let’s begin in Inkscape, by designing a fancier button…** | **A quick recap on where we got to last time: using CSS classes, we were able to toggle the style of a button by clicking on it. But it worked well only for a simple button with no content. If you clicked on the text inside the button, the toggle wouldn’t work. And you were still able to select the text, which is less than ideal for a button. What we really want to do is to group together several objects, and have a click on any of them act as a trigger for the button. And, with a little more CSS, we can deal with the selectable text issue, too. So let’s begin in Inkscape, by designing a fancier button…** | ||
+ | |||
+ | Récapitulons rapidement ce que nous avons vu la dernière fois : en utilisant les classes du CSS, nous avons été capables de basculer le style d'un bouton en cliquant dessus. Mais ça ne marchait bien que si le bouton ne contenait rien. Si vous cliquiez sur le texte à l' | ||
**This button is made up of four objects, each of which has a solid fill color so there are no stroke colors to worry about. When toggled, we’d like to change the background and text colors, and give the impression of the button being ‘pressed in’ by making the top/left object dark and the bottom/ | **This button is made up of four objects, each of which has a solid fill color so there are no stroke colors to worry about. When toggled, we’d like to change the background and text colors, and give the impression of the button being ‘pressed in’ by making the top/left object dark and the bottom/ | ||
We’re going to put the entire button into a single group. This isn’t strictly necessary, as Inkscape’s layers are already SVG group objects, but does make it a little easier to work with if we want to add more than one button (or other objects) to a single layer.** | We’re going to put the entire button into a single group. This isn’t strictly necessary, as Inkscape’s layers are already SVG group objects, but does make it a little easier to work with if we want to add more than one button (or other objects) to a single layer.** | ||
+ | |||
+ | Ce bouton est constitué de quatre objets, chacun d'eux ayant une couleur de fond unie et aucune couleur de contour. Lors d'un basculement, | ||
+ | |||
+ | Nous mettons tout le bouton dans un seul groupe. Ce n'est pas strictement nécessaire, | ||
**Now it’s time to set up the CSS classes. The basic idea is that we will give the outer group a class of ‘button’, | **Now it’s time to set up the CSS classes. The basic idea is that we will give the outer group a class of ‘button’, | ||
Ligne 20: | Ligne 26: | ||
</g> | </g> | ||
</ | </ | ||
+ | |||
+ | Maintenant, c'est le moment de paramétrer les classes du CSS. L' | ||
+ | |||
+ | <svg> | ||
+ | ... | ||
+ | <g inkscape: | ||
+ | <g id=" | ||
+ | <rect id=" | ||
+ | <path id=" | ||
+ | <path id=" | ||
+ | <text id=" | ||
+ | <tspan id=" | ||
+ | </ | ||
+ | </g> | ||
+ | </g> | ||
+ | </ | ||
**It’s all pretty much as you might expect: a <g> (the layer in Inkscape) containing a <g> (our button) which contains the four objects from the table above. There’s a slight oddity in terms of the < | **It’s all pretty much as you might expect: a <g> (the layer in Inkscape) containing a <g> (our button) which contains the four objects from the table above. There’s a slight oddity in terms of the < | ||
To keep the CSS a little clearer, it’s best to change the IDs of some objects, or give them classes to better describe what they do. Otherwise, trying to remember which < | To keep the CSS a little clearer, it’s best to change the IDs of some objects, or give them classes to better describe what they do. Otherwise, trying to remember which < | ||
+ | |||
+ | C'est à peu près tout ce que vous pouviez espérer : un <g> (le calque dans Inkscape) contenant un <g> (notre bouton) qui contient les quatre objets du tableau ci-dessus. Il y a une légère bizarrerie dans les termes de l' | ||
+ | |||
+ | Pour garder le CSS un peu plus clair, il vaut mieux changer l' | ||
**With the addition of a class for the button group, and one each for the paths, we’ve basically got this structure: | **With the addition of a class for the button group, and one each for the paths, we’ve basically got this structure: | ||
Ligne 35: | Ligne 61: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | Avec l' | ||
+ | |||
+ | <g class=" | ||
+ | <rect /> | ||
+ | <path class=" | ||
+ | <path class=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </g> | ||
**Now it’s time to add our CSS rules. We’ll use the immediate child selector (>) to ensure that these rules apply only to elements inside our button, so there’s no danger of all the text in the document becoming blue. Compare these rules with the table earlier in this document and you should be able to see what they’re doing: | **Now it’s time to add our CSS rules. We’ll use the immediate child selector (>) to ensure that these rules apply only to elements inside our button, so there’s no danger of all the text in the document becoming blue. Compare these rules with the table earlier in this document and you should be able to see what they’re doing: | ||
Ligne 62: | Ligne 99: | ||
</g> | </g> | ||
</ | </ | ||
+ | |||
+ | Maintenant, c'est le moment d' | ||
+ | |||
+ | <svg> | ||
+ | ... | ||
+ | < | ||
+ | .button > rect { | ||
+ | fill: #000080; | ||
+ | } | ||
+ | |||
+ | .button > .top-left { | ||
+ | fill: #ffffff; | ||
+ | } | ||
+ | |||
+ | .button > .bottom-right { | ||
+ | fill: #00002e; | ||
+ | } | ||
+ | |||
+ | .button > text { | ||
+ | fill: #a6a6ff; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <g inkscape: | ||
+ | ... | ||
+ | </g> | ||
+ | </ | ||
**Don’t forget to also remove any explicit fill and color properties in the ‘style’ attributes of your elements (including the < | **Don’t forget to also remove any explicit fill and color properties in the ‘style’ attributes of your elements (including the < | ||
Take a careful look at each CSS rule to make sure you understand what’s happening. Pay particular attention to the difference between an element selector (eg. ‘rect’) and a class selector (with a dot – eg. ‘.button’). So, in this case, ‘.button > rect’ (matches any < | Take a careful look at each CSS rule to make sure you understand what’s happening. Pay particular attention to the difference between an element selector (eg. ‘rect’) and a class selector (with a dot – eg. ‘.button’). So, in this case, ‘.button > rect’ (matches any < | ||
+ | |||
+ | N' | ||
+ | |||
+ | Vérifiez attentivement chaque règle du CSS pour vous assurer que vous comprenez ce qui arrive. Soyez particulièrement attentif à la différence entre un sélecteur d' | ||
**If everything is working okay at this point, it’s time to add another set of rules that will apply when the <g> has both the ‘button’ and the ‘clicked’ classes set. In this case, you just have to concatenate the class selectors – but make sure not to add any spaces between them, as that signifies an ancestor-descendent relationship. Yeah, the syntax of CSS really is that terse. | **If everything is working okay at this point, it’s time to add another set of rules that will apply when the <g> has both the ‘button’ and the ‘clicked’ classes set. In this case, you just have to concatenate the class selectors – but make sure not to add any spaces between them, as that signifies an ancestor-descendent relationship. Yeah, the syntax of CSS really is that terse. | ||
Ligne 76: | Ligne 144: | ||
You can test your new CSS rules by manually adding an extra ‘clicked’ class to the group (so that it reads class=" | You can test your new CSS rules by manually adding an extra ‘clicked’ class to the group (so that it reads class=" | ||
+ | |||
+ | Si tout fonctionne bien à ce stade, c'est le moment d' | ||
+ | |||
+ | Voici un exemple de règle additionnelle pour le < | ||
+ | |||
+ | .button.clicked > rect { | ||
+ | fill: #800000; | ||
+ | } | ||
+ | |||
+ | Vous pouvez tester manuellement vos nouvelles règles du CSS en ajoutant une classe « clicked » supplémentaire au groupe (ce qui se lit class=" | ||
**Open the file in Inkscape and select the group that represents the button. In the Object Properties dialog, expand the ‘interactivity’ section and add the following one-liner to the ‘onclick’ field (this should be familiar from last month’s column): | **Open the file in Inkscape and select the group that represents the button. In the Object Properties dialog, expand the ‘interactivity’ section and add the following one-liner to the ‘onclick’ field (this should be familiar from last month’s column): | ||
Ligne 89: | Ligne 167: | ||
pointer-events: | pointer-events: | ||
}** | }** | ||
+ | |||
+ | Ouvrez le fichier dans Inkscape et sélectionnez le groupe qui représente le bouton. Dans le dialogue des Propriétés de l' | ||
+ | |||
+ | this.classList.toggle(' | ||
+ | |||
+ | Enregistrez votre fichier, chargez-le dans votre navigateur et, si tout se passe comme il faut, vous trouverez qu'en cliquant sur le bouton il bascule entre les deux états. | ||
+ | |||
+ | L' | ||
+ | |||
+ | .button > text { | ||
+ | fill: #a6a6ff; | ||
+ | pointer-events: | ||
+ | } | ||
**That deals with the selectability problem, but we can go a step further in making our button seem clickable. By adding a ‘cursor’ property to the group itself, we can make the mouse pointer change when it moves over the button. Add this rule to the CSS: | **That deals with the selectability problem, but we can go a step further in making our button seem clickable. By adding a ‘cursor’ property to the group itself, we can make the mouse pointer change when it moves over the button. Add this rule to the CSS: | ||
Ligne 97: | Ligne 188: | ||
Save, reload, and move your mouse pointer over the button to see the effect.** | Save, reload, and move your mouse pointer over the button to see the effect.** | ||
+ | |||
+ | Le problème de sélectivité est ainsi résolu, mais nous pouvons aller un peu plus loin en faisant que notre bouton paraisse cliquable. En ajoutant la propriété « cursor » (curseur) au groupe lui-même, nous pouvons faire changer le pointeur de la souris quand il passe sur le bouton. Ajoutez cette règle au CSS : | ||
+ | |||
+ | .button { | ||
+ | cursor: pointer; | ||
+ | } | ||
**Previously, | **Previously, | ||
Why not spend the next month designing ever more impressive buttons? There are plenty of tutorials online for different styles if you’re stuck for inspiration. You don’t just have to make them toggle when clicked: a common effect is to apply a class in the ‘onmouseover’ field, and remove it in the ‘onmouseout’. You could even go the whole hog and create a button that has both a mouseover effect and a click effect. And next time, I promise, I will show you how to hook your new buttons up to other elements on your page.** | Why not spend the next month designing ever more impressive buttons? There are plenty of tutorials online for different styles if you’re stuck for inspiration. You don’t just have to make them toggle when clicked: a common effect is to apply a class in the ‘onmouseover’ field, and remove it in the ‘onmouseout’. You could even go the whole hog and create a button that has both a mouseover effect and a click effect. And next time, I promise, I will show you how to hook your new buttons up to other elements on your page.** | ||
+ | |||
+ | Précédemment, | ||
+ | |||
+ | Pourquoi ne pas passer le prochain mois à concevoir des boutons de plus en plus impressionnants ? Il y a plein de tutoriels en ligne pour différents styles si vous manquez d' |
issue145/inkscape.1560148397.txt.gz · Dernière modification : 2019/06/10 08:33 de d52fr