首页 > 其他分享 >css27 CSS Layout - width and max-width

css27 CSS Layout - width and max-width

时间:2024-06-01 11:10:28浏览次数:10  
标签:Layout 500px max element width auto div css27

https://www.w3schools.com/css/css_max-width.asp

 

CSS Layout - width and max-width

   

Using width, max-width and margin: auto;

As mentioned in the previous chapter; a block-level element always takes up the full width available (stretches out to the left and right as far as it can).

Setting the width of a block-level element will prevent it from stretching out to the edges of its container. Then, you can set the margins to auto, to horizontally center the element within its container. The element will take up the specified width, and the remaining space will be split equally between the two margins:

 

Note: The problem with the <div> above occurs when the browser window is smaller than the width of the element. The browser then adds a horizontal scrollbar to the page.

Using max-width instead, in this situation, will improve the browser's handling of small windows. This is important when making a site usable on small devices:

 

Tip: Resize the browser window to less than 500px wide, to see the difference between the two divs!

Here is an example of the two divs above:

Example

div.ex1 {
  width: 500px;
  margin: auto;
  border: 3px solid #73AD21;
}

div.ex2 {
  max-width: 500px;
  margin: auto;
  border: 3px solid #73AD21;
}

 

<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
  width: 500px;
  margin: auto;
  border: 3px solid #73AD21;
}

div.ex2 {
  max-width: 500px;
  margin: auto;
  border: 3px solid #73AD21;
}
</style>
</head>
<body>

<h2>CSS Max-width</h2>

<div class="ex1">This div element has width: 500px;</div>
<br>

<div class="ex2">This div element has max-width: 500px;</div>

<p><strong>Tip:</strong> Drag the browser window to smaller than 500px wide, to see the difference between 
the two divs!</p>

</body>
</html>

 

标签:Layout,500px,max,element,width,auto,div,css27
From: https://www.cnblogs.com/emanlee/p/18225696

相关文章

  • css17 CSS Height, Width
    https://www.w3schools.com/css/css_dimension.aspTheCSSheightandwidthpropertiesareusedtosettheheightandwidthofanelement.TheCSSmax-widthpropertyisusedtosetthemaximumwidthofanelement.Thiselementhasaheightof50pixelsand......
  • Golang初学:项目目录结构,project-layout 项目
    goversiongo1.22.1windows/amd64Windows11+amd64x86_64x86_64GNU/Linux--- 序章golang项目的代码要怎么组织?怎么放比较简洁易读?看下面这个项目就晓得了。 project-layouthttps://github.com/golang-standards/project-layout注,有时访问失败。特写文记录。......
  • GridLayout 等控件来完成多行按钮操作
     第一步,在布局文件中添加一个GridLayout控件,设置它的行列数和间距等属性,例如:<GridLayoutandroid:id="@+id/grid_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:columnCount="4"andr......
  • 测试 width="242" height="242"
    1  width="242"height="242"         ......
  • QPrinter、QPrinterInfo、QPageLayout
    QPrinter一、描述QPrinter类是在打印机上绘制的绘制设备,其使用方式与其他绘图设备(如QWidget和QPixmap)几乎完全相同。提供了一组附加功能来管理特定于设备的功能,例如方向、分辨率、在生成文档时逐步浏览文档中的页面。在无效打印机上设置参数(如纸张尺寸和分辨率)是未定义的。......
  • HTML 29 - Layouts
     TheHTMLLayoutsspecifiesthearrangementofcomponentsonanHTMLwebpage.Agoodlayoutstructureofthewebpageisimportanttoprovideauser-friendlyexperienceonourwebsite.Ittakesconsiderabletimetodesignawebsite'slayoutwithag......
  • HTML 30 - Layout Elements
     TheLayoutElementsofHTMLInHTML,therearevarioussemanticelementsthatareusedtodefinedifferentpartsofawebpagemakingitvisuallyappealinganduser-friendly.Thesesemanticelementsarecollectivelytermedaslayoutelements.Eacheleme......
  • HTML 31 - Layout using CSS
     NowweallhavelearnedvarioustechniquestodesignanHTMLlayoutincludingtablesandsemanticelements.Weareverymuchcomfortableandefficientatcreatinglayouts.Inthistutorial,wearegoingtolookathowCSSpropertieshelpinarrangingdi......
  • msvc 获取c++类内存布局 /d1 reportAllClassLayout
     visualstudio配置获取所有类内存布局/d1reportAllClassLayout或者指定类/d1reportSingleClassLayoutXXXclass  编译时输出:     ps:https://www.openrce.org/articles/full_view/23   【原文地址】https://blog.csdn.net/qq_29542611/article......
  • Vue3 vue-grid-layout布局添加右键事件
    示例code<template><divclass="dashboard-container"><ulclass='contextmenu'v-show="menuConfig.visible":style="{left:menuConfig.left+'px',top:menuConfig.top+'px'}">......