So I have this card with a div inside it. And the idea is that I want to show a icon to the left and then a text to the right of the icon indicating a username can be up to 32 characters long.
<div>
<h5 class="d-inline"><i class="icofont icofont-social-snapchat"></i></h5>
<p class="d-inline">rwmGhw9El8cBMeyvzQ18fmZP2EbLaQhY</p>
</div>
The issue is that when I start shrinking the page, the text gets places under the icon and it starts going outside of the card.
I'm actually not sure to why this happens or what the best way to fix this is.
How do I properly deal with something like this? Would adding ellipsis be a good idea?
Here is the markup for the card
<div class="col-xl-4 px-2">
<div class="card card-with-border mt-5 ">
<div class="card-body mb-0">
#foreach (var item in user.Tags)
{
<span class="badge badge-primary mt-3 ml-0">#item</span>
}
</div>
<div class="card-body socialprofile filter-cards-view pt-2">
<div class="media">
<div class="avatar ratio"><img class="b-r-8 height-50 mr-3 img-80" src=#user.Image alt="#"></div>
<div class="media-body">
<h6 class="font-danger f-w-600">Hello, World!</h6>
<div>
<h5 class="d-inline"><i class="icofont icofont-social-snapchat"></i></h5>
<p class="d-inline">rwmGhw9El8cBMeyvzQ18fmZP2EbLaQhY</p>
</div>
<span class="card-text"><h5><i class="icofont icofont-social-instagram"></i></h5><p></p></span>
<p class="card-text mt-2">Testing the text lets see what it looks like.</p>
</div>
</div>
<div class="social-btngroup d-flex">
<button class="btn btn-primary w-100">Like</button>
</div>
<div class="likes-profile text-center">
<h5> <span> <i class="fa fa-heart font-danger"></i> 884</span></h5>
</div>
</div>
</div>
</div>
Your element need to be in display: block or display: inline-block.
/* Limit size of media-body */
.media-body {
max-width: calc(100% - 2rem);
}
.ellipsis {
display: block !important;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
<div>
<h5 class="d-inline"><i class="icofont icofont-social-snapchat"></i></h5>
<!-- Add the class ellipsis where you want -->
<p class="d-inline ellipsis">rwmGhw9El8cBMeyvzQ18fmZP2EbLaQhY</p>
</div>
Related
I have a issue with vertical alignment in a container. I have the following code that does what I want, that is, the first row in the center and the second at the bottom of the container.
Full screen
<header class="masthead" id="home">
<div class="container h-100">
<div class="row h-100 align-items-center justify-content-evenly text-center">
<div class="col-4">
<img src="assets/img/profil.png" class="rounded-circle img-fluid" alt="...">
<hr class="divider" />
<h1 class="text-white font-weight-bold">d3vyce</h1>
</div>
<div class="col-md-8 col-lg-4">
<h2 class="text-white font-weight-bold">Hi 👋, Welcome to my Site!</h2>
<p class="text-white">Developer, CTF Player, Homelab, 3D Printing</p>
<hr class="divider" />
<div class="d-grid col-6 mx-auto">
<a class="btn btn-outline-light btn-lg" href="https://blog.d3vyce.fr" target="_blank"><i class="fa fa-bookmark fa-lg"></i> Blog</a>
<a class="btn mt-2 btn-outline-light btn-lg" href="https://github.com/d3vyce" target="_blank"><i class="fa fa-github fa-lg"></i> Github</a>
</div>
</div>
</div>
<div class="row head-row justify-content-center">
<div class="col-12 mouse_scroll p-0">
<a href="#about">
<div class="mouse">
<div class="wheel"></div>
</div>
<div>
<span class="m_scroll_arrows unu"></span>
<span class="m_scroll_arrows doi"></span>
<span class="m_scroll_arrows trei"></span>
</div>
</a>
</div>
</div>
</div>
</header>
For the alignment at the bottom of the second row I use the following CSS:
.mouse_scroll {
display: block;
width: 24px;
height: 100px;
position: absolute;
bottom: 0; }
The problem happens with the responsive. The columns of the first row are well one on top of the other, but the space between the two is much too important and I can't modify it :(
I tried to search on stackoverflow for answers, but after many tests I'm in a dead end...
Reponsive
Thank you in advance for your answers!
This question already has answers here:
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 1 year ago.
I am trying to vertically center my text content in the right column with bootstrap. However when I do that, the height of the column collapse to the height of the content like this.
How can I make the height of the right column the same as that on the left while vertically centering my text?
This is my HTML code:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-md mt-5 d-grid">
<div class="row gx-0"> <!--gx sets the gutter btw columns to 0-->
<div class="col-sm-8">
<img src="https://www.syfy.com/sites/syfy/files/wire/legacy/edge_of_tomorrow-wide.jpg" alt="Edge of Tomorrow" class="img-fluid" href="featured.html">
</div>
<div class="col-sm-4 bg-light align-self-center text-center">
<h1>Edge of Tomorrow</h1>
<div class="rating">
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
</div>
<p>It leaves you on the edge, wishing for a tomorrow. An epic action movie with twists and turns along the way.</p>
<button class="featured-button">Read more →</button>
</div>
</div>
</div>
</div>
</div>
Update:
Now I have set it to flex to vertically center my content which works perfectly. It looks like this now:
With the updated code:
<div class="container-md mt-5 featured">
<div class="row gx-0"> <!--gx sets the gutter btw columns to 0-->
<div class="col-md-7"> <!--col adds up to 12-->
<img src="images/edge-of-tomorrow.jpg" alt="Edge of Tomorrow" class="img-fluid featured-img" href="featured.html">
</div>
<div class="col-md-5 h-100 bg-light d-flex flex-column align-items-center justify-content-center text-center featured-content">
<h1>Edge of Tomorrow</h1>
<div class="rating">
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
</div>
<p>It leaves you on the edge, wishing for a tomorrow. An epic action movie with twists and turns along the way.</p>
<button class="btn btn-warning">Read more →</button>
</div>
</div>
</div>
<!--other content-->
<!--grid of cards-->
<div class="container card-deck mt-5"> <!--card deck so that it's equal height and width-->
<div class="row">
<div class="col-md-4">
<div class="card h-100">
<img class="card-img-top" src="images/500-days-of-summer.jpg" alt="500 Days of Summer">
<div class="card-body">
<h5 class="card-title">500 Days of Summer</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
But now the problem is when I minimise my screen, the content overlaps like this.
How can I prevent this from happening?
Instead of self-aligning the col-sm-4 to center, change it to a flex (column-wise). Then make everything center with: d-flex flex-column align-items-center justify-content-center. This will make it as you want.
Here's the fiddle (used a random image off the internet): JSFiddle
I added extra height to image just for the demo, you do not need to do that.
As a workaround, i would consider removing the img tag, and add a bg class to the div like this:
<div class="col-sm-8 bg"></div>
And in CSS Add:
.bg {
background-image: url("images/edge of tomorrow.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
object-fit: cover;
}
You can afterwards change the height of the image as you want, to display it in a proper way.
That worked for me, Hope this helped.
set the right column height to 100% with .h-100 bootstrap class.
Then set that right side column to position relative and wrap all the content inside a div(as u can see in my code).
-Than set that div to absolute and set it center with css as I did.
.content {
position: absolute;
top: 50%;
left: 0;
right: 0;
transform: translateY(-50%);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.min.js"></script>
<div class="container-md mt-5 d-grid">
<div class="row gx-0"> <!--gx sets the gutter btw columns to 0-->
<div class="col-sm-8">
<img src="https://images.unsplash.com/photo-1627850019941-9ca7769b314e?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1868&q=80" alt="Edge of Tomorrow" class="img-fluid" href="featured.html">
</div>
<div class="col-sm-4 bg-light text-center h-100 position-relative">
<div class="content"><h1>Edge of Tomorrow</h1>
<div class="rating" style="
">
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
</div>
<p>It leaves you on the edge, wishing for a tomorrow. An epic action movie with twists and turns along the way.</p><button class="featured-button" style="
width: fit-content;
">Read more →</button>
</div>
</div>
</div>
</div>
</div>
</div>
I have been trying to make this layout even. How can I have a vertical equidistance between the text and have them contained in the card.
Here is the html code:
<div class="card text-center">
<p class="card-title"><small class="text-muted">Societal</small></p>
<div class="card-body">
<small class="card-text">Large involontary migration</small>
<div class="card-footer">
<small class="text-muted">10.5%</small>
</div>
</div>
</div>
Thanks
There are a few options for achieving this listed in the bootstrap documentation.
Bootstrap Website
I chose a slightly different card variation from bootstrap v4.5.
You can play around with the padding and margins to get it exactly how you'd like.
<div class="container">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title text-danger text-center mb-0 pb-0">Societal</h5>
<p class="card-text text-center mb-0 pb-0"><strong>Large-scale involontary migration</strong></p>
<p class="text-danger text-center">10.5%</p>
</div>
</div>
</div>
.card-body {
border: 20px solid #b19cd9;
}
code output
Code snippet
I am using a Bootstrap-4 card in my web page.
I want the text in card-body to grow from bottom to top.
<div class="col-xl-3 col-sm-6 mb-3">
<div class="card text-white color4 o-hidden h-100">
<div class="card-body">
<div class="mr-5"><span class="float-left"
style="min-width:280px;font-size:17px;">Tool</span>
</div>
<p>Contents i want this text to grow from bottom
to top.</p>
</div>
<div class="card-body-icon">
<i class="fa fa-cogs" aria-hidden="true"></i>
</div>
</div>
</div>
I am not sure what you mean. I guess you want to grow your text?
You can use:
p {
font-size: 60px;
}
or even better
your-div-name p {
font-size: 60px;
}
I've been trying to have two span elements, one with Bootstrap 4 class 'close' and the other with class 'badge', floated right. The thing is if I add float-right to the badge, they always end up right next to each other. Or, if I use clear: right, the badge falls to the end of the div.
This needs to be my outline:
Here's the HTML I have so far:
<div class="card">
<div class="card-header">
<span class="close">x</span>
<img src="image.png">
<h1 class="card-title d-inline">Title</h1>
<span class="badge badge-default d-inline">Badge</span>
<h2 class="card-subtitle">Subtitle</h2>
</div>
</div>
How can I achieve that with Bootstrap 4? Thank you!
You can use margin or padding (spacing utils) around the badge..
http://www.codeply.com/go/XEbOw2F29d
<div class="card">
<div class="card-header">
<span class="close">x</span>
<span class="badge badge-default float-right m-2">Badge</span>
<img src="//placehold.it/40">
<h1 class="card-title d-inline">Title</h1>
<h2 class="card-subtitle">Subtitle</h2>
</div>
</div>
EDIT
If you're looking for something like shown in your image, it's not a simple matter of float-right. You'll need to use the spacing utils to adjust the elements..
<div class="card">
<div class="card-header pt-0">
<div class="w-100 text-right close">x</div>
<img src="//placehold.it/60" class="float-left mt-2 mr-2">
<span class="badge badge-default float-right mt-2">Badge</span>
<h1 class="card-title my-0"> Title</h1>
<h2 class="card-subtitle d-inline-block">Subtitle</h2>
</div>
</div>
http://www.codeply.com/go/XEbOw2F29d
Why don't you try creating a new div and putting inside "Close" and "Badge"? Then you only need to float the div to the right.
Tell me if it works! 😉