issue145:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue145:inkscape [2019/06/01 14:57] – créée auntiee | 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…** |
- | 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/ | + | 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' |
- | 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. | + | **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/ |
- | 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’, | + | |
+ | 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’, | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | <g inkscape: | ||
+ | <g id=" | ||
+ | <rect id=" | ||
+ | <path id=" | ||
+ | <path id=" | ||
+ | <text id=" | ||
+ | <tspan id=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Maintenant, c'est le moment de paramétrer les classes du CSS. L' | ||
<svg> | <svg> | ||
Ligne 20: | Ligne 43: | ||
</ | </ | ||
- | 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 < | ||
+ | |||
+ | 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' | ||
- | To keep the CSS a little clearer, it’s best to change the IDs of some objects, or give them classes | + | 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: |
+ | |||
+ | <g class=" | ||
+ | <rect /> | ||
+ | <path class=" | ||
+ | <path class=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Avec l' | ||
<g class=" | <g class=" | ||
Ligne 35: | Ligne 73: | ||
</g> | </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: |
+ | |||
+ | < | ||
+ | ... | ||
+ | < | ||
+ | .button > rect { | ||
+ | fill: #000080; | ||
+ | } | ||
+ | |||
+ | .button > .top-left { | ||
+ | fill: #ffffff; | ||
+ | } | ||
+ | |||
+ | .button > .bottom-right { | ||
+ | fill: #00002e; | ||
+ | } | ||
+ | |||
+ | .button > text { | ||
+ | fill: #a6a6ff; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <g inkscape: | ||
+ | ... | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Maintenant, c'est le moment d' | ||
<svg> | <svg> | ||
Ligne 62: | Ligne 127: | ||
</ | </ | ||
- | 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 < | ||
+ | |||
+ | N' | ||
- | 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 | + | 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. |
Here’s an example of the additional rule for the < | Here’s an example of the additional rule for the < | ||
Ligne 74: | Ligne 143: | ||
} | } | ||
- | 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=" |
- | 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): | + | 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): | ||
this.classList.toggle(' | this.classList.toggle(' | ||
Ligne 83: | Ligne 162: | ||
One advantage of wrapping everything in a group, and applying the code to that outer layer, is that clicks on any part of the button are passed through to the enclosing element. This avoids our previous problem whereby clicks on the text didn’t toggle the button. But we still have an issue with the text being selectable. We can address this with the ‘pointer-events’ CSS rule, which lets us tell the browser that all mouse activity over the text – including clicks and selection – should be ignored. Modify your first set of rules so that the last one looks like this: | One advantage of wrapping everything in a group, and applying the code to that outer layer, is that clicks on any part of the button are passed through to the enclosing element. This avoids our previous problem whereby clicks on the text didn’t toggle the button. But we still have an issue with the text being selectable. We can address this with the ‘pointer-events’ CSS rule, which lets us tell the browser that all mouse activity over the text – including clicks and selection – should be ignored. Modify your first set of rules so that the last one looks like this: | ||
+ | |||
+ | .button > text { | ||
+ | fill: #a6a6ff; | ||
+ | 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 { | .button > text { | ||
Ligne 89: | Ligne 181: | ||
} | } | ||
- | 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: |
.button { | .button { | ||
Ligne 95: | Ligne 187: | ||
} | } | ||
- | 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, | ||
+ | |||
+ | 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.** | ||
- | Previously, I said I would show you how to make clicks on one element have an effect on a completely different one, but I’ve run out of space in this article, | + | Précédemment, j'ai dit que je vous montrerais comment faire pour que les clics sur un élément aient un effet sur un élement complètement différent, mais je manque de place dans cet article |
- | Why not spend the next month designing ever more impressive buttons? There are plenty of tutorials online for different | + | Pourquoi ne pas passer le prochain mois à concevoir des boutons de plus en plus impressionnants |
issue145/inkscape.1559393826.txt.gz · Dernière modification : 2019/06/01 14:57 de auntiee