Gaz*_*aza 4 svg responsive-design responsiveness
我在网页中有一个 SVG,它由图像 + 文本组成
<object data="/infographic/timeline.svg" type="image/svg+xml">
<img src="/infographic/timeline.svg" alt="Timeline">
</object>
Run Code Online (Sandbox Code Playgroud)
所有的图像都是响应式的,但文本不是,所以文本变得非常非常小。
SVG 片段(大量的)
<defs>
<style>
.cls-1 {
font-size: 60.014px;
}
.cls-1, .cls-10 {
opacity: 0.69;
}
.cls-1, .cls-10, .cls-4, .cls-5, .cls-7, .cls-8, .cls-9 {
fill: #ffffff;
}
.cls-1, .cls-10, .cls-3, .cls-4, .cls-5, .cls-6, .cls-7, .cls-9 {
text-anchor: middle;
}
.cls-1, .cls-3, .cls-6 {
font-family: "Roboto";
}
.cls-2 {
font-size: 32.014px;
}
.cls-3 {
font-size: 14.089px;
}
.cls-3, .cls-6 {
fill: #db7426;
}
.cls-4, .cls-6 {
font-size: 32px!important;
}
.cls-10, .cls-4, .cls-5, .cls-7, .cls-8, .cls-9 {
font-family: Roboto;
}
.cls-5 {
font-size: 24px;
}
.cls-5, .cls-8, .cls-9 {
font-weight: 400;
}
.cls-6 {
font-weight: 600;
}
.cls-10, .cls-7 {
font-size: 18.75px;
font-weight: 300;
}
.cls-7 {
opacity: 0.4;
}
.cls-8, .cls-9 {
font-size: 22px;
}
</style>
</defs>
<text id="Who_are_you_what_do_you_do_what_s_your_why_What_s_been_keepi" data-name="Who are you, what do you do, what’s your why? What’s been keepi" class="cls-8" x="397.706" y="535.325">Who are you, what do you do, what’s your why?<tspan x="397.706" dy="26.4">What’s been keeping you lying awake at night. </tspan></text>
Run Code Online (Sandbox Code Playgroud)
无论如何,随着 SVG/屏幕宽度变小,我可以增加文本大小吗?
任何帮助将不胜感激。
纯 SVG 是不可能的(至少现在还没有)。唯一的解决方案是:
内联 SVG 并使用 javascript 操作文本的大小。
内联 SVG 并使用媒体查询控制文本的大小(见下文)。
将 CSS 添加到 SVG 并在那里使用媒体查询(见下文)。
当页面变小时使用媒体查询切换 SVG
选项 2 的示例:使用带有内联 SVG 的媒体查询
text {
font-size: 10px;
}
@media (max-width: 400px) {
text {
font-size: 20px;
}
}Run Code Online (Sandbox Code Playgroud)
<svg viewBox="0 0 100 100" width="100%" height="100%">
<circle cx="50" cy="50" r="50" fill="orange"/>
<text x="50" y="60" text-anchor="middle">Testing</text>
</svg>Run Code Online (Sandbox Code Playgroud)
选项 3 的示例:在 SVG 中使用 CSS 中的媒体查询
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100%" height="100%">
<style>
text {
font-size: 10px;
}
@media (max-width: 400px) {
text {
font-size: 20px;
}
}
</style>
<circle cx="50" cy="50" r="50" fill="orange"/>
<text x="50" y="60" text-anchor="middle">Testing</text>
</svg>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8599 次 |
| 最近记录: |