Flex 0 0 Bootstrap remedy

Is there a way to style my wrapped H2 text with a border that fits the width of the text without creating custom classes?

While using the correct bootstrap classes, I noticed that adding the class "flex-grow-0" to my H2 element didn't work as expected. However, when I used the inline style "flex: 0 0;", it achieved the desired effect. Check out the snippet provided. Any ideas on how to accomplish this without manually creating classes would be appreciated. Thank you!

:root {
/* Customize colors here to modify site-wide color scheme */
    --color1:#F39207; /* Orange */
    --color2:#951B81; /* Purple */
    --color3:#ffffff; /* White */
--color4:#e6e6e6; /* Grey */
}

/* GRID Styling
------------------------------------------------------ */

.grid article div div {
height:20em;
}

.grid article div div {
overflow: hidden;
position: relative;
}

.grid article div div figure div {
position: absolute; 
top: 0; 
left: 0;
background-position: center;
background-size: cover;

-webkit-transition: all 1.5s;
    -moz-transition: all 1.5s;
    -o-transition: all 1.5s;
    transition: all 1.5s;
}

.grid article div div figure div:hover {
-ms-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -webkit-transform: scale(1.2);
    -o-transform: scale(1.2);
transform: scale(1.2);

}

/* GRID Text Styling */
.grid figcaption {
z-index: 2;
}

.grid figcaption .grid-title-band {
font-family: sans-serif;
color: var(--color3);
text-transform: uppercase;
letter-spacing: 0.3em;
border:0.4em solid var(--color3);

clip-path: polygon( 
    calc(0% + 5px) calc(0% + 5px), /* top left */
    calc(100% - 5px) calc(0% + 5px), /* top right */
    calc(100% - 5px) calc(100% - 5px), /* bottom right */
    calc(0% + 5px) calc(100% - 5px) /* bottom left */
);
transition: clip-path 0.4s linear;
}

