I've the following code:
<div class="card" >
<div class="card-block">
<h4 class="card-title">
<span class="text-left">π―</span>
<span class="text-right">Drago</span>
</h4>
<span class="card-text">
Location: ???<br>
District: ???<br>
Last updated: Tue, May 8th 2018
</span><br><br>
<div class="card-buttons" class="text-center">
<i class="fas fa-user-cog"></i> Edit User
<i class="fas fa-home"></i> Manage Addresses
<i class="fas fa-trash-alt"></i> Delete
</div>
</div>
</div>
I'm trying to make a card in Bootstrap 4.
I do want the emoji in the <h4> to be aligned left and the text after it to be aligned to the right. I'm trying to do it like this:
<h4 class="card-title">
<span class="text-left">π―</span>
<span class="text-right">Drago</span>
</h4>
But this is not working, I get:
I also tried to do it without the bootstrap classes. Using style="text-align: left" and style="text-align: right". However this also doesn't seem to work.
When I use <div> the horizontal alignment works fine. I get this problem only with <span> and <div>s that have display property set to inline-block and inline-flex.
You would use float-right because the .card-title is display:block...
<h4 class="card-title">
<span>π―</span>
<span class="float-right">Drago</span>
</h4>
https://www.codeply.com/go/CMrl4JydKp
Using text-right works on the parent of an inline element.
.card-title {
display: flex;
flex-wrap: wrap;
}
.text-right {
margin-left: auto;
}
You would probably want to add custom classes to the card-title for example, so you are not adjusting all card titles in general.
Fiddle: https://jsfiddle.net/2xv2t12c/
Hope this helps!!
BS4 update:- Added .float-{sm,md,lg,xl}-{left,right,none} classes for responsive floats and removed .pull-left and .pull-right since theyβre redundant to .float-left and .float-right.
So use float right and also i added a br tag under h4 so the below span wouldn't overflow into h4.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card">
<div class="card-block">
<h4 class="card-title ">
<span class="float-left">π―</span>
<span class="float-right">Drago</span>
</h4>
<br/>
<span class="card-text">
Location: ???<br>
District: ???<br>
Last updated: Tue, May 8th 2018
</span><br><br>
<div class="card-buttons" class="text-center">
<i class="fas fa-user-cog"></i> Edit User
<i class="fas fa-home"></i> Manage Addresses
<i class="fas fa-trash-alt"></i> Delete
</div>
</div>
</div>
Related
This is how It must looks like:
here is the image , circle is a place where phtoto must be uploaded
<div class="container ">
<div class="row mx-auto">
<div class="col ">
<span class="border border-success rounded-circle">
<button class="btnUpload">
<i class="fa fa-upload"></i> Upload
</button>
</span>
</div>
</div>
</div>
First of all: use "className" instead of "class" when working with react. To your problem: span is an inline element and doesn't have border. Turn it into a block element by setting display to block or use div element instead. Then center button vertically and horizontally inside of it, for example with flexbox:
<div
className="border border-success rounded-circle"
style={{ width: 100, height: 100, margin: 50 }}
>
<div className="h-100 d-flex justify-content-center align-items-center">
<button className="btnUpload">
<i class="fa fa-upload"></i> Upload
</button>
</div>
</div>
https://codesandbox.io/s/white-http-wsy881
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>
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>
Currently i have the following:
I would like the collapsible cards to be centered under the text and icons.. How would i go about doing that? I have tried using CSS on the div, however nothing seems to make a change in their position?
The code i have so far:
<div class="categoryList">
#result
#if (result == "")
{
foreach (String dataLine in userData)
{
<p>
<a data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
#dataLine.Split(delimiterChar)[0]
</a>
<button class="btn"><i class="fas fa-plus secondaryPlusIcon"></i></button>
<button class="btn"><i class="far fa-edit secondaryPlusIcon"></i></button>
<button class="btn"><i class="far fa-trash-alt secondaryPlusIcon"></i></button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body w-25 p-3">
</div>
</div>
}
}
</div>
If Kira's answer does not work you could try this as an alternative.
<div class="collapse" id="collapseExample">
<div class="card card-body w-25 p-3 desiredclassname">
...
</div>
</div>
CSS code:
.desiredclassname{
margin: auto;
}
Hope it helps :)
You can use CSS flexbox to get exact centering
.collapse{
display: flex;
justify-content: center;
}
There is more info here https://www.w3schools.com/css/css3_flexbox.asp
Or, you could wrap it in a <center> tag:
<center>
<div class="collapse" id="collapseExample">
...
</center>
The center tag is discouraged, however. It could be replaced by
<div style="text-align: center;">
<div class="collapse" id="collapseExample">
...
</div>
Hopefully one of these answers helps!
I've created a simple button link in my page with container-fluid and row classes so that I can take utilize the whole available width of the page for the link button.
However, my code doesn't result in the button taking full width of the page. Attached is the screenshot of the said output.
Please inform me as to what I'm doing incorrectly. Thanks in advance.
[Basically what I want is that the well in the below screenshot should take 100% (or atleast 90% and centered) of the page width.]
My HTML and CSS codes are mentioned below:
My HTML Code:
<div class="container-fluid">
<div class="row">
<section id="access_list_session" class="col-sm-12">
<br/>
<p id="form-header"> Access Colleague List </p>
<br /><br /><br />
<div class="row">
<div class="hidden-xs hidden-sm col-md-4">
<i class="fa fa-5x fa-cogs" aria-hidden="true"></i>
</div>
<div class="well col-xs-12 col-sm-12 col-md-8">
<div id="form_link">
<i class="fa fa-list-alt" aria-hidden="true"></i> Click to access our Colleague List<br /> <span style="font-size: 10px; text-align:center;"">(Use of this list is subject to our Privacy Policy and other T&C)</span>
</div>
<br/>
<hr>
<p> In case of any difficulty please contact the site administrator using the form below.</p>
</div>
</div>
</section>
</div>
</div>
My CSS Code
#form_link a
{
width: 100%;
font-size: 1em;
}
.row
{
padding-top: 60px;
height: 60em;
width: 100%;
}
2 solutions IMHO :
Add in .row
.row {
margin: auto;
}
to center your block (see https://jsfiddle.net/os7frkq5/1/)
or simply delete width: 100% :
(see https://jsfiddle.net/os7frkq5/2/ )
I don't know if this is what you mean but you can try this:
<div class="container-fluid">
<section id="access_list_session" class="col-md-12">
<br/>
<p id="form-header"> Access Colleague List </p>
<br /><br /><br />
<div class="row">
<div class="hidden-xs hidden-sm col-md-4">
<i class="fa fa-5x fa-cogs" aria-hidden="true"></i>
</div>
<div class="well col-xs-12 col-sm-12 col-md-12">
<div id="form_link">
<i class="fa fa-list-alt" aria-hidden="true"></i> Click to access our Colleague List<br /> <span style="font-size: 10px; text-align:center;"">(Use of this list is subject to our Privacy Policy and other T&C)</span>
</div>
<br/>
<hr>
<p> In case of any difficulty please contact the site administrator using the form below.</p>
</div>
</section>
</div>
What you want is the a element to use block-display.
a { display: block }
Read up on the differences between inline and block elements, because it's vital to the way they're laid out.