background-size

How to emulate background-size: cover on <img>?

孤者浪人 提交于 2019-11-27 10:50:57
How can I resize and reposition the image inside a box, in such way that it covers the entire box, similar to how background-size: cover works. <div class="box" style="width: 100px; height: 100px;"> <img src="pic.jpg" width="413" height="325"> </div> I know I have to add overflow:hidden to the box and the image needs position: absolute . But what's the formula that gets me the right new size for the image, and left + top positions? this may be easier jQuery $('.box').each(function() { //set size var th = $(this).height(),//box height tw = $(this).width(),//box width im = $(this).children('img'

python 之 前端

我们两清 提交于 2019-11-27 08:38:21
11.38 css三大特性 11.381 继承性 1、定义:给某一个元素设置一些属性,该元素的后代也可以使用,这个我们就称之为继承性​2、注意: 1、只有以color、font-、text-、line-开头的属性才可以继承 2、a标签的文字颜色和下划线是不能继承别人的 3、h标签的文字大小是不能继承别人的,会改变,但是会在原来字体大小的基础上改变 ps:打开浏览器审查元素可以看到一些inherited from...的属性3、应用场景: 通常基于继承性统一设置网页的文字颜色,字体,文字大小等样式 11.382 层叠性 定义:CSS全称:Cascading StyleSheet层叠样式表,层叠性指的就是CSS处理冲突的一种能力,即如果有多个选择器选中了同一个标签那么会有覆盖效果​注意:1、层叠性只有在多个选择器选中了同一个标签,然后设置了相同的属性,才会发生层叠性 11.383 优先级 1、定义:当多个选择器选中同一个标签,并且给同一个标签设置相同的属性时,如何层叠就由优先级来确定2、优先级 整体优先级从高到底:行内样式>嵌入样式>外部样式1、大前提:直接选中 > 间接选中(即继承而来的)2、如果都是间接选中,那么离目标标签比较近的优先级高,就近原则3、如果都是直接选中,并且都是同类型的选择器,那么写在后面的优先级高4、如果都是直接选中,并且是不同类型的选择器

Mobile Webkit browser (chrome) address bar changes $(window).height(); making background-size:cover rescale every time

六月ゝ 毕业季﹏ 提交于 2019-11-27 01:41:52
问题 The problem is that I have a few DIV's positioned absolutely which have background-size: cover; and their height is calculated by javascript to fill 100% of viewport. On every desktop browser and mobile firefox everything is fine, but on mobile chrome address bar (upon appearing/disappearing) changes $(windows).height(); value. That results in quirky background image rescaling every time it does that. Is there a workaround to always display address bar (so the window height value wouldn't

Background-size with SVG squished in IE9-10

三世轮回 提交于 2019-11-27 00:33:41
I have a div set with a background image: <div>Play Video</div> with the following CSS: div { background-image: url('icon.png'); background-image: url('icon.svg'), none; background-size: 40px 40px; background-repeat: no-repeat; background-position: 90% 50%; padding: 20px; width: 150px; } The background size is respected in Firefox, Safari and Chrome. In IE8, the SVG is replaced by the PNG file. However, in IE9 and IE10, the SVG file is drastically sized down. The problem seems to be linked to the width and height of the div. If I add a height of 150px, the SVG is rendered properly. If I make

background-size: cover not working in portrait on Android tablet

蓝咒 提交于 2019-11-27 00:03:14
问题 I'm using the background-size property for a full width and height background image but having trouble getting it to fully cover in Chrome on a Nexus7 tablet in portrait view. It only covers the width and not the height i.e. there is about 200px of white space below it. However when I view the site in desktop Chrome (or anything else) and on a vertical monitor to emulate portrait dimensions it covers no problem. Anyone have a solution? CSS: html { background: url(/images/post_bg.jpg) no

CSS background-size: cover + background-attachment: fixed clipping background images

