【问题标题】:Svg background width problem with background-sizeSVG背景宽度问题与背景大小
【发布时间】:2020-11-08 20:01:37
【问题描述】:

enter image description here

您好,我在设计中有一个宽度为 160 像素、宽度为 100% 的标题,我将它设置在一个 div 上,我将高度设置为 160 像素,当我想要但背景大小时:封面;宽度也会增加,高度也会增加,看起来像这样=>背景在底部被裁剪这是代码

  color: red;
  background-image: url(/photo.svg);
  background-repeat: no-repeat;
  height: 160px;
  background-size: cover;
}

【问题讨论】:

  • 我不允许发布图片,但可能很清楚我有什么问题
  • 我可以帮你张贴有问题的图片。需要帮助吗?
  • 是的,我需要你怎么做?
  • 通过编辑您的问题添加图片
  • 我不能大声笑。

标签: html css svg


【解决方案1】:

尝试使用 vw(视口宽度)和 vh(视口高度)来控制元素的尺寸。

比如:

.element {
    height: 20vh; // This is 20% of the viewport height.
    width: 100vh; // This is 100% of the viewport width.
}

更多关于 CSS 单元的信息在这里:https://www.w3schools.com/cssref/css_units.asp

【讨论】:

    猜你喜欢
    • 2014-08-04
    • 2017-07-05
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    相关资源
    最近更新 更多