Free Code Camp - practice
  • Introduction
  • Getting Start
    • Introduction
    • Join the Free Code Camp Community
    • 實做成果
  • Front End Development Certification
    • HTML5 and CSS
      • HTML5 and CSS: 01-10
      • HTML5 and CSS: 11-20
      • HTML5 and CSS: 21-30
      • HTML5 and CSS: 31-40
      • HTML5 and CSS: 41-50
      • HTML5 and CSS: 51-
    • Responsive Design with Bootstrap
      • Bootstrap 01-10
      • Bootstrap 11-20
      • Bootstrap 21-31
    • Gear up for Success
    • jQuery
    • Basic Front End Development Projects
    • Basic JavaScript
      • Basic JavaScript 030
      • Basic JavaScript 060
      • Basic JavaScript 090
      • Basic JavaScript 101
    • Object Oriented and Functional Programming
    • Basic Algorithm Scripting
    • JSON APIs and Ajax
    • Intermediate Front End Development Projects
    • Intermediate Algorithm Scripting
Powered by GitBook
On this page
  • margin
  • padding
  • padding

Was this helpful?

  1. Front End Development Certification
  2. HTML5 and CSS

HTML5 and CSS: 31-40

PreviousHTML5 and CSS: 21-30NextHTML5 and CSS: 41-50

Last updated 5 years ago

Was this helpful?

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,就可以省去這些設定

<form action="/submit-cat-photo">

    <label> <input type="radio" name="indoor-outdoor"/>indoor</label>
    <label><input type="radio" name="indoor-outdoor">outdoor</label>

  <button type="submit">Submit</button>
</form>

33 - Create a Set of Checkboxes

  • 複選

<form action="/submit-cat-photo">
  <label><input type="checkbox" name="personality"> 內向</label>
  <label><input type="checkbox" name="personality"> 外向</label>
  <label><input type="checkbox" name="personality"> 神經</label>
  <input type="text" placeholder="cat photo URL" required>
  <button type="submit">Submit</button>
</form>

34 - Check Radio Buttons and Checkboxes by Default

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

    <form action="/submit-cat-photo">
    <label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
    <label><input type="radio" name="indoor-outdoor"> Outdoor</label>
    <label><input type="checkbox" name="personality" checked> Loving</label>
    <label><input type="checkbox" name="personality"> Lazy</label>
    <label><input type="checkbox" name="personality"> Energetic</label>
    <input type="text" placeholder="cat photo URL" required>
    <button type="submit">Submit</button>
    </form>

35 - Nest Many Elements within a Single Div Element

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

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

<div>
  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
</div>

36 - Give a Background Color to a Div Element

<style>
  .silver-background {
    background-color: silver;
  }
</style>

<div class="silver-background">
  <p >Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
</div>

37 - Set the ID of an Element

  • id 在 html 元素中是唯一的

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

38 - Use an ID Attribute to Style an Element

  • id 竟然這麼後面才說

<style>
  #cat-photo-form {
    background-color: green;
  }
</style>  

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

39 - Adjusting the Padding of an Element

  • padding 內邊距

  • border 邊框

  • margin 外邊距

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

40 - Adjust the Margin of an Element

<style>
  .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>
<h5 class="injected-text">margin</h5>

<div class="box yellow-box">
  <h5 class="box red-box">padding</h5>
  <h5 class="box green-box">padding</h5>
</div>

.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

Waypoint 35: Create a Set of Radio Buttons · Issue #1307 · FreeCodeCamp/FreeCodeCamp
Html: label (radio bottom) 小技巧 - Tsung's Blog
[CSS3] 用 CSS3 做表單 - 自訂單 / 多選框樣式 (一) | 男丁格爾's 脫殼玩
Create a Set of Checkboxes | Free Code Camp
Create a Set of Checkboxes | FreeCodeCamp 中文社區