I have a card-group with several cards like this:
<div class="card-group">
<div class="justify-content-start p-3">
<div class="card bg-light text-center p-0" style="width: 10rem;">
<div class="card-header justify-content-right align-middle">
<span class="align-middle"><h3> {{ item[1] }} </h3></span>
</div>
<div class="card-body justify-content-center">
<img class="w-50 m-2" style="image-rendering: pixelated;" src="../static/icon.png">
<div class="input-group mt-3 w-100">
<button type="button" class="btn btn-outline-primary w-75" id="toggleButton">Water</button>
<button type="button" class="btn btn-outline-primary w-25" data-bs-toggle="collapse" data-bs-target="#timeCollapse" aria-expanded="false" aria-controls="collapseButton">
<i class="bi bi-three-dots-vertical"></i>
</button>
</div>
<div class="collapse mt-2" id="timeCollapse">
<input type="text" class="form-control" aria-label="Time Input Dropdown">
</div>
</div>
</div>
</div>
</div>
When Testing on Chrome, they work perfectly, stacking into multiple rows.
However when I turn on the mobile Layouts/Narrow the Viewport, the cards start to all go into individual rows.
I have tried narrowing the cards, to make sure they are not just too wide, but nothing seems to work.
What could cause this issue? Also is there a 'smart' width feature for cards, similar to css background-repeat: round;
Related
I need to have my button occupy the whole width when the view is small such as viewing it on a mobile phone. This is what I have so far...
Large Device
Medium Device
Small Device
On medium to small device, I need to have the button take up the whole block. I am not using any custom css yet. I'm just using the bootstrap default. Please see my code below:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<header class="p-3 bg-dark text-white">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-white text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"></use></svg>
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li>Home</li>
<li>Features</li>
<li>Pricing</li>
<li>FAQs</li>
<li>About</li>
</ul>
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" style="display:flex; align-items:inherit;">
<input type="text" class="form-control form-control-dark" placeholder="Username" aria-label="Username">
<input type="password" class="form-control form-control-dark" placeholder="Pasword" aria-label="Password">
<button type="submit" class="form-control btn btn-outline-light" style="margin-left: 1rem!important;">Login</button>
</form>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
<button class="btn btn-primary me-md-2" type="button">Button</button>
<button class="btn btn-primary" type="button">Button</button>
</div>
#*
<div class="text-end d-sm-block gap-2">
<button type="button" class="btn btn-warning" style="width:100%; display:block;">
Sign-up
</button>
</div>*#
</div>
</div>
</header>
Try this.... The only change is adding d-grid gap-2 to the Div which houses your button. You may have to edit the number 2 to get your fully desired effect. With this you can probably remove the style= from your button too.
<div class="text-end d-grid gap-2">
<button type="button" class="btn btn-warning" style="width:100%; display:
block;">Sign-up</button>
</div>
I am learning Bootstrap and now I am facing a problem that I just couldn't get it.
This is a snippet of the code:
<button
className="
col-md-4
col-sm-auto
btn
btn-info
btn-custom"
onClick={this.toggleModalHandler}
> Salvar
</button>
Here a somewhat more complete code:
<div className="container">
<h2 className="border-bottom mb-4 pt-sm-2">Insira Os Valores Do Produto</h2>
<div className="pt-4 border-bottom">
<h5>Valor Total: R$ </h5>
<div className="
row
align-items-md-center
mb-2
flex-md-row
flex-sm-column"
>
<h5 className="col-md-4 col-sm-auto mb-md-0">Valor Total Acumulado: R$</h5>
<div className="col-md-8 col-sd-12">
<button
className="col-auto btn btn-success btn-custom"
onClick={() => this.addOrcHandler()}
> Adicionar Orçamento
</button>
<button
className="col-auto btn btn-danger btn-custom"
onClick={() => this.limparHistoricoOrcHandler()}
> Limpar Orçamentos
</button>
<button
className="col-md-4 col-sm-auto col-3 btn btn-info btn-custom"
onClick={this.toggleModalHandler}
> Salvar
</button>
</div>
</div>
</div>
</div>
As I understand it so far col-md-4 should override col-sm-auto when the screen is bigger than 768px, but it is not working and I don't know why, since it worked properly in other elements.
I couldn't find an answer to this specific situation on my researches.
What I am not getting is why col-md-4 is not ocuppying 4 columns of the grid.
Just an observation: It works fine if I remove col-sm-auto. And it is in a row
What am I doing wrong?
You see, the .col uses for blocks which are the part of Bootstrap Grid. For correct work they should be covered in .row and .container parents. Although, you shouldn't mix it with button and .btn, because they works with different logic and for different purpose. The correct code is:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row">
<div class="col-md-4 col-sm-auto">
<button class="btn btn-info btn-custom btn-block">Salvar</button>
</div>
</div>
</div>
UPDATED
More about .col wrapping https://getbootstrap.com/docs/4.0/layout/grid/#column-wrapping
Added .btn-block for .btn to get them 100% in a parent .col.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
<div class="container">
<h2 class="border-bottom mb-4 pt-sm-2">Insira Os Valores Do Produto</h2>
<div class="pt-4 border-bottom">
<h5>Valor Total: R$ </h5>
<div class="row align-items-md-center mb-2 flex-md-row flex-sm-column">
<h5 class="col-md-4 col-sm-auto mb-md-0">Valor Total Acumulado: R$</h5>
<div class="col-md-8 col-sd-12">
<div class="row">
<div class="col-sm-4 col-auto">
<button class="btn btn-success btn-custom btn-block">Adicionar Orçamento</button>
</div>
<div class="col-sm-4 col-auto">
<button class="btn btn-danger btn-custom btn-block">Limpar Orçamentos</button>
</div>
<div class="col-sm-4 col-auto">
<button class="btn btn-info btn-custom btn-block">Salvar</button>
</div>
</div>
</div>
</div>
</div>
</div>
I am creating an angular application in which i have an detail page with a cardheader which consist of two buttons namely back and edit and both sides and a text in between.
I have used bootstap and set the columns like below.
But when i see the screen in mobile view the header is not aligned properly
Below is the code i am using. How could i fix it to view in a single line in mobile view
<div class="card-header">
<div class="row">
<div class="col-sm-3 col-lg-3 text-left">
<button size="sm" class="btn btn-primary" (click)="goBack()">
<i class="fa fa-chevron-left"></i> Back
</button>
</div>
<div class="col-sm-6 col-lg-6 text-center">
<h4>Switch Detail</h4>
</div>
<div class="col-sm-3 col-lg-3 text-right">
<button size="sm" class="btn btn-primary" (click)="gotoEdit()">
<i class="fa fa-pencil"></i> Edit
</button>
</div>
</div>
</div>
There is a couple of approach you can follow.
You could force the width of the container to stay constant on all views. Note that this can cause your text to overflow.
<div class="card-header">
<div class="row">
<div class="col-3 text-left">
<button size="sm" class="btn btn-primary" (click)="goBack()">
<i class="fa fa-chevron-left"></i> <span class="button-text"> Back
</span>
</button>
</div>
<div class="col-6 text-center">
<h4>Switch Detail</h4>
</div>
<div class="col-3 text-right">
<button size="sm" class="btn btn-primary" (click)="gotoEdit()">
<i class="fa fa-pencil"></i> <span class="button-text"> Edit </span>
</button>
</div>
</div>
</div>
You could use #media Query to hide the text on the buttons leaving only the icons on a mobile view.
#media screen and (max-width: 560px) {
button-text {
display: none;
}
}
Alternatively, you could reduce the font size of the title on mobile using the same approach in case 2 above.
I can't find a good answer for this. I'm just trying to get the centered elements to line up between the two lines, as in Bootstrap's documentation. There isn't any extra margin or padding that could be throwing them off, and there doesn't seem to be any difference between justify-content-center and d-flex on parent, mx-auto on element combination. Any ideas?
Also, is d-flex flex-column necessary on all of these or is there a more efficient way to line the label and button up so they're centered as shown?
EDIT: Here's the actual code
<div v-if="isDeepSearch" class="d-flex flex-column">
<div class="d-flex flex-column">...omitted for brevity; not relevant...</div>
<div class="d-flex justify-content-around">
<div class="d-flex flex-column text-center">
<label for="isRead">Read State</label>
<button id="isRead" type="button" class="btn btn-sm btn-danger">Unread</button>
</div>
<div class="d-flex flex-column text-center">
<label for="importance">Importance</label>
<div
id="importance"
class="btn-group mt-auto"
role="group"
aria-label="Importance buttons"
>
<button type="button" class="btn btn-sm btn-secondary">Low</button>
<button type="button" class="btn btn-sm btn-warning">Medium</button>
<button type="button" class="btn btn-sm btn-danger">High</button>
</div>
</div>
<div class="d-flex flex-column text-center">
<label for="isRead">Has Attachment</label>
<button id="isRead" type="button" class="btn btn-sm btn-success">Yes</button>
</div>
</div>
</div>
<div class="d-flex justify-content-center">
<button
class="my-3 btn btn-lg btn-success"
:disabled="isSearchDisabled"
#click.prevent="search()"
>
<div v-if="!searching">
<i class="fas fa-search"></i> Search
</div>
<div v-else>
<i class="fas fa-spinner fa-spin"></i> Searching...
</div>
</button>
</div>
Got it. Thanks to #birdspider who cleared up my misunderstanding of justify-content-around. The issue was that the 3 items are not being centered in a 3-column-type layout, but rather ensuring that the space around them is equal. Since the items aren't all the same width, that was causing the middle element to be slightly off to the left. Solution I used was to add col-4 to each element and row to the parent.
I have this in my html:
.btn {
height: 100%;
font-size: 10em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container-fluid mb-5">
<div class="row ">
<div class="col pl-0 pr-0 ml-5">
<button type="button" class="btn btn-primary btn-block">ONE</button>
</div>
<div class="col pl-0 pr-0 ml-5">
<button type="button" class="btn btn-primary btn-block">TWO</button>
</div>
<div class="col pl-0 pr-0 ml-5 mr-5">
<button type="button" class="btn btn-primary btn-block">THREE</button>
</div>
</div>
</div>
The problem that I am having is that when I resize browser buttons stick to the right side and to eachother. What can be done here? Any help appreciated!
Please run this in your browser rather than using snippet to have a better response
See I have changed one thing in your code . What I did was just added col-sm for div classes. You can find more about bootstrap grid system via this link. Bootstrap grid system .
I think you expect this.
To see the result please expan the snippet and then with Inspect Element in you browser and then navigate to mobile view . Thanks
Update
In addition to what you asked at the chat I have added some custom css which is responsive to increase the font size . Just added style="font-size:5vw;".The text size can be set with a vw unit, which means the "viewport width".
That way the text size will follow the size of the browser window:
This is the new view after adding style="font-size:5vw;"
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container-fluid mb-5 ">
<div >
<div class="container-fluid mb-5 ">
<div class="row ">
<div class="col pl-0 pr-0 ml-5 col-sm-3">
<button type="button" style="font-size:5vw;" class=" btn btn-primary btn-block">ONE</button>
</div>
<div class="col pl-0 pr-0 ml-5 col-sm-3">
<button type="button" style="font-size:5vw;" class=" btn btn-primary btn-block">TWO</button>
</div>
<div class="col pl-0 pr-0 ml-5 mr-5 col-sm-3">
<button type="button" style="font-size:5vw;" class=" btn btn-primary btn-block">THREE</button>
</div>
</div>