Documente Academic
Documente Profesional
Documente Cultură
</svg>
And we’re going to reference the logo using an <img> tag like so:
<img src="logo.svg" alt="Logo" />
At this point, it’s time to point out that the sizes specified in the media queries refer to
the size of the SVG viewport, except for when the SVG is embedded inline in the
document using an <svg> tag. The SVG viewport is defined by the dimensions of the
element referencing the SVG. For example, in the case when the SVG is referenced in
an img tag, the width and height of the img specify the viewport. In other words, the
conditions specified in the media queries apply to the img tag, so that (width: 30em) would
apply styles to the SVG when the img is 30em wide.
That said, here is the markup for the SVG. Each of the elements inside it has an ID
that we’re going to use in the CSS to select and style it:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 194 186">
<path id="curved_bg" fill="#195463" d="..."/>
<g id="primary_content" fill="#ECECEC">
<path id="icon" d="..."/>
<path id="inner-circle" d="..."/>
<path id="middle-circle" d="..."/>
</g>
<g id="secondary_content" fill="#ECECEC">
<path id="bottom-text" d="..."/>
<path id="upper-text" d="..."/>
<path id="outer-circle" d="..."/>
<circle id="left-dot" cx="31.1" cy="91.5" r="3"/>
<circle id="right-dot" cx="163.4" cy="91.5" r="3"/>
</g>
</svg>
Using a <style> tag inside the SVG, we’re going to specify the media queries that will
change the SVG’s styles depending on the size of the viewport. The SVG will change
as shown in the following image:
We’re only going to be using the CSS fill and opacity properties. As the viewport size
decreases, the curvy background is first removed by setting its opacity to zero, and the
fill color of the remaining content of the SVG is changed from white to dark navy. As
the screen gets smaller, the text part of the logo is removed so that it takes up less
screen estate. And finally, the circle surrounding the icon is removed and only the
anchor icon remains on very small screens.
Adding the media queries, our SVG file looks like this:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 194 186">
<style>
svg * {
transition: fill .1s ease-out, opacity .1s ease-out;
}
@media all and (max-width: 250px) {
#curved_bg {
opacity: 0;
}
#secondary_content, #primary_content {
fill: #195463;
}
}
@media all and (max-width: 200px) {
#secondary_content {
opacity: 0;
}
}
@media all and (max-width: 150px) {
#inner-circle, #middle-circle {
opacity: 0;
}
}
</style>
<path id="curved_bg" fill="#195463" d="..."/>
</svg>
First, I added a transition to the elements inside the SVG so that they fade in and out
and change color smoothly over the course of 0.1 seconds. Then, for each media
query, part of the SVG is hidden.