inside divs move on minimizing width of screen - css

I am having troubles with the css on how to make my content within a div that has a border to stay inside and horizontal. when the columns run out of room with their content the columns and content move down. I want them to stay horizontal and readable still instead of moving down below.
Picture before minimizing screen width:
Picture after minimizing screen width:
As you can see the the content inside doesnt stay put!!
Here is my html and some css:
<div class="container3" style="">
<div class="row">
<div class="col-md-11" style="min-width:760px;">
<div class="panel panel-default" style="">
<div class="panel-heading" >
<div >
<h style="margin-left:40px;">Your Requests </h>
</div>
<div style="float:right;margin-top:-30px;">Total: $<div id="sum" style="float:right;"> </div>
</div>
</div>
<% #revisers.each do |reviser| %>
<% reviser.reservations.where("status = ?", true).each do |reservation| %>
<script>
var total = <%= reviser.reservations.where("status = ?", true).sum(:total) %>;
$('#sum').html(total);
</script>
<div class="panel-body" style="">
<div class="col-md-12" style="border:3px solid black;height:108px;max-height:108px;min-width:703px;overflow:hidden;">
<!-- first column -->
<div class="row" style="">
<div class="col-sm-3 center" style="">
<div style="margin-left:-45px;">
<%= reservation.reviser.essay_type %>
</div>
</div>
<div class="col-sm-2 center" >
<div style=" margin-left:-40px;">
File
</div>
</div>
<div class="col-sm-2 center" >
<div style="margin-left:35px;">
Due
</div>
</div>
<div class="col-sm-2 center" >
<div style="margin-left:70px;">
File
</div>
</div>
<div class="col-sm-2 center" style="">
<div style="margin-left:110px;">
Total
</div>
</div>
</div>
<!-- second column -->
<div class="row" style="">
<div class="col-sm-2" style="">
<div style="margin-left:20px;">
<%= render 'shared/essayicons', reviser: reservation.reviser %>
</div>
</div>
<div class="col-sm-1" >
<li class="thumbnail2" style=""><%= image_tag(reservation.user.avatar.url(:thumb), :id => "image-tag", class: "portrait") %></li>
</div>
<div class="col-sm-1 center" style="margin-top:10px;">
<div class="row">
<div style="color:green;margin-left:10px;">
sent
</div>
</div>
<div class="row">
--->
</div>
</div>
<div class="col-sm-1">
<li class="thumbnail2"><%= image_tag(reservation.reviser.user.avatar.url(:thumb), :id => "image-tag", class: "portrait") %></li>
</div>
<div class="col-sm-2 center">
<%= reservation.due_date %>
</div>
<div class="col-sm-1">
<li class="thumbnail2"><%= image_tag(reservation.user.avatar.url(:thumb), :id => "image-tag", class: "portrait") %></li>
</div>
<div class="col-sm-1 center" style="margin-top:10px;">
<div class="row">
<div style="color:green;margin-left:10px;">
sent
</div>
</div>
<div class="row">
<---
</div>
</div>
<div class="col-sm-1">
<li class="thumbnail2"><%= image_tag(reservation.reviser.user.avatar.url(:thumb), :id => "image-tag", class: "portrait") %></li>
</div>
<div class="col-sm-1 center" style="margin-left:30px;">
<h4>$<%= reservation.total %></h4>
</div>
</div>
<!-- Third Column -->
<div class="row" style="">
<div class="col-sm-2 center">
<div>
<%= time_ago_in_words(reservation.created_at) %> ago
</div>
</div>
<div class="col-sm-2 center" style="">
<div style="margin-left:-45px;">
<%= reservation.user.username %>
</div>
</div>
<div class="col-sm-2 center">
<div style="margin-left:-40px;">
<%= reservation.reviser.user.username %>
</div>
</div>
<div class="col-sm-2 center" >
<div style="margin-left:70px;">
<%= reservation.user.username %>
</div>
</div>
<div class="col-sm-2 center" >
<div style="margin-left:50px;">
<%= reservation.reviser.user.username %>
</div>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
SCSS file:
.container3{
margin:auto;
width:80%;
}
.panel {
border-radius: 8px;
}
.panel-default .panel-heading {
color: #565a5c;
background-color: #edefed;
font-size: 18px;
font-weight: 400;
}
.panel-heading{
margin:0 auto;
h1 {
text-align: center;
}
}
.panel-body{
margin-top: 0px;
}
How can i get these divs to stop moving underneath each other? Just keep them put and if someone reduces screen width then they will just not be shown on screen unless the user extends the screen again, just like how the total on the header near Your Requests isn't showing up at a certain point when I minimize screen. Thank you!!^^

