canvas文本居中对齐_如何使用文本对齐来居中图像:居中
canvas文本居中对齐
An <img>
element is an inline element (display value of inline-block
). It can be easily centered by adding the text-align: center;
CSS property to the parent element that contains it.
<img>
元素是一个内联元素( inline-block
显示值)。 通过添加text-align: center;
可以很容易地将其text-align: center;
包含它的父元素CSS属性。
To center an image using text-align: center;
you must place the <img>
inside of a block-level element such as a div
. Since the text-align
property only applies to block-level elements, you place text-align: center;
on the wrapping block-level element to achieve a horizontally centered <img>
.
要使用text-align: center;
来居中图像text-align: center;
您必须将<img>
放置在块级元素(例如div
。 由于text-align
属性仅适用于块级元素,因此请放置text-align: center;
在包装块级元素上实现水平居中的<img>
。
例 (Example)
<!DOCTYPE html>
<html><head><title>Center an Image using text align center</title><style>.img-container {text-align: center;}</style></head><body><div class="img-container"> <!-- Block parent element --><img src="user.png" alt="John Doe"></div></body>
</html>
Note: The parent element must be a block element. If it is not a block element, you should add display: block;
CSS property along with the text-align
property.
注意:父元素必须是块元素。 如果不是block元素,则应添加display: block;
CSS属性以及text-align
属性。
<!DOCTYPE html>
<html><head><title>Center an Image using text align center</title><style>.img-container {text-align: center;display: block;}</style></head><body><span class="img-container"> <!-- Inline parent element --><img src="user.png" alt=""></span></body>
</html>
Demo: Codepen
演示: Codepen
对象拟合 (Object Fit)
Once your image is centered, you might want to resize it. The object-fit
property specifies how an element responds to the width / height of it’s parent box.
图像居中后,您可能需要调整其大小。 object-fit
属性指定元素如何响应其父框的宽度/高度。
This property can be used for image, video, or any other media. It can also be used with the object-position
property to get more control on how the media is displayed.
此属性可用于图像,视频或任何其他媒体。 它也可以与object-position
属性一起使用,以更好地控制媒体的显示方式。
Basically we use the object-fit
property to define how it stretch or squish an inline media.
基本上,我们使用object-fit
属性来定义其如何拉伸或压缩嵌入式媒体。
句法 (Syntax)
.element {object-fit: fill || contain || cover || none || scale-down;
}
价值观 (Values)
fill
: This is the default value. Resize the content to match its parent box regardless of the aspect-ratio.fill
: 这是默认值 。 调整内容的大小以匹配其父框,而不考虑纵横比。contain
: Resize the content to fill its parent box using the correct aspect-ratio.contain
:调整内容的大小以使用正确的宽高比填充其父框。cover
: similar ascontain
but often cropping the content.cover
:与contain
类似,但经常裁剪内容。none
: display the image in its original size.none
:以原始尺寸显示图像。scale-down
: compare the difference betweennone
andcontain
to find the smallest concrete object size.scale-down
:比较之间的差异none
和contain
找到最小的具体对象的大小。
浏览器兼容性 (Browser Compatibility)
The object-fit
is supported by most of the modern browsers, for the most updated info about compatibility you can check this out http://caniuse.com/#search=object-fit.
大多数现代浏览器都支持object-fit
,有关兼容性的最新信息,请访问http://caniuse.com/#search=object-fit 。
文献资料 (Documentation)
text-align - MDN
文字对齐 -MDN
object-fit - MDN
对象拟合 -MDN
<img> - MDN
<img> -MDN
翻译自: https://www.freecodecamp.org/news/how-to-center-an-image-using-text-align/
canvas文本居中对齐
canvas文本居中对齐_如何使用文本对齐来居中图像:居中相关推荐
- 文本分类模型_多标签文本分类、情感倾向分析、文本实体抽取模型如何定制?...
文心(ERNIE)是依托百度深度学习平台飞桨打造的语义理解技术与平台,集先进的预训练模型.全面的NLP算法集.端到端开发套件和平台化服务于一体,为企业和开发者提供一整套NLP定制与应用能力.在2020 ...
- mysql字节对齐_结构体字节对齐-位域及其对齐
字节对齐的准则:其实字节对齐的细节和具体编译器实现相关,但一般而言,满足三个准则: 1) 结构体变量的首地址能够被其最宽基本类型成员的大小所整除: 2) 结构体每个成员相对于结构体首地址的偏移量都是成 ...
- mysql字节对齐_结构体字节对齐(转)
结构体字节对齐 在用sizeof运算符求算某结构体所占空间时,并不是简单地将结构体中所有元素各自占的空间相加,这里涉及到内存字节对齐的问题.从理论上讲,对于任何变量的访问都可以从任何地址开始访问,但是 ...
- 文本摘要提取_了解自动文本摘要-1:提取方法
文本摘要提取 Text summarization is commonly used by several websites and applications to create news feed ...
- php文本域输出_如何在文本分类任务中Fine-Tune BERT
问 题 BERT在许多自然语言理解(NLU)任务中取得了惊人的成果,但它的潜力还有待充分挖掘.目前很少有如何能进一步提高BERT性能的研究,因此,如何通过一些技巧和方法最大限度的提升BERT在文本分类 ...
- js复制文本到剪贴板_如何将文本和图像固定到Windows 10的剪贴板历史记录
js复制文本到剪贴板 Windows 10 makes copy and paste more convenient with a feature called Clipboard history. ...
- java富文本传图片_使用富文本编辑器上传图片实例详解
富文本编辑器上传图片 一.导入kindeditor的js 二.将kindeditor与一个文本域textarea进行关联,即用textarea初始化一个kindeditor对象 itemaddedit ...
- 语义分析 文本矛盾点解析_关于解析文本的几点思考
语义分析 文本矛盾点解析 Yesterday I wrote about three course modules in Oslo, and the fact that most of the pre ...
- [css] 实现单行文本居中和多行文本左对齐并超出显示“...“
[css] 实现单行文本居中和多行文本左对齐并超出显示"-" .one {text-align: center }.multi {overflow: hiddentext-over ...
最新文章
- ExtJs2.0学习系列--Ext.Panel
- C# 调用C++ dll
- 大型网站的负载均衡器、db proxy和db
- PHP实现微信随机红包算法和微信红包的架构设计简介
- 在Mysql中显示所有用户的操作教程(Linux环境下)
- 周六——中国电影博物馆
- python certificate verify failed
- 机器视觉产品技术市场需求日益增长
- C语言学习输入输出函数,函数的调用
- 一天一个Java基础——序列化
- 给输入框添加自动检索的功能
- 台式电脑计算机能创建新磁盘吗,解决方案:如何添加硬盘以扩展台式计算机上的存储空间|如何对新添加的硬盘进行分区...
- 牛客练习赛29 F 算式子
- android获取进程名,android – 按包名查找正在运行的进程ID
- App Store、Steam、Google Play等出海应用、游戏如何收款到国内账户
- java堆栈类_JAVA 堆栈类(Stack)的使用
- Arduino uno读取mpu6050模块角度以及温度值
- 除尘器选型需要考虑的因素
- 公众号配置服务器信息在哪里,公众号服务器配置在哪
- excel行列值相同,交叉单元格高亮显示
热门文章
- 【AI视野·今日CV 计算机视觉论文速览 第195期】Tue, 11 May 2021
- 【今日CV 计算机视觉论文速览 第146期】Mon, 22 Jul 2019
- 算法—两个有序数组的中位数 Median of Two Sorted Arrays
- 文件的读操作 c# 1614526130
- private关键字 java 1613808402
- 对象交互。英雄搏击游戏。0107
- 数据结构与算法-什么是数据结构,什么是数据,什么是抽象数据类型
- Laravel 怎么查看执行的Sql语句
- Mysql查看某个表大小
- 360路由器刷openwrt后设置wifi中继