| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | id: 587d7791367417b2b2512ab3 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | title: 使用 text-align 属性创建视觉平衡 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | challengeType: 0 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:46:34 +08:00
										 |  |  | videoUrl: 'https://scrimba.com/c/c3b4EAp' | 
					
						
							|  |  |  | forumTopicId: 301053 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | dashedName: create-visual-balance-using-the-text-align-property | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --description--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 这部分课程的主题是应用视觉设计。 开始的挑战基于美化一个卡片组件的外观,借此展示了若干核心原则。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | web 内容大部分都是文本。 CSS 里面的 `text-align` 属性可以控制文本的对齐方式。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | `text-align: justify;` 可以让除最后一行之外的文字两端对齐,即每行的左右两端都紧贴行的边缘。 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | `text-align: center;` 可以让文本居中对齐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | `text-align: right;` 可以让文本右对齐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | `text-align: left;` 是默认值,它可以让文本左对齐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --instructions--
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 请让内容文本为 “Google” 的 `h4` 标签居中对齐, 然后将介绍 Google 创立历程的段落文本两端对齐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --hints--
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | `h4` 标签应有值为 `center` 的 text-align 属性。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert($('h4').css('text-align') == 'center'); | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2020-02-11 15:46:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | `p` 标签应有值为 `justify` 的 text-align 属性。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert($('p').css('text-align') == 'justify'); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | # --seed--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## --seed-contents--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   h4 { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   p { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .links { | 
					
						
							|  |  |  |     margin-right: 20px; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .fullCard { | 
					
						
							|  |  |  |     border: 1px solid #ccc; | 
					
						
							|  |  |  |     border-radius: 5px; | 
					
						
							|  |  |  |     margin: 10px 5px; | 
					
						
							|  |  |  |     padding: 4px; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .cardContent { | 
					
						
							|  |  |  |     padding: 10px; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | <div class="fullCard"> | 
					
						
							|  |  |  |   <div class="cardContent"> | 
					
						
							|  |  |  |     <div class="cardText"> | 
					
						
							|  |  |  |       <h4>Google</h4> | 
					
						
							|  |  |  |       <p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <div class="cardLinks"> | 
					
						
							|  |  |  |       <a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a> | 
					
						
							|  |  |  |       <a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --solutions--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | ```html | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   h4 { | 
					
						
							|  |  |  |     text-align: center; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   p { | 
					
						
							|  |  |  |     text-align: justify; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .links { | 
					
						
							|  |  |  |     margin-right: 20px; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .fullCard { | 
					
						
							|  |  |  |     border: 1px solid #ccc; | 
					
						
							|  |  |  |     border-radius: 5px; | 
					
						
							|  |  |  |     margin: 10px 5px; | 
					
						
							|  |  |  |     padding: 4px; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .cardContent { | 
					
						
							|  |  |  |     padding: 10px; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | <div class="fullCard"> | 
					
						
							|  |  |  |   <div class="cardContent"> | 
					
						
							|  |  |  |     <div class="cardText"> | 
					
						
							|  |  |  |       <h4>Google</h4> | 
					
						
							|  |  |  |       <p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <div class="cardLinks"> | 
					
						
							|  |  |  |       <a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a> | 
					
						
							|  |  |  |       <a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | ``` |