css max-width_CSS中的max-width属性

css max-width

CSS | 最大宽度属性 (CSS | max-width property)

The max-width property is used to help in setting the width of an element to the maximum. Although if the element or content is already larger than the maximum width then the height of that content or element will be changed.

max-width属性用于帮助将元素的宽度设置为最大。 尽管如果元素或内容已经大于最大宽度,则该内容或元素的高度将被更改。

The max-width property doesn't work on content which is smaller than the maximum width. The maximum width property overrides the width property. The default value of the max-width property is none. The width of the element can be measured in terms of %, px, cm or none.

max-width属性不适用于小于最大宽度的内容。 最大宽度属性将覆盖width属性。 max-width属性的默认值为none。 元素的宽度可以用% , px , cm或不测量 。

Syntax:

句法:

    Element
{
max-width : 50% / 50px /50cm etc.
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.element1 {
background-color: #f40;
color: #ffffff;
max-width: 50%;
}
.element2 {
background-color: #f40;
color: #ffffff;
max-width: 200px;
}
.element3 {
background-color: #f40;
color: #ffffff;
max-width: 300px;
}
</style>
</head>
<body>
<div class="element1">
<p>This is sample text in element1 DIV.</p>
</div>
<div class="element2">
<p>This is sample text in element2 DIV.</p>
</div>
<div class="element3">
<p>This is sample text in element3 DIV.</p>
</div>
</body>
</html>

Output

输出量

max-width property in CSS | Example 1

In the above example, there are three CSS classes element1, element2 and element3 and applied max-width are 50%, 200px and 300px respectively.

在上面的示例中,存在三个CSS类element1 , element2和element3,并且所应用的最大宽度分别为50% , 200px和300px 。

属性值 (Property values)

ValueDescription
noneThere is no maximum width. This is default.
lengthIt defines the maximum width in px, cm, etc.
%This is used to define the maximum width in percent of the containing block.
initialThis sets this property to its default value.
inheritThis inherits this property from its parent element.
描述
没有 没有最大宽度。 这是默认值。
长度 它以px,cm等为单位定义最大宽度。
这用于定义包含块的最大宽度(以百分比为单位)。
初始 将此属性设置为其默认值。
继承 这将从其父元素继承此属性。

Hence, the max-width property comes in handy when you want to style your element in a very specific manner i.e., to adjust the width.

因此,当您要以非常特定的方式(例如调整宽度)来设置元素样式时, max-width属性会派上用场。

Sometimes a website focuses more on its content for the audience, they want their content to be comprehensive and legible. Those websites tend to keep the width of their content a bit large.

有时,网站会更着重于面向受众的内容,他们希望其内容全面且清晰易读。 这些网站倾向于将其内容的宽度保持较大。

But not everywhere this property can be applied as you do not want your site to look clumsy or congested. Thus, one needs to be very careful while using this property to decide where to use it.

但是,并非所有地方都可以应用此属性,因为您不希望站点显得笨拙或拥挤。 因此,在使用此属性来决定在哪里使用它时需要非常小心。

翻译自: https://www.includehelp.com/code-snippets/max-width-property-in-css.aspx

css max-width

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540835.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

20个编写现代CSS代码的建议

本文翻译自Danny Markov 的20-Tips-For-Writing-Modern-CSS一文。 本文归纳于笔者的Web Frontend Introduction And Best Practices:前端入门与最佳实践中CSS入门与最佳实践系列&#xff0c;其他的关于CSS样式指南的还有提升你的CSS姿势、Facebook里是怎样提升CSS代码质量的。本…

android package.xml,Android自动化编译设置AndroidManifest.xml中package值(包名)

手动修改Android的AndroidManifest.xml中package值(包名)很简单&#xff0c;手动修改即可。但是项目中需要把Android的项目源代码放到服务器端在客户下载时候动态编译生成&#xff0c;且生成的app签名相同但包名不同(若此时包名相同就是相同的app)&#xff0c;这种需求需要在服…

css 相同的css属性_CSS中的order属性

css 相同的css属性CSS | 订单属性 (CSS | order Property) Introduction: 介绍&#xff1a; Web development is an ever-growing field that would never find its end, therefore it is equally necessary to learn new ways to deal with the elements of the web page or …

StoreServ的ASIC架构师必须面向未来做出决断

StoreServ阵列采用特殊硬件&#xff0c;即一套ASIC来加速存储阵列操作&#xff0c;而且其每代阵列都会在这方面进行重新设计。目前的设计为第五代。 作为惠普企业业务公司研究员兼StoreServ架构师&#xff0c;Siamak Nazari当下主要负责第六代ASIC的设计工作。 每代ASIC设计往往…

android网页省略分页器,Android轻量级网页风格分页器

博客同步自:个人博客主页轻量级仿网页风格分页器&#xff0c;和RecycleView封装一起配合使用&#xff0c;也可单独使用&#xff0c;喜欢就star、fork下吧&#xff5e;谢谢目录功能介绍效果图如何引入简单使用依赖github地址功能介绍支持延迟加载分页支持单独分页器组件使用&…

scala重载无参构造方法_Scala中的无参数方法

scala重载无参构造方法Scala无参数方法 (Scala parameterless method) A method which accepts no parameters from the calling code. It also denotes that there will not be any empty parentheses. These are special types of methods in Scala that are initialized and…

传统存储做到极致也惊人!看宏杉科技发布的CloudSAN

传统存储阵列首先考虑的是高可靠、高性能。那么在成本上、扩展上、部署上就差。 互联网企业带来分布式存储&#xff0c;扩展上、部署上是优势了&#xff0c;但是单节点的可靠性差、数据一致性差、IO延迟大、空间浪费严重&#xff0c;能耗大。 这两者的问题&#xff0c;我想很多…

android inflate,Android 关于inflate

通俗的说,inflate就相当于将一个xml中定义的布局找出来.因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageVie…

keil lic_LIC的完整形式是什么?

keil licLIC&#xff1a;印度人寿保险公司 (LIC: Life Insurance Corporation of India) LIC is an abbreviation of the Life Insurance Corporation of India. It is a public segment insurance and investment group corporation in India that generally deals with life …

“云”上存储初显规模 如何架构是关键

在安防系统中&#xff0c;存储设备只是给数据提供存储空间&#xff0c;数据存储的意义更多是为了给上层应用提供二次挖掘。目前的智能分析、大数据、图帧等技术都是基于数据存储做的数据挖掘。为了将二次挖掘应用的性能提升到最高&#xff0c;在优化分析算法的同时&#xff0c;…

在线图片转成html,在线将JPEG 转换成HTML。 免费将.jpeg 转换成.html。

描述|介绍JPEG – is a popular graphic format, which is characterized by a high degree of compression, which leads to a decrease in image quality. It uses the technology of encoding of smooth color renditions, providing the ability to reduce the amount of d…

密码学常用的算法填充模式_密码学的操作模式

密码学常用的算法填充模式Modes of operation of a block cipher are procedural rules for a generic block cipher. The different modes of operation result in different properties being achieved which add to the security of the underlying block cipher in the cry…

【干货】分享总结:MySQL数据一致性

0、导读 沃趣科技数据库工程师罗小波为大家全面分析如何保证MySQL的数据一致性。 1、活动总结 罗小波老师从MySQL的崩溃数据恢复安全性、MySQL复制原理及异步&semi sync复制原理、MySQL主从服务器如何保证数据一致性等多方面分析如何保证MySQL的数据一致性。 分享内容满满的…

设置html按钮点击事件无效果,css怎么设置按钮不能点击?

css怎么设置按钮不能点击&#xff1f;下面本篇文章就来给大家介绍一下使用CSS设置按钮不能点击的方法。有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对大家有所帮助。想要按钮不能点击可以通过设置按钮点击事件失效来实现&#xff1b;而在CSS中&…

计算机图形学与几何造型导论_计算机图形学导论

计算机图形学与几何造型导论历史 (History) The main forerunner sciences to the development of modern computer graphics were the advances in electrical engineering, electronics, and television that took place during the first half of the twentieth century whe…

android scrollview焦点,scrollview里面的edittext,当它获得焦点时如何滚动到edittext

在scrollview中有一个edittext。 (并且edittext上方的scrollview中还有其他视图。)当用户按下edittext时&#xff0c;键盘变得可见&#xff0c;并且scrollview的可见区域变得很小。因为edittext没有显示在屏幕上。 (它不会滚动滚动视图&#xff0c;以便显示编辑文本。)在用户按…

Linux中解压rar文件

Linux平台默认是不支持RAR文件的解压&#xff0c;需要安装linux版本的RAR压缩软件&#xff0c;下载地址为&#xff1a;http://www.rarlab.com/download.htm 下载之后进行解压之后&#xff0c;进入rar目录&#xff0c;运行make指令进行安装&#xff1a; [rootlocalhost rar]# ls…

kotlin 查找id_Kotlin程序查找立方体区域

kotlin 查找idA cube has 6 square faces, if edges length is side. Then the area of each square is side2, thus, the area of cube will be 6*sise2. 如果边的长度为side &#xff0c;则一个立方体有6个正方形的面。 那么每个正方形的面积是边2 &#xff0c;因此&#xff…

Python自动化运维之高级函数

一、协程1.1协程的概念协程&#xff0c;又称微线程&#xff0c;纤程。英文名Coroutine。一句话说明什么是线程&#xff1a;协程是一种用户态的轻量级线程。&#xff08;其实并没有说明白~&#xff09;那么这么来理解协程比较容易&#xff1a;   线程是系统级别的&#xff0c;…

android 继承listview,Android listView 继承ListActivity的用法

Android listView 继承ListActivity的用法 在手机中经常有列表方式。如果Activity中只有唯⼀⼀个List(这也是通常的情况)&#xff0c;可以继承ListActivity来实现。我们用两个例子来学习List。List例子⼀&#xff1a;利用Android自带的List格式步骤⼀&#xff1a;Android XML文…