| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | id: 5a9036d038fddaf9a66b5d32 | 
					
						
							|  |  |  | title: Add Columns with grid-template-columns | 
					
						
							|  |  |  | challengeType: 0 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  | videoUrl: 'https://scrimba.com/p/pByETK/c7NzDHv' | 
					
						
							|  |  |  | forumTopicId: 301117 | 
					
						
							|  |  |  | localeTitle: 使用 grid-template-columns 添加多列 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Description
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  | <section id='description'> | 
					
						
							|  |  |  | 简单地添加一个网格元素并不会有任何明显的效果。你还需要明确网格的结构。在一个网格容器中使用<code>grid-template-columns</code>属性可以添加一些列,示例如下: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | .container { | 
					
						
							|  |  |  |   display: grid; | 
					
						
							|  |  |  |   grid-template-columns: 50px 50px; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 上面的代码可以在网格容器中添加两列,宽度均为 50px。 | 
					
						
							|  |  |  | <code>grid-template-columns</code>属性值的个数表示网格的列数,而每个值表示对应列的宽度。 | 
					
						
							|  |  |  | </section> | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Instructions
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  | <section id='instructions'> | 
					
						
							|  |  |  | 给网格容器设置三个列,每列宽度均为<code>100px</code>。 | 
					
						
							|  |  |  | </section> | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Tests
 | 
					
						
							|  |  |  | <section id='tests'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```yml | 
					
						
							|  |  |  | tests: | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  |   - text: '<code>container</code>类应该有<code>grid-template-columns</code>属性,该属性有三个值,均为<code>100px</code>。' | 
					
						
							| 
									
										
										
										
											2020-02-18 01:40:55 +09:00
										 |  |  |     testString: assert(code.match(/.container\s*?{[\s\S]*grid-template-columns\s*?:\s*?100px\s*?100px\s*?100px\s*?;[\s\S]*}/gi)); | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Challenge Seed
 | 
					
						
							|  |  |  | <section id='challengeSeed'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div id='html-seed'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   .d1{background:LightSkyBlue;} | 
					
						
							|  |  |  |   .d2{background:LightSalmon;} | 
					
						
							|  |  |  |   .d3{background:PaleTurquoise;} | 
					
						
							|  |  |  |   .d4{background:LightPink;} | 
					
						
							|  |  |  |   .d5{background:PaleGreen;} | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  |   .container { | 
					
						
							|  |  |  |     font-size: 40px; | 
					
						
							|  |  |  |     width: 100%; | 
					
						
							|  |  |  |     background: LightGray; | 
					
						
							|  |  |  |     display: grid; | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  |     /* 请在本行以下添加你的代码 */ | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     /* 请在本行以上添加你的代码 */ | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | </style> | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | <div class="container"> | 
					
						
							|  |  |  |   <div class="d1">1</div> | 
					
						
							|  |  |  |   <div class="d2">2</div> | 
					
						
							|  |  |  |   <div class="d3">3</div> | 
					
						
							|  |  |  |   <div class="d4">4</div> | 
					
						
							|  |  |  |   <div class="d5">5</div> | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Solution
 | 
					
						
							|  |  |  | <section id='solution'> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | ```js | 
					
						
							|  |  |  | // solution required | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | </section> | 
					
						
							| 
									
										
										
										
											2020-02-11 21:39:15 +08:00
										 |  |  |                |