Categories
HTML

How to add a scrollable canvas inside a div?

Sometimes, we want to add a scrollable canvas inside a div.

In this article, we’ll look at how to add a scrollable canvas inside a div.

How to add a scrollable canvas inside a div?

To add a scrollable canvas inside a div, we can make the div scrollable and put a canvas inside it.

For instance, we write:

<div style="width: 150px; overflow: auto; ">
  <canvas width="200" style="border:1px solid #ff0000;"></canvas>
</div>

to add a div with the overflow CSS property set to auto.

And then we add a canvas inside it with a red border.

Conclusion

To add a scrollable canvas inside a div, we can make the div scrollable and put a canvas inside it.

Categories
HTML

How to change the selected option background-color CSS style?

Sometimes, we want to change the selected option background-color CSS style.

In this article, we’ll look at how to change the selected option background-color CSS style.

How to change the selected option background-color CSS style?

To change the selected option background-color CSS style, we can set the style attribute of the select and option elements.

For instance, we write:

<select style="background: #009966; color: #FFF;">
  <option value='0' style="background: white; color: black;">Protect my email</option>
  <option value='1' style="background: white; color: black;">Show email on advert</option>
</select>

to set the whole select element to background color 009966 and color FFF.

Then we override the the styles in the option elements with style="background: white; color: black;".

As a result, we see that the selected item has a green background and white text and the options have black text and a white background.

Conclusion

To change the selected option background-color CSS style, we can set the style attribute of the select and option elements.

Categories
HTML

How to disable autocomplete in input?

Sometimes, we want to disable autocomplete in input.

In this article, we’ll look at how to disable autocomplete in input.

How to disable autocomplete in input?

To disable autocomplete in input, we can set the autocomplete attribute to off.

For instance, we write:

<input autocomplete="off" type="text" name="username">

to add an input with autocomplete disabled.

Conclusion

To disable autocomplete in input, we can set the autocomplete attribute to off.

Categories
HTML

How to add a div that stays at the top while a web page scrolls?

Sometimes, we want to add a div that stays at the top while a web page scrolls

In this article, we’ll look at how to add a div that stays at the top while a web page scrolls

How to add a div that stays at the top while a web page scrolls?

To add a div that stays at the top while a web page scrolls, we set the position CSS property of the div to fixed.

For instance, we write:

<div>
  fixed
</div>

to add a div.

Then we make it fixed by writing:

div {
  top: 0;
  position: fixed
}

We set the top position of the div and the position to fixed to make the div stay at the top of the screen.

Conclusion

To add a div that stays at the top while a web page scrolls, we set the position CSS property of the div to fixed.

Categories
HTML

How to Align a Div with Fixed Position on the Right Side?

Sometimes, we want to align a div with fixed position on the right side.

In this article, we’ll look at how to align a div with fixed position on the right side.

Align a Div with Fixed Position on the Right Side

To align a div with fixed position on the right side, we set the right CSS property of the div we want to align to the right side.

For instance, we write:

<div class='test'>
  hello world
</div>

and

.test {
  position: fixed;
  right: 20px;
}

to add a div with the class test.

Then in the CSS code, we select the elements with class test, and set the right property on it.

We set it to 20px so that the div is displayed 20px from the right edge of the screen.

Conclusion

To align a div with fixed position on the right side, we set the right CSS property of the div we want to align to the right side.