Categories
CSS

How to move an entire div element up x pixels with CSS?

Sometimes, we want to move an entire div element up x pixels with CSS.

In this article, we’ll look at how to move an entire div element up x pixels with CSS.

How to move an entire div element up x pixels with CSS?

To move an entire div element up x pixels with CSS, we set the margin-top property.

For instance, we write

div {
  margin-top: -15px;
}

to move the div up 15px by setting margin-top to -15px.

Conclusion

To move an entire div element up x pixels with CSS, we set the margin-top property.

Categories
CSS

How to change background Opacity when bootstrap modal is open with CSS?

Sometimes, we want to change background opacity when Bootstrap modal is open with CSS.

In this article, we’ll look at how to change background opacity when Bootstrap modal is open with CSS.

How to change background opacity when bootstrap modal is open with CSS?

To change background Opacity when Bootstrap modal is open with CSS, we set the opacity style in the modal-backdrop class.

For instance, we write

.modal-backdrop {
  opacity: 0.5 !important;
}

to set the elements with class modal-backdrop to have opacity 0.5.

Conclusion

To change background Opacity when bootstrap modal is open with CSS, we set the opacity style in the modal-backdrop class.

Categories
CSS

How to make scrollbar visible in mobile browsers with CSS?

Sometimes, we want to make scrollbar visible in mobile browsers with CSS.

In this article, we’ll look at how to make scrollbar visible in mobile browsers with CSS.

How to make scrollbar visible in mobile browsers with CSS?

To make scrollbar visible in mobile browsers with CSS, we set the scrollbar’s width.

For instance, we write

::-webkit-scrollbar {
  -webkit-appearance: none;
}

::-webkit-scrollbar:vertical {
  width: 12px;
}

::-webkit-scrollbar:horizontal {
  height: 12px;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 10px;
  border: 2px solid #ffffff;
}

::-webkit-scrollbar-track {
  border-radius: 10px;
  background-color: #ffffff;
}

to set the vertical width of the scrollbar with

::-webkit-scrollbar:vertical {
  width: 12px;
}

We set the horizontal width of the scrollbar with

::-webkit-scrollbar:horizontal {
  height: 12px;
}

Then we set the background color and border radius of the handle with

::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 10px;
  border: 2px solid #ffffff;
}

::-webkit-scrollbar-track {
  border-radius: 10px;
  background-color: #ffffff;
}

Conclusion

To make scrollbar visible in mobile browsers with CSS, we set the scrollbar’s width.

Categories
CSS

How to change display of toggle button with Twitter Bootstrap collapse?

Sometimes, we want to change display of toggle button with Twitter Bootstrap collapse.

In this article, we’ll look at how to change display of toggle button with Twitter Bootstrap collapse.

How to change display of toggle button with Twitter Bootstrap collapse?

To change display of toggle button with Twitter Bootstrap collapse, we can add our own CSS styles.

For instance, we write

<a
  class="btn btn-primary collapsed"
  data-toggle="collapse"
  href="#collapseExample"
>
  <!--You can put any valid html inside these!-->
  <span class="if-collapsed">Open</span>
  <span class="if-not-collapsed">Close</span>
</a>
<div class="collapse" id="collapseExample">
  <div class="well">...</div>
</div>

to add the collapse elements.

Then we write

[data-toggle="collapse"].collapsed .if-not-collapsed {
  display: none;
}
[data-toggle="collapse"]:not(.collapsed) .if-collapsed {
  display: none;
}

to hide the button when the when the collapsed is open with

[data-toggle="collapse"].collapsed .if-not-collapsed {
  display: none;
}

And we hide the collapse container when it’s closed with

[data-toggle="collapse"]:not(.collapsed) .if-collapsed {
  display: none;
}

Conclusion

To change display of toggle button with Twitter Bootstrap collapse, we can add our own CSS styles.

Categories
CSS

How to use aria-expanded=”true” to change a CSS property?

Sometimes, we want to use aria-expanded="true" to change a CSS property.

In this article, we’ll look at how to use aria-expanded="true" to change a CSS property.

How to use aria-expanded="true" to change a CSS property?

To use aria-expanded="true" to change a CSS property, we can use the aria-expanded="true" selector.

For instance, we write

<li class="active">
  <a
    href="#3a"
    class="btn btn-default btn-lg"
    data-toggle="tab"
    aria-expanded="true"
  >
    <span class="network-name">Google+</span>
  </a>
</li>
<li class="active">
  <a
    href="#3a"
    class="btn btn-default btn-lg"
    data-toggle="tab"
    aria-expanded="false"
  >
    <span class="network-name">Google+</span>
  </a>
</li>

to add 2 links.

Then we write

a[aria-expanded="true"] {
  background-color: #42dca3;
}

to select the a elements with the aria-expanded attribute set to true and set their background color to #42dca3.

Conclusion

To use aria-expanded="true" to change a CSS property, we can use the aria-expanded="true" selector.