How can i center a div with the class of "collapse" (Bootstrap)? - html

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!

Related

How to have a design of the upload button inside the circle in the website either using: bootstrap, React, materialUI?

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

How to place a link button next to a div using Bootstrap 4

I have a link button that I need to place to the right of a div. Adding float-left on the div and float-right on the link button does not do it. What am I doing wrong?
https://jsfiddle.net/3v2s4c50/
<div class="container">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">Today and Tomorrow</div>
<div class="card-body">
<div class="float-left">Someone somewhere is waiting for you.</div>
<a role="button" href="google.com" class="float-right btn btn-primary"> Login</a>
</div>
</div>
</div>
<div class="col">
2 of 2
</div>
</div>
</div>
remove floats and add:
.card-body{
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="card-body d-flex">
<div class="flex-fill">Someone somewhere is waiting for you</div>
<a role="button" href="google.com" class="flex-fill btn btn-primary"> Login</a>
</div>
Well, it is doing it. But the portion of the screen that is showing the results is not wide enough to show both the div with the text and the button in the same row.. then it breaks down.
If you change the text to something smaller, like 'Someone is waiting' you can see the button floating right :)
You can also set a fixed width for your text div (currently it is expanding based on the content).
<div class="card-body">
<div class="float-left" style="width: 50%;">Someone somewhere is waiting for you</div>
<a role="button" href="google.com" class="float-right btn btn-primary"> Login</a>
</div>
You can add your link to a div with any class. Then add style "text-align: right;" into your div like this:
.my-link {
text-align: right;
}
.
<div class="my-link">
<a role="button" href="google.com" class="float-right btn btn-primary"> Login</a>
</div>
.
I hope this will be useful.

Getting the accordion to take full height and each individual panes to take the full viewport height. (Bootstrap 4)

https://i.stack.imgur.com/LqhXn.png This doesn't belong to me but its clear to explain what I want to achieve.
Below is my current code
<div class="accordion" id="myAccordion">
<div class="card">
<div class="card-header" id="section1" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<h2 class="mb-0">
<i class="fa fa-search" aria-hidden="true"></i> Section 1
</h2>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="section1" data-parent="#myAccordion">
<div class="card-body">
Some content here
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="section2" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<h2 class="mb-0">
<i class="fa fa-briefcase" aria-hidden="true"></i> Section 2
</h2>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="section2" data-parent="#myAccordion">
<div class="card-body">
some other content here
</div>
</div>
</div>
</div>
</div>
</div>
I've look at some similar questions asked and none has helped by far. I need the the card-body of section1 to take full height based on the user's viewpoint despite the amount of content inside the card-body, and push section2's card-header all the way to the bottom of the accordion. Any help or further reference is appreciated.
[This is what the result I have now ->] https://i.stack.imgur.com/THCb9.png
The basic idea is to set the accordion height to 100% viewport height, display the accordion as flexbox in column direction, and grow the opened section (using flex-grow:1;) so that it will take up the remaining space vertically.
This way you don't have to hard code any number for heights.
It would have been PURE CSS if Bootstrap has the ability to extend the collapse plugin so that I can add any CSS class to the parent who has a collapsible child. Currently when you click on the header, the collapsible section opens and the .show class is only added to that collapsible section, not its parent .card.
To identity which .card is open we need the following JavaScript utilizing Bootstrap Collapse Events:
$(function() {
$('.accordion-vh-100 .collapse').on('show.bs.collapse', function () {
$(this).parents('.card').addClass('show');
});
$('.accordion-vh-100 .collapse').on('hide.bs.collapse', function () {
$(this).parents('.card').removeClass('show');
});
});
Here when we toggle the collapsible, I add/remove a CSS class .show on its parent .card.
Now we know which .card is opened when its collasible child is opened. We can start writing CSSs to make the accordion take up 100% viewport height.
First, I would like to introduce a separate CSS class for this 100% viewport height feature. Let's call it .accordion-vh-100. Another change I made was to change the .card-header from a div to an anchor tag so that the entire .card-header is clickable:
<div class="accordion accordion-vh-100" id="myAccordion">
<div class="card">
<a class="card-header" href="#collapseOne" data-toggle="collapse">
<h2 class="mb-0">Section 1</h2>
</a>
<div id="collapseOne" class="collapse" data-parent="#myAccordion">
<div class="card-body">...</div>
</div>
</div>
...
</div>
Next, we need to style the new .accordion-vh-100 to take up 100% viewport height, as well as to display as a flexbox with a column flow direction:
.accordion-vh-100 {
height: 100vh;
display: flex;
flex-flow: column nowrap;
}
Lastly, we need to grow the opened .card:
.accordion-vh-100 .card.show {
flex-grow: 1;
}
demo: https://jsfiddle.net/davidliang2008/b1duyLs8/24/
Check out this snippet:
<div class="accordion" id="myAccordion">
<div class="card">
<div class="card-header" id="section1" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<h2 class="mb-0">
<i class="fa fa-search" aria-hidden="true"></i> Section 1
</h2>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="section1" data-parent="#myAccordion">
<div class="card-body" style="height: 85vh;">
Some content here
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="section2" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<h2 class="mb-0">
<i class="fa fa-briefcase" aria-hidden="true"></i> Section 2
</h2>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="section2" data-parent="#myAccordion">
<div class="card-body" style="height: 85vh;">
some other content here
</div>
</div>
</div>
</div>
Here we applied style="height: 85vh;" on <div class="card-body"> to increase it height up-to 85% of view-port height.
If you going to add more cards, you will need to decrease this height, to display other card headers when one of the card expanded.

