简体   繁体   English

响应Svg图标

[英]Responsive Svg Icons

Hi I have page where I use responsive svgs as icons. 嗨,我有页面,我使用响应svgs作为图标。 Here is the js.fiddle: 这是js.fiddle:

https://jsfiddle.net/4yp65vu0/ https://jsfiddle.net/4yp65vu0/

Pay attention to this CSS: 请注意以下CSS:

.svg-content2 {
   display:inline-block;
   position:absolute;
   top:0;
   left:0;
   border:1px solid red;
}

.svg-container2 {
   display:inline-block;
   position:relative;
   width:100%;
   padding-bottom:100%;
   vertical-align:middle;
   border:1px solid red;
}

and the HTML: 和HTML:

<div class="row">
   <div class="col half">
      <div class="svg-container2">
         <object data="images/money_ico.svg" type="image/svg+xml" width="30%"                         height="30%" class="svg-content2"> 
         </object>
      </div>
      <span class="benefits">Charge your own<br>rates per minute</span>
   </div>

I've put a red border around the svg icons and also the surrounding containers. 我在svg图标和周围的容器周围放了一个红色边框。 In order for them to be responsive, I've positioned them absolutely inside a relative div, with padding-bottom equals proportions ratio trick. 为了使它们具有响应性,我将它们放在一个相对的div中,其中padding-bottom等于比例比例。 The svg_contatiner2 however, fills the entire column width. 但是,svg_contatiner2会填充整个列宽。 I just want to snugly fit the svg icons and have the text bump up without the huge amount of space. 我只是想贴合svg图标,让文字在不占用大量空间的情况下提升。

You need to add the CSS property clear:both; 你需要添加CSS属性clear:both; on your CSS rule .row 在您的CSS规则.row

https://jsfiddle.net/4yp65vu0/3/ https://jsfiddle.net/4yp65vu0/3/

.row {
    clear:both;
}

The clear:both; clear:both; will allow your .row class to keep its row layout without having elements collapse into each other. 将允许您的.row类保持其行布局,而不会让元素相互折叠。

More info on the CSS clear property: 有关CSS clear属性的更多信息:

https://developer.mozilla.org/en-US/docs/Web/CSS/clear https://developer.mozilla.org/en-US/docs/Web/CSS/clear

The clear CSS property specifies whether an element can be next to floating elements that precede it or must be moved down (cleared) below them. clear CSS属性指定元素是否可以在其前面的浮动元素旁边,或者必须在它们下面向下移动(清除)。 The clear property applies to both floating and non-floating elements. clear属性适用于浮动和非浮动元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM