figure{ max-width: 300px; max-width: min-content;//这个关键字将解析为这个容器内部最大的不可断行元素的宽度( 即最宽的单词、 图片或具备固定宽度的盒元素。 margin: auto; } figure > img{ max-width: inherit; } <p>Some text [...]</p> <figure> <img src="./2.jpg" alt=""> <figcaption> The great Sir Adam Catlace was named after Countess Ada Lovelace,the first programmer. </figcaption> </figure> <p>More Text[...]</p>
table{ table-layout:fixed; width:100%;
*:segmentfault
请注意, 为了确保这个技巧奏效, 须要为这 些表格元素指定一个宽度( 哪怕是 100%)。 一样, 为了让 text-overflow: ellipsis 发挥做用,咱们还须要为那一列指定宽度。
**:app
若是不指定任何宽度,则各列的宽度将是平均分配的;后续的表格行并不会影响列宽;给单元格指定很大的宽度也会直接生效,并不会自动缩小;overflow 和 text-overflow属性都是能够正常生效的;若是overflow 的值是 visible,则单元格的内容有可能会溢出.
li:only-child{ /* ...*/ } 或者 li:first-child:nth-last-child(1){ //括号中的1为参数 /* */ }
li:first-child:nth-last-child(4) //选中的是刚好有四个元素的第一个 li:first-child:nth-last-child(4) ~ li //能够用兄弟选择符选中刚好有四个元素时的所有四个
li:nth-child(n+4) //选中从第4个开始的全部元素
li:first-child:nth-last-child(n+4), li:first-child:nth-last-child(n+4)~li { /* ...*/ }//选中元素总数是4或更多时的全部元素
li:first-child:nth-last-child(-n+4), li:first-child:nth-last-child(-n+4)~li{ /* ..*/ }//仅元素少于等于4时选中全部元素
li:first-child:nth-last-child(n+2):nth-last-child(-n+6), li:first-child:nth-last-child(n+2):nth-last-child(-n+6) ~ li{ /* ...*/ }//元素数量处于2-6时选中全部元素
.hello { max-width: 900px; padding: 1em calc(50% - 450px);//取代内层元素的margin: auto; background: #333; } <div class="hello"> <div class="wrapper"> 66 </div> </div>
<main> <h1>Am I centered yet?</h1> <p>Center me, please!</p> </main>
main { position: absolute; top: 50%; left: 50%; margin-top: -3em; /* 6/2 = 3 */ margin-left: -9em; /* 18/2 = 9 */ width: 18em; height: 6em; }
main { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);//transform是根据自身尺寸为基准进行换算和移动的 }
main { width: 18em; padding: 1em 1.5em; margin: 50vh auto 0; transform: translateY(-50%); }
详情看:关于Flexboxspa
可参考:关于Flexboxcode