Just add .hidden-xs and .hidden-sm to the offending col-md-* divs
http://getbootstrap.com/css/#responsive-utilities

Related

Aligning text to the right in a table using Bootstrap

As part of my experimentation in learning Bootstrap, I created a table without actually using any of the tags that correspond to making a table. Instead, I used the grid system. While it looks decent, I was wondering if there was a way to align the numbers to the right? I have provided a JSFiddle link to show you what I came up with. Any help or leads are appreciated.
https://jsfiddle.net/silosc/9jbd1rpw/2/
<div class="container-xl">
<div class="report-card-weekly-report">
<div class="CompanyName">
<h1>Weekly Summary for John's Groceries</h1>
<h4> Week Ending: 01/20/2010</h4>
</div>
<br />
<div class="row">
<div class="col-sm-2">
</div>
<div class="col-sm-2">
<p>Number of Sales</p>
</div>
<div class="col-sm-2">
<p>Total earnings</p>
</div>
<div class="col-sm-2">
<p>Taxes charged</p>
</div>
<div class="col-sm-2">
<p>Refunds</p>
</div>
<div class="col-sm-2">
<p>Deliveries</p>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<h2>Total numbers</h2>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<p>Numbers for the week</p>
</div>
<div class="col-sm-2">
21,922
</div>
<div class="col-sm-2">
$0.00
</div>
<div class="col-sm-2">
$304,431.37
</div>
<div class="col-sm-2">
$0.00
</div>
<div class="col-sm-2">
$0.00
</div>
</div>
</div>
</div>
<style>
.CompanyName {
text-align: center;
}
h2 {
color: orangered;
margin-left: 15px;
}
p {
font-weight: bold;
font-size: 15px;
margin-left: 15px;
}
p1 {
text-align: right;
}
</style>
You can use the text-right property of bootstrap to align your desired text to the right. Here is a small piece of code to show you how it will work in your example.
<div class="col-sm-2 text-right">
21,922
</div>
similarly, you can also align the text to left with text-left property.
You can use the text-right class of bootstrap:
<div class="container-xl">
<div class="report-card-weekly-report">
<div class="CompanyName">
<h1>Weekly Summary for John's Groceries</h1>
<h4> Week Ending: 01/20/2010</h4>
</div>
<br />
<div class="row">
<div class="col-sm-2">
</div>
<div class="col-sm-2">
<p>Number of Sales</p>
</div>
<div class="col-sm-2">
<p>Total earnings</p>
</div>
<div class="col-sm-2">
<p>Taxes charged</p>
</div>
<div class="col-sm-2">
<p>Refunds</p>
</div>
<div class="col-sm-2">
<p>Deliveries</p>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<h2>Total numbers</h2>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<p>Numbers for the week</p>
</div>
<div class="col-sm-2 text-right">
21,922
</div>
<div class="col-sm-2 text-right">
$0.00
</div>
<div class="col-sm-2 text-right">
$304,431.37
</div>
<div class="col-sm-2 text-right">
$0.00
</div>
<div class="col-sm-2 text-right">
$0.00
</div>
</div>
</div>
</div>
<style>
.CompanyName {
text-align: center;
}
h2 {
color: orangered;
margin-left: 15px;
}
p {
font-weight: bold;
font-size: 15px;
margin-left: 15px;
}
p1 {
text-align: right;
}
</style>
See the JsFiddle here.

Bootstrap 4: Equal width columns using grid

