Logo
/
Frontend
/
CSS Course
/

Block height and width

CSS: Block height and width

When you create pages, you often want to control the height and width of blocks. This is useful in long articles when you want to put explanatory text in a small block. This way it will be separated from the main part of the text, and you can see it immediately.

The rules width and height are used to control the height and width of block elements, taking values for width and height respectively (in pixels or other available units of measure, for example).

Let's create a block 100 pixels high and 100 pixels wide. To visually separate it from the theory in the tutorial, set the background color to black:

<style>
  .square {
    width: 100px;
    height: 100px;
    background-color: #000;
  }
</style>

<div class="square"></div>

A square that is 100px tall and wide

Instructions

Add <div> to the editor with the class set to rectangle. Set the properties:

  • Width: 300px
  • Height: 100px
  • Background color: #000.

Write the styles in the <style> tag

If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:

  • Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Found a bug? Have something to add? Pull requests are welcome!