My space between div doesn't work with float and margin

I have two divs like this:
First div :
<div class="col-md-6" id="owner_name_76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" style="visibility: visible;float:left;margin-left:2px">
<div class="container-fluid">
<div class="row">
<span class="user" style="color:#000a75;font-weight:bold">Général</span>
</div>
</div>
</div>
Second div :
<div class="col-md-2 px-4 chevron-down collapsed" data-toggle="collapse" data-target="#76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" aria-expanded="false" style="float:right;margin-right:2px">
<i class="material-icons float-right material-expand ripple" style="color: #0047FD !important;margin-right:2px">expand_more</i>
</div>
This two div are in :
<a class="mdc-list-item" data-placement="top" title="Acceuil" style="cursor:pointer;width:400px;margin-left:4px;margin-right:0em" data-toggle="collapse" data-target="#76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a">
<div class="col-md-6" id="owner_name_76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" style="visibility: visible;float:left;margin-left:2px">
<div class="container-fluid">
<div class="row">
<span class="user" style="color:#000a75;font-weight:bold">Général</span>
</div>
</div>
</div>
<!--Collaspe zone-->
<div class="col-md-2 px-4 chevron-down collapsed" data-toggle="collapse" data-target="#76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" aria-expanded="false" style="float:right;margin-right:2px">
<i class="material-icons float-right material-expand ripple" style="color: #0047FD !important;margin-right:2px">expand_more</i>
</div>
</a>
Here what it looks like :
I want the space between the div to be greater than this , so i have tried with float and with margin but i have the same problem.
So i want the icon of expand more to be in the right margin 0 now it is in the center.
I think your codes is not completely posted here, so we have a difference in viewing.
But I see in your codes, the width has been set as fixed value 400px. That's why the icon could not move to right. Please remove the width:400px; in the a tag.
Maybe when you run code at your side, the a tag has been set display: block/inline-block .etc.. So you can see it can not move to right. That why we can not understand what you want.
Something like this? I need more details.
Just used d-flex from bootstrap.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<!-- just to show it whit boostrap -->
<a class="mdc-list-item" data-placement="top" title="Acceuil" style="cursor:pointer;" data-toggle="collapse" data-target="#76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a">
<div class="d-flex" id="owner_name_76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" style="visibility: visible;">
<div>
<span class="user" style="color:#000a75;font-weight:bold">Général</span>
</div>
<!--Collaspe zone-->
<div class="ml-auto px-4 chevron-down collapsed" data-toggle="collapse" data-target="#76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" aria-expanded="false">
<i class="material-icons float-right material-expand ripple" style="color: #0047FD !important;margin-right:2px">expand_more</i>
</div>
</div>
</a>
My problem was solved ! i followed this exemple
<div class="container">
<div class="row">
<div class="col-sm">
<div class="row">
<span class="user" style="color:#000a75;font-weight:bold">Général</span>
</div>
</div>
<div class="col-sm">
<div class="col-md-2 px-4 chevron-down collapsed" data-toggle="collapse" data-target="#76a62a154a220a104a16a203a196a25a92a71a58a216a222a172a64a" aria-expanded="false" style="float:right;margin-right:2px">
<i class="material-icons float-right material-expand ripple" style="color: #0047FD !important;margin-right:2px">expand_more</i>
</div>
</div>
</div>
</div>

Trying to line up text under Font Awesome icon

I'm currently using 2 Font Awesome icons. The problem is that I want to add text under each one that align with these icons. The problem is that the text is centered on the page but not under the corresponding icons.
Code:
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1 class="brand-heading">Title</h1>
<p class="intro-text">description</p>
<a href="#about" class="btn btn-circle page-scroll btn-lg">
<i class="fa fa-angle-double-down animated"></i>
</a>
<a href="#contact" class="btn btn-circle page-scroll">
<i class="fa fa-angle-double-up animated"></i>
</a>
</div>
</div>About Contact
</div>
I think this is what you want to do. Here is the fiddle:
http://jsfiddle.net/plushyObject/02s7wnm8/
<div class="col-md-8 col-md-offset-2 text-center outline">
<h1 class="brand-heading">Title</h1>
<p class="intro-text">description</p>
<div class="col-sm-4 outline">
<a href="#about" class="btn btn-circle page-scroll btn-lg outline">
<i class="fa fa-angle-double-down fa-fw"></i>
</a>
<p class="outline">
Text is centered by 'text-center' class inherited from first
column.
</p>
</div>
</div>
If you text-align the parent element, it will be inherited by the picture.
CSS
.container {
text-align: center;
}
Line it up using an HTML <table>, and style it with CSS. That way it will stay on top of the icons correctly.
http://jsfiddle.net/vd6smL75/