HTML5 and CSS: 31-40

31 - Use HTML5 to Require a Field

  • 使用這個 input required 屬性,使用者就不能以空白提交資料

<form action="/submit-cat-photo">
  <input type="text" placeholder="cat photo URL" required>
  <button type="submit">Submit</button>  
</form>

Submit

32 - Create a Set of Radio Buttons

  • radio button 單選按鈕

  • 單選按鈕只是input輸入框的一種類型。

  • 每一個單選按鈕都應該嵌套在它自己的label(標簽)元素中。

  • 注意:所有關聯的單選按鈕應該使用相同的name屬性。

  • 這一題我覺得怪怪的 orz

參考資料

應該 <label></label> 像是單純顯示的文字,但和 input 又有點關係。看其他的範例,都是 label 裡面要再設定 for=""。因此我推測,如果將 input 放到 label 裡面 nesting,就可以省去這些設定

33 - Create a Set of Checkboxes

34 - Check Radio Buttons and Checkboxes by Default

  • 在 input 新增 checked 屬性,就會默認被選中

35 - Nest Many Elements within a Single Div Element

  • div 竟然這麼後面才提到 @@

  • 主要用途是,包裹內容用的容器,方便之後排版

36 - Give a Background Color to a Div Element

37 - Set the ID of an Element

  • id 在 html 元素中是唯一的

  • <h2 id="cat-photo-form">

38 - Use an ID Attribute to Style an Element

  • id 竟然這麼後面才說

39 - Adjusting the Padding of an Element

  • padding 內邊距

  • border 邊框

  • margin 外邊距

40 - Adjust the Margin of an Element

.injected-text { margin-bottom: -25px; text-align: center; }

.box { border-style: solid; border-color: black; border-width: 5px; text-align: center; }

.yellow-box { background-color: yellow; padding: 10px; }

.red-box { background-color: red; padding: 20px; margin: 20px; }

.green-box { background-color: green; padding: 20px; margin: 20px; } </style>

margin

padding

padding

Last updated

Was this helpful?