.grid figcaption:hover .grid-title-band {
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<section class="grid">
<article class="row bg-white pt-2 pb-2">
<!-- Item // NOT GOOD -->
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-4 p-2">
<div>
<a href="" class="text-decoration-none">
<figure class="d-flex h-100 align-items-center justify-content-center p-5">
<div class="w-100" style="background-image:url(http://www.cactusfestival.be/test-2/pics/bands/het_zesde_metaal.jpg);"></div>
<figcaption class="d-flex flex-wrap justify-content-around"><h2 class="flex-grow-0 grid-title-band p-3 m-0">This Example Is Wrong - Original</h2></figcaption>
</figure>
</a>
</div>
</div>
<!-- / Item -->
    <!-- Item // NOT GOOD -->
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-4 p-2">
<div>
<a href="" class="text-decoration-none">
<figure class="d-flex h-100 align-items-center justify-content-center p-5">
<div class="w-100" style="background-image:url(http://www.cactusfestival.be/test-2/pics/bands/het_zesde_metaal.jpg);"></div>
<figcaption class="d-flex flex-wrap justify-content-around"><h2 class="flex-shrink-0 flex-grow-0 grid-title-band p-3 m-0">This Example Is Wrong - Edits</h2></figcaption>
</figure>
</a>
</div>
</div>
<!-- / Item -->
    <!-- Item // GOOD -->
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-4 p-2">
<div>
<a href="" class="text-decoration-none">
<figure class="d-flex h-100 align-items-center justify-content-center p-5">
<div class="w-100" style="background-image:url(http://www.cactusfestival.be/test-2/pics/bands/het_zesde_metaal.jpg);"></div>
<figcaption class="d-flex flex-wrap justify-content-around"><h2 class="grid-title-band p-3 m-0" style="flex:0 0;">This Example Is Good</h2></figcaption>
</figure>
</a>
</div>
</div>
<!-- / Item -->
</article>
</section>
</body>
</html>

Answer №1

You may want to consider using the .col class in combination with flex-basis:0, along with flex-grow-0 flex-shrink-0

:root {
/* You can customize these colors here to affect the entire site + manually change the colors in the .gradient tag + navigation etc */
    --color1:#F39207; /* Orange */
    --color2:#951B81; /* Purple */
    --color3:#ffffff; /* White */
--color4:#e6e6e6; /* Grey */
}

/* GRID
------------------------------------------------------ */

.grid article div div {
height:20em;
}

.grid article div div {
overflow: hidden;
position: relative;
}

.grid article div div figure div {
position: absolute; 
top: 0; 
left: 0;
background-position: center;
background-size: cover;

-webkit-transition: all 1.5s;
    -moz-transition: all 1.5s;
    -o-transition: all 1.5s;
    transition: all 1.5s;
}

.grid article div div figure div:hover {
-ms-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -webkit-transform: scale(1.2);
    -o-transform: scale(1.2);
transform: scale(1.2);

}

/* GRID - Text */
.grid figcaption {
z-index: 2;
}

.grid figcaption .grid-title-band {
font-family: sans-serif;
color: var(--color3);
text-transform: uppercase;
letter-spacing: 0.3em;
border:0.4em solid var(--color3);

clip-path: polygon( 
    calc(0% + 5px) calc(0% + 5px), /* top left */
    calc(100% - 5px) calc(0% + 5px), /* top right */
    calc(100% - 5px) calc(100% - 5px), /* bottom right */
    calc(0% + 5px) calc(100% - 5px) /* bottom left */
);
transition: clip-path 0.4s linear;
}

.grid figcaption:hover .grid-title-band {
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<section class="grid">
<article class="row bg-white pt-2 pb-2">
<!-- Item // NOT GOOD -->
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-4 p-2">
<div>
<a href="" class="text-decoration-none">
<figure class="d-flex h-100 align-items-center justify-content-center p-5">
<div class="w-100" style="background-image:url(http://www.cactusfestival.be/test-2/pics/bands/het_zesde_metaal.jpg);"></div>
<figcaption class="d-flex flex-wrap justify-content-around"><h2 class="flex-grow-0 flex-shrink-0 col wid grid-title-band p-3 m-0">This Example Is Good</h2></figcaption>
</figure>
</a>
</div>
</div>
<!-- / Item -->
    <!-- Item // GOOD -->
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-4 p-2">
<div>
<a href="" class="text-decoration-none">
<figure class="d-flex h-100 align-items-center justify-content-center p-5">
<div class="w-100" style="background-image:url(http://www.cactusfestival.be/test-2/pics/bands/het_zesde_metaal.jpg);"></div>
<figcaption class="d-flex flex-wrap justify-content-around"><h2 class="grid-title-band p-3 m-0" style="flex:0 0;">This Example Is Good</h2></figcaption>
</figure>
</a>
</div>
</div>
<!-- / Item -->
</article>
</section>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The keyframes animation for the navigation bar will not restart from a different location

I've been working on creating a CSS keyframes animation for a navigation bar, and I'm encountering some issues. The animation involves a red line moving when a user clicks on a nav bar element. By default, the first element is active (red line un ...

The HTML page is not responsive to the screen size of the mobile device

Check out my HTML code: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Test</title> <style type= ...

"Spin an image using Javascript when it is shown on the

I've got a script that shows an image when we are attacked by a monster. The image is initially set to display="none", but switches to display="" when a monster appears. What I'm looking to do is make the image rotate 360° when it changes from ...

I am curious as to why the Bootstrap 4 dropright selected menu appears as a default browser button in Chrome, while it functions seamlessly in Firefox

An issue has been identified that is specific to Chrome. The dropright selected menu appears differently in Chrome compared to Firefox, where it displays correctly with a white background. !https://i.sstatic.net/BulRA.jpg The Bootstrap version being used ...

Is there a way to incorporate animation into a :hover element?

Currently, I am trying to create a :hover effect that will change the background color of an element between five different colors when it is hovered over. Below is the code I have been working on: <div class="background_changer"> < ...

The Tahoma font is not being displayed properly in HTML emails on mobile devices

I am struggling to ensure that the font "tahoma" displays correctly in an HTML email. While it works fine on desktops, the font "tahoma" does not appear on mobile clients. How can I fix this issue? Below is the code for the email I am sending: <h3 ...

Modifying the div based on the color it is positioned in front of

I am attempting to create a sticky, transparent div that changes its color based on the background behind it. I have both dark and light colored divs, and I want the sticky div to adjust its text color accordingly (white on dark backgrounds, black on light ...

Is the use of the auto image attribute height/width impacting rendering performance?

Currently, I am facing an issue with setting the height and width attributes for an image as I do not have access to its dimensions from the server. One solution I am considering is setting both the width and height values to auto. For example: img { ...

Tips for properly positioning a bootstrap popover within a grid column

I'm currently utilizing bootstrap 4 alpha 6. Displayed below is a grid consisting of one row and two columns. The first column contains text, while the second column displays a popover: <div class="row text-center align-items-center" style="heigh ...

Toggle a jQuery bar based on the presence of a specific CSS class

I am working on a feature where I can select and deselect images by clicking on a delete button. When an image is selected, a bar appears at the top. If I click the same delete button again, the image should be deselected and the bar should disappear. This ...

Tips for emphasizing the letters of the alphabet used in search functionality with Angular

Is there a way to highlight specific alphabets in the searched list instead of highlighting the entire word? Currently, when filtering the memberOffice and memberFacilities lists based on the alphabet entered in the search field, the entire text is highlig ...

Adjust the video's position to ensure it scales properly on mobile devices

I'm facing a coding challenge with the following snippet: https://codesandbox.io/s/cool-sunset-pe8pgh?file=/src/styles.css My goal is to scale the video on mobile devices without sacrificing any part of the video element. What would be the best appro ...

Embed an iframe that occupies the entire page, all without the use of

I am facing a challenge with an iframe on my webpage, as it appears in letterbox shape. My goal is to make it fill the page vertically while maintaining the horizontal size at 60% with sidebars on the left and right. Currently, I have achieved this in Chr ...

Apply the transition property to all elements except for the text inside a specific tag

I'm wondering if it's possible to apply a hover transition effect to everything in this tag except the text within it. The desired effect is for the button to fade away while the text remains visible. Below is the code I have written so far: ul ...

Dimensions of Bootstrap carousel

I am attempting to create a Bootstrap carousel with full-width images (width: 100%) and a fixed height. However, when I set the width to 100%, the height automatically takes on the same value. I am unsure if the issue lies within my files. <div id="m ...

Is there a way to align the height of a standard column with the ng-include section to ensure a cohesive page display?

I have been working on my Angular app and have implemented ng-include to dynamically add content to a template within the page. The issue I'm facing is that this specific area ends up being longer than both the html and body elements where it resides. ...

The Jquery function for selecting a div added by an Ajax call is not functioning properly, but it works fine without the need for an

I have a unique checkbox that I created using an Ajax call. The issue I'm facing is that the jQuery to select the checked input in the second div #test_checkbox_ajax isn't working, while it works perfectly fine in the first div #test_checkbox. Cr ...

Guide on how to prevent Paste (Ctrl+V) and Copy (Ctrl+C) functionalities in a TextField within MaterialUI

Is there a way to restrict the Paste (Ctrl+V) and Copy (Ctrl+C) functions in a specific TextField within MaterialUI? I am currently working with ReactJs ...

Struggling to Position Bootstrap Custom Checkboxes on the Right Side

I'm working with a bootstrap 4 table that includes custom checkboxes that I want to align to the right. If you need an example, feel free to check out this demo Here's how I've created the custom checkboxes: <label class="custom-contro ...

animated text scroller with keyframes

I've successfully implemented a slider with three items, and it's working as expected. If you'd like to see a live demo, check out this working demo. This text slider features three items: HTML <span class="item-1">FAST.</span&g ...