你离开我真会死。 提交于 2019-11-26 16:16:32
I have a list of figures containing background images. Something like the following: <ul> <li> <figure style="background-image: url(...);"></figure> </li> <li> <figure style="background-image: url(...);"></figure> </li> <li> <figure style="background-image: url(...);"></figure> </li> </ul> Each of these images has their background-size set to cover and background-attachment set to fixed . figure { width: 100%; height: 100%; background-size: cover; background-attachment: fixed; } When each of the figures takes up the entire viewport, this works fine, but if there is an offset of any kind the

CSS background-size: cover + background-attachment: fixed clipping background images

大憨熊 提交于 2019-11-26 04:46:58
问题 I have a list of figures containing background images. Something like the following: <ul> <li> <figure style=\"background-image: url(...);\"></figure> </li> <li> <figure style=\"background-image: url(...);\"></figure> </li> <li> <figure style=\"background-image: url(...);\"></figure> </li> </ul> Each of these images has their background-size set to cover and background-attachment set to fixed . figure { width: 100%; height: 100%; background-size: cover; background-attachment: fixed; } When

移动WEB开发笔记

…衆ロ難τιáo~ 提交于 2019-11-26 04:43:16
vertical-align: middle;设置图片居中 移动WEB开发 视口viewport(显示网页的屏幕区域) 布局视口 layout viewport 字太小,手动缩放网页 视觉视口 visual viewport 左右滑动看 理想视口 ideal viewport 理想视口 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,minimum-scale=1.0,user-scalable=no"> 物理像素 /物理像素比(DPR) 物理像素 :屏幕显示的最小颗粒 屏幕分辨率 物理像素比:1px能显示的物理像素点的个数 背景缩放background-size background-size:宽度 高度; background-size:宽度;高度等比缩放 background-size:百分比;相对父盒子来说 background-size:contain;一个边顶满盒子,就不在缩放,可能留白/等比缩放 background-size:cover;两个边全部顶满,完全覆盖盒子,可能显示不全/等比缩放 css3移动端盒子模型 box-sizing: border-box; padding 和border不会撑开盒子 清除高亮: tap

用CSS新属性实现特殊的图片显示效果

自闭症网瘾萝莉.ら 提交于 2019-11-26 01:53:22
1 概述 1.1 前言 使用一个或多个图像相关的CSS属性(background-blend-mode, mix-blend-mode, or filter)可以实现许多特殊的图片显示效果。本文转载自Bennett Feely的个人网站,文中共列举了20种图片显示效果。 详细代码及英文原文请访问 Bennett Feely的主页 。 2 效果列表 2.1 铅笔画效果 效果示例 SCSS代码 .pencil-effect { $url : url(photo.jpg); background-image: $url; background-size: cover; background-position: center; @supports (filter: invert(1)) and (background-blend-mode: difference) { background-image: $url, $url; background-blend-mode: difference; background-position: calc(50% - 1px) calc(50% - 1px), calc(50% + 1px) calc(50% + 1px); filter: brightness(2) invert(1) grayscale(1); box-shadow:

用CSS新属性实现特殊的图片显示效果

青春壹個敷衍的年華 提交于 2019-11-26 01:53:15
1 概述 1.1 前言 使用一个或多个图像相关的CSS属性(background-blend-mode, mix-blend-mode, or filter)可以实现许多特殊的图片显示效果。本文转载自Bennett Feely的个人网站,文中共列举了20种图片显示效果。 详细代码及英文原文请访问 Bennett Feely的主页 。 2 效果列表 2.1 铅笔画效果 效果示例 SCSS代码 .pencil-effect { $url : url(photo.jpg); background-image: $url; background-size: cover; background-position: center; @supports (filter: invert(1)) and (background-blend-mode: difference) { background-image: $url, $url; background-blend-mode: difference; background-position: calc(50% - 1px) calc(50% - 1px), calc(50% + 1px) calc(50% + 1px); filter: brightness(2) invert(1) grayscale(1); box-shadow: