Yes, you can absolutely use Bootstrap and external custom CSS at the same time. In fact, this is a common practice when you want to leverage Bootstrap's pre-built components and utilities while adding your own custom styles to tailor the design to your specific needs.
Here’s how to effectively combine Bootstrap and external CSS:
1. Include Bootstrap and Your Custom CSS
Add Bootstrap's CSS file in your <head> section.
Include your custom CSS file after Bootstrap's CSS to ensure your styles override Bootstrap's defaults when necessary.
3. Use Bootstrap's Utility Classes in Your Custom CSS
Bootstrap's utility classes (e.g., text-center, mt-3, bg-primary) can be used directly in your custom CSS or HTML. This allows you to extend Bootstrap's functionality without writing repetitive CSS.
Example:
css
.custom-card {
@extend .card; /* If using Sass */
background-color: #f8f9fa;
padding: 20px;
}
Bootstrap uses common class names like .btn, .container, and .row. If you use the same class names in your custom CSS, ensure they don’t conflict with Bootstrap's styles. You can namespace your classes (e.g., .my-btn, .my-container) to avoid collisions.
5. Use Bootstrap's Sass Variables (Optional)
If you're using Sass, you can customize Bootstrap's default styles by overriding its variables before importing Bootstrap.
If you're using Bootstrap's JavaScript plugins (e.g., modals, carousels), ensure your custom JavaScript doesn’t conflict with Bootstrap's behavior. Include Bootstrap's JavaScript after your custom scripts if needed.
Order matters: Place your custom CSS after Bootstrap's CSS to override styles.
Leverage utilities: Use Bootstrap's utility classes in your custom CSS or HTML.
Avoid conflicts: Be mindful of class name collisions and namespace your custom classes if necessary.
Customize with Sass: If using Sass, override Bootstrap's variables for deeper customization.
By combining Bootstrap and custom CSS, you get the best of both worlds: the speed and convenience of Bootstrap's pre-built components, plus the flexibility to create a unique design.