I am attempting to make the layout of a container with a row and an accordion beneath it have equal width columns using the bootstrap grid. The problem is with aligning the data within the accordion to the top most row.
My understanding with bootstrap 4 is that the col class should auto-size per column so I would think all 8 columns would be the same width regardless of content.
The top looks okay but the rows below are condensed. Here is an example:
Here is my razor page below:
<body>
<div class="container">
<div class="row">
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].Item)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].ItemDescription)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].CorpCustomer)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].UoM)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].SummedOrder)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].SummedForecast)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].Difference)
</div>
<div class="col">
#Html.DisplayNameFor(model => model.ReportHighLevel[0].Week)
</div>
</div>
</div>
<div class="container">
<div id="accordion">
#{int counter = 0; }
#foreach (var dataVM in Model.CollapseReport)
{
<div class="card">
<div class="card-header" id="heading#(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse#(counter)" aria-expanded="true" aria-controls="collapse#(counter)">
<div class="row">
<div class="col">
#dataVM.Summary.Item
</div>
<div class="col">
#dataVM.Summary.ItemDescription
</div>
<div class="col">
#dataVM.Summary.CorpCustomer
</div>
<div class="col">
#dataVM.Summary.UoM
</div>
<div class="col">
#dataVM.Summary.SummedOrder
</div>
<div class="col">
#dataVM.Summary.SummedForecast
</div>
<div class="col">
#dataVM.Summary.Difference
</div>
<div class="col">
#dataVM.Summary.Week
</div>
</div>
</button>
</h5>
</div>
<div id="collapse#(counter)" class="collapse" aria-labelledby="heading#(counter)" data-parent="#accordion">
<div class="card-body">
<form method="post">
<input type="hidden" name="var1" value="#dataVM.Summary.CorpCustomer" />
<input type="hidden" name="var2" value="#dataVM.Summary.Item" />
<input type="submit" class="btn btn-default" value="Add to Log" asp-page-handler="AddLog" asp-route-data="#dataVM.Summary.CorpCustomer, #dataVM.Summary.Item)" />
</form>
<div class="container">
#foreach (var item in dataVM.WeeksOfData)
{
<div class="row">
<div class="col">
#item.Item
</div>
<div class="col">
#item.ItemDescription
</div>
<div class="col">
#item.CorpCustomer
</div>
<div class="col">
#item.UoM
</div>
<div class="col">
#item.SummedOrder
</div>
<div class="col">
#item.SummedForecast
</div>
<div class="col">
#item.Difference
</div>
<div class="col">
#item.Week
</div>
</div>
}
</div>
</div>
</div>
</div>
counter++;
}
</div>
</div>
The reason is your btn btn-link button nested in <h5>. .btn class from Bootstrap is with style display: inline-block;, which doesn't take up the 100% width.
Even you set width: 100%; on the button, your columns still won't be aligned because:
.btn has style of white-space: nowrap; hence the texts inside your collapsable heading won't wrap, while the texts inside the collapsable body will.
.btn class has .75rem padding left and right, which will take up the overall row width.
You have a nested container inside your collapsable body. The container has 15px padding left and right, which will take up the overall row width as well.
Hints: you might want to think of a different design / layout.
For example, get rid of the button nested in the heading and use anchor isntead:
<div class="container">
#for (int i = 0; i < 5; i++)
{
<div class="card">
<div class="card-header">
<a href="#" data-toggle="collapse" data-target="#collapse#(i)">
<div class="row">
<div class="col">Item</div>
<div class="col">Item Description</div>
<div class="col">Corp Customer</div>
<div class="col">UoM</div>
<div class="col">Summed Order</div>
<div class="col">Summed Forecase</div>
<div class="col">Difference</div>
<div class="col">Week</div>
</div>
</a>
</div>
<div id="collapse#(i)" class="collapse">
<div class="card-body">
<div class="row">
<div class="col">Item</div>
<div class="col">Item Description</div>
<div class="col">Corp Customer</div>
<div class="col">UoM</div>
<div class="col">Summed Order</div>
<div class="col">Summed Forecase</div>
<div class="col">Difference</div>
<div class="col">Week</div>
</div>
<div class="row">
<div class="col">Item</div>
<div class="col">Item Description</div>
<div class="col">Corp Customer</div>
<div class="col">UoM</div>
<div class="col">Summed Order</div>
<div class="col">Summed Forecase</div>
<div class="col">Difference</div>
<div class="col">Week</div>
</div>
<div class="row">
<div class="col">Item</div>
<div class="col">Item Description</div>
<div class="col">Corp Customer</div>
<div class="col">UoM</div>
<div class="col">Summed Order</div>
<div class="col">Summed Forecase</div>
<div class="col">Difference</div>
<div class="col">Week</div>
</div>
</div>
</div>
</div>
}
</div>
Screenshot:

Need help arrange items in a div with bootstrap

I'm trying to arrange a div like this but can't get it to work.
What I'm getting is this
My thought was to keep the image in its own column and then split the other columns into smaller rows and insert there but that doesn't seem to work. Here's my code:
<a href="#" class="list-group-item list-group-item-action flex-column align-items-start">
<div class="row d-flex w-100 justify-content-between products-div">
<div class="col-sm-1">
<img [src]="prod.imagePath" class="product-page-images">
</div>
<div class="row">
<div class="col-sm-10">
<h3 class="mb-1">{{prod.name}}</h3>
<p class="products-price-text">${{prod.price}}</p>
</div>
</div>
<div class="row">
<div class="col-sm-10">
<h5 class="mb-1">{{prod.seller}}</h5>
</div>
</div>
<div class="row">
<div class="col-sm-10">
<p class="mb-1">{{prod.description}}</p>
</div>
</div>
</div>
</a>
HTML
<div class="container">
<div class="row">
<div class="main-container clearfix">
<div class="col-md-1">
<div class="img-con">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Small-city-symbol.svg/348px-Small-city-symbol.svg.png" alt="" />
</div>
</div>
<div class="col-md-11">
<div class="row">
<div class="col-md-12">
<div class="clearfix">
<div class="pull-left">
<h3>Name</h3>
<small>Seller</small>
</div>
<div class="pull-right">
<h3>Price</h3>
</div>
</div>
</div>
<div class="col-md-12">
<div class="desc">
description
</div>
</div>
</div>
</div>
</div>
</div></div>
css
.main-container
{
border:1px solid ;
}
.img-con
{
height:100%;
width:100%;
}
.img-con img
{
max-width:inherit;
max-height:inherit;
height:100%;
width:100%;
}
.desc
{
border:1px solid;
}
reference link
and style accordingly.. hope this helps

Bootstrap panel-heading with vertical-middle char/icon

How can I get the x positioned vertical middle when displaying on small devices (< 600px width)?
<div class="row">
<div class="col-sm-12">
<section class="panel panel-default panel-slider"><div class="panel-heading">
<h1 class="panel-title" style="font-size:18px">
Test with long description in title panel bla bla<a class="align-middle more pull-right" href="https://example.com" title="" data-toggle="tooltip" data-placement="right" data-original-title="more" ><i>x</i></a>
</h1>
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8" style="margin-bottom: 10px;">
...
</div>
</div>
Currently it is:
Should be:
https://jsfiddle.net/9dtu4en1/
Thanks in advance!
Kind regards
Alex
I'd use flexbox on that h1 for a more fluid resizing, and remove align-middle & pull-right (to avoid floating which would make it's parent not consider child's height) from a:
External Fiddle to resize
Snippet:
h1 {
display: flex;
justify-content: space-between;
align-items: center;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-sm-12">
<section class="panel panel-default panel-slider">
<div class="panel-heading">
<h1 class="panel-title" style="font-size:18px">Test with long description in title panel bla bla
<a class="more" href="https://example.com" title="" data-toggle="tooltip" data-placement="right" data-original-title="more"><i>x</i></a>
</h1>
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8" style="margin-bottom: 10px;">
...
</div>
</div>

Layout has wide rows when browser width is smaller

here's my markup:
<style>
a.item
{
border:1px solid #aaa;
background:#ddd;
padding:10px;
display:block;
}
span.price
{
display:block;
text-align:center;
background:#555;
color:white;
}
</style>
<div class="main">
<div class="row">
<div class="col-md-3">
<a class="item" href="#">
<div class="row">
<div class="col-md-6">
IMAGE
</div>
<div class="col-md-6">
<span class='price'>123.45</span>
</div>
</div>
</a>
</div>
<div class="col-md-3">
<a class="item" href="#">
<div class="row">
<div class="col-md-6">
IMAGE
</div>
<div class="col-md-6">
<span class='price'>123.45</span>
</div>
</div>
</a>
</div>
<div class="col-md-3">
<a class="item" href="#">
<div class="row">
<div class="col-md-6">
IMAGE
</div>
<div class="col-md-6">
<span class='price'>123.45</span>
</div>
</div>
</a>
</div>
<div class="col-md-3">
<a class="item" href="#">
<div class="row">
<div class="col-md-6">
IMAGE
</div>
<div class="col-md-6">
<span class='price'>123.45</span>
</div>
</div>
</a>
</div>
</div>
</div>
it looks fine - like this:
the problem however is - when decreasing the browser window's width, it will destroy the layout and will look like this:
"image" and price are not side-bye-side anymore .. any ideas what's wrong with my code?
thanks
Include col-xs-6 next to col-md-6.
https://jsfiddle.net/gqmarfkh/ jsFiddle - I changed 2 of them as an example.
If you change .col-md-6 to col-xs-6 it should solve your problem. The class col-md-6 has no value untill the screen size is medium and up. Class col-xs-* will have a value from x-small and up. Check out this link: http://getbootstrap.com/css/#grid-options

Resources