PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 30, 2022

[FIXED] How to work with repetitive bootstrap css code

 September 30, 2022     bootstrap-5, css     No comments   

Issue

I am frequently using this code to center some content

<!-- horizontal -->
<div class="d-flex align-items-center justify-content-center h-100">
  ..
</div>

<!-- vertical -->
<div class="d-flex align-items-center justify-content-center h-100 flex-column">
  ..
</div>

Is there a way to reuse / inherit this code, so that I can use it like below, where my-centered-container-vertical just adds flex-column to my-centered-container (no code duplication)?

<div class="my-centered-container">
</div

<div class="my-centered-container-vertical">
</div

Solution

You shouldn't write in CSS anyway. Use SASS or LESS instead. See other answers for how to integrate bootstrap into your project. Also see bootstrap#importing. As for your specific question, you can re-use like this.

.my-center {
    @extend .d-flex;
    @extend .align-items-center;
    @extend .justify-content-center ;
    @extend .h-100;
}


Answered By - IT goldman
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing