CSS Question-Answer

  1. What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?
  2. Class attribute can be applied on multiple HTML elements, whereas Id attribute can be applied only on one single HTML element. Id must be unique within a web page.

  3. Is it possible to change an inline element into a block level element?
  4. Yes, it is possible to change the inline element into a block-level element using the CSS 'display' property with its value as 'block'

  5. Is it possible to change an block level element into a inline element?
  6. Yes, using the CSS 'display' property, with its value as 'inline'

  7. Why the code is not working?
    <style>
    .form-control:after{
      content: '*';
      color: red;
    }
    </style>
    <input type="text" class="form-control" name="contact_name" placeholder="Name" required>
  8. Answer: The above code will not work because the input elements have no content.
    <style> .form-control:after{
      content: '*';
      color: red;
    }
    </style>
    <input type="text" name="contact_name" placeholder="Name" required>
    <span class="form-control"></span>