How do I fix weird offsets in bootstrap columns - css

How do I make my pictures be aligned in the center when the screen shrinks to small to keep them side by side? I tried using columns, but it has a weird offset and it won't scoot to the side or align in a straight column when needed.
Here is my code:
<h2 class="text-center h2">Recent Projects</h2>
</div>
<div class="pics col-md-4 col-md-offset-2 col-xs-10 col-xs-offset-1">
<a href="350_project.html">
<img src="images/IMG_2579.JPG" width="450" height="350">
</a>
<h3 class="text-center">350 Project</h3>
</div>
<div class="pics col-md-6 col-md-offset-1 col-xs-10 col-xs-offset-1">
<a href="silk_screening.html">
<img src="images/IMG_0978.JPG" width="450" height="350">
</a>
<h3 class="text-center">Silk Screening</h3>
</div>
<div class="pics col-md-4 col-md-offset-2 col-xs-10 col-xs-offset-1">
<a href="compost.html">
<img src="images/IMG_7793.JPG" width="450" height="350">
</a>
<h3 class="text-center">Food Feud</h3>
</div>
<div class="pics col-md-6 col-md-offset-1 col-xs-10 col-xs-offset-1">
<a href="terracycle.html">
<img src="images/Official_TerraCycle_Logo.png" width="450" height="350">
</a>
<h3 class="text-center">TerraCycle</h3>
</div>

You could use #media queries, making your div having something like "margin: auto" at a certain screen size or with a global parent div with "text-align:center".
Don't forget bootstrap grid item have a default "float:left" attribut, maybe you'll have to change it with #media queries.
I used it in my last project. I don't know it my objectives are compatibles with yours but it could help you.
<div class="container_losange container_losange_mission col-lg-4 col-md-4 col-sm-4 col-xs-8"> //content </div>
<div class="container_losange container_losange_mission float-right col-lg-4 col-md-4 col-sm-4 col-xs-8"> //content </div>
<div class="container_losange container_losange_mission col-lg-4 col-md-4 col-sm-4 col-xs-8"> //content </div>
<div class="clear"></div>
<div class="container_losange container_losange_mission float_none float-right col-lg-4 col-md-4 col-sm-4 col-xs-8"> //content </div>
<div class="container_losange container_losange_mission float_none float-left col-lg-4 col-md-4 col-sm-4 col-xs-8"> //content </div>
Then here I have 3 + 2 divs. The 2 last divs are center in the page because I make some modification :
.section_mission {
text-align: center;
.container_losange_mission {
display: inline-block;
&.float_none {
float: none;
}
}
float-right and float-left are just here for the specific design of the mobile view. (to have a "staggered" structure)
The clear div doesn't seems to be needed, I didn't remember why I used it.
/* Extra small devices (Phones (<768px)) */
#media(max-width:767px){
.section_mission {
.container_losange_mission.float-right { float: right !important; }
.container_losange_mission.float-left { float: left !important; }
}
}
I don't know if my explications are usefull for you because I'm not sure it'll works with random number of elements..
If not, have a look on the CSS3 new functionnality FLEX:
http://the-echoplex.net/flexyboxes/
http://www.alsacreations.com/tuto/lire/1493-css3-flexbox-layout-module.html
Could be usefull on this type of problem

Related

How to make same size div for diff size image and title length in bootstrap

I am working on an angular project where I am getting the data in image and title and location. I tried to make a responsive div but unable to make them in one size.
<div *ngFor="let company of companies" class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-12">
<div class="card">
<div class="card-content">
<div class="card-body py-0 text-center">
<input [checked]="true" type="radio" formControlName="scope" (click)="nextFormPostion(nextFormPostionName)" (change)="nextFormPostion(nextFormPostionName)" id="img{{company.scope}}" class="d-none imgbgchk" value="{{company.scope}}">
<label for="img{{company.scope}}">
<div class="row justify-content-center">
<div class="col-12" style="height: 6rem ; display:table-cell; vertical-align: middle;">
<img src="{{company.logo}}" class="mt-1 img-fluid mh-100" alt="Image 1">
</div>
<div class="col-12 mt-2" style="min-height: 3rem;font-size: 12px;text-transform: none;">
<span>{{company.company}}</span>
</div>
<div class="col-12 mt-1" style="min-height: 2.5rem;font-size: 12px;text-transform: none;">
<span>{{company.country}}</span>
</div>
</div>
<div class="tick_container">
<div class="tick"><i class="fa fa-check"></i></div>
</div>
</label>
</div>
</div>
</div>
</div>
company.logo is the image path and company.company is the name of the company. I want to make image in vertical and horizontal align center and if company name length is new line it change the size of all divs.
You don't need bootstrap exactly to do that you can use JavaScript to get the div side you want and apply as width + height.
Also you can use CSS with, for example:
width: 100%
The first thing you need to check if you have any border, margin, padding that is affecting your code. I don't know, I don't have enough information. But I believe it could be because Bootstrap puts automatic padding on .row
For this you can put
<div class="row g-0">
</div>
Bootstrap 5 - No gutters
Or if it is in another element, simply add the px-0 class that removes the padding from the widths.

Using uneven offsets for centering content in Bootstrap

Using Bootstrap 3, I'm trying to center a image on its own row. Here is what I have, which responds well across display sizes:
<div class="row">
<div class="col-lg-2 col-lg-offset-5 col-md-2 col-md-offset-5 col-sm-4 col-sm-offset-4 col-xs-6 col-xs-offset-3 text-center">
<img src="img.jpg" class="img-responsive">
</div>
</div>
However, .img-responsive sets max-width: 100%. The image is too large on some displays. For example, I'd rather have col-lg-1 than col-lg-2.
Obviously, I could do col-lg-1 col-lg-offset-5 but the content will be off-center.
Is there an equivalent to col-lg-1 col-lg-offset-5.5, or some other method to center content in this scenario?
I would say no by default. But It can be possible with Bootstrap customize then you can define your custom responsive grid column with #grid-columns. You can specify 16.
<div class="row">
<div class="col-lg-2 col-lg-offset-7 text-center">
<img src="img.jpg" class="img-responsive">
</div>
</div>
Or you can just style your image to be smaller width.
<div class="row">
<div class="col-lg-2 col-lg-offset-5 col-md-2 col-md-offset-5 col-sm-4 col-sm-offset-4 col-xs-6 col-xs-offset-3 text-center">
<img src="img.jpg" class="img-resize img-responsive">
</div>
</div>
<style type="text/css">
.img-resize {
width: 200px;
}
</style>

bootstrap grid system : how to remove gap between two columns

I am using bootstrap grid to have the responsive layout.
But I am unable to remove gap between two columns.
my code is as follows:
<div class="contact-us-box">
<div class="container-fluid">
<div class="row">
<div class="col-lg-2 col-md-2">
</div>
<div class="col-lg-6 col-md-7 col-sm-8 col-xs-12 text-center">
<p class="contact-us-footer">Choose Share&Care as your development partner </p>
</div>
<div class="col-lg-4 col-md-3 col-sm-4 col-xs-12 text-center">
<a class="contact-us-link" href="../contact-us.php">
<i class="fa fa-envelope-o"></i> Contact Now!
</a>
</div>
</div>
</div>
</div>
my output is:
I want to remove the gap between partner and contact now button.
please help me is this regard.
My Solution
here is my solution:
<div class="contact-us-box">
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-9 col-xs-12 contact-us-gap-p">
<p class="contact-us-footer">Choose Share&Care as your development partner </p>
</div>
<div class="col-lg-4 col-md-4 col-sm-3 col-xs-12 contact-us-gap-a">
<a class="contact-us-link" href="contact-us.php">
<i class="fa fa-envelope-o"></i> Contact Now!
</a>
</div>
</div>
</div>
</div>
here is my css file :
.contact-us-gap-p{
text-align: right;
}
.contact-us-gap-a{
text-align: left;
}
#media (max-width: 768px) {
.contact-us-gap-p{
text-align: center;
}
.contact-us-gap-a{
text-align: center;
}
}
This code is working fine for me.
Here I used css inline for semplicity, but using class is better. I simply aligned the text of the two div to reduce the gap between the two columns.
<div style="text-align: right;" class="col-lg-6 col-md-7 col-sm-8 col-xs-12 text-center">
...
</div>
<div style="text-align: left;" class="col-lg-4 col-md-3 col-sm-4 col-xs-12 text-center">
If you do not want this to apply in mobile version, insert this code into media query for screen only
....

How to make text not to overflow box in bootstrap

i am using Bootstrap 3, and i have a text within a col and when it's longer, it does not fit the div and overflows it in the width of the box. I have used different display styles, do a lot of search but without success.
<div class="container-fluid">
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-12 col-xs-12 col-lg-offset-1 col-md-offset-2">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="thumbnail">
<img src="http://www.kungfunguyen.com/wp-content/uploads/2013/08/Bootstrap-2-1-Is-the-Latest-Update-to-Twitter-s-Popular-Open-Source-Project.png">
<div class="caption">
Very long text which oveflows the whole div in width.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</div>
</div>
</div>
</div>
</div>
</div>
Example with thumbnail and caption, the same problem
http://jsfiddle.net/zqeLse5q/
Thanks
.caption{
word-wrap: break-word;
}
http://jsfiddle.net/zqeLse5q/2/

Bootstrap Grid Layout

My CSS isn't picking up my different columns. They are stacked on top of each other. I want each of them each to span 4 columns of the same row.
<div class="container">
<div class="row">
<div class="col-md-4" id="directionsPanel1">
<h3 class="directions-discription" id="directions-info1"></h3>
</div>
<div class="col-md-4" id="directionsPanel2">
<h3 class="directions-discription" id="directions-info2"></h3>
</div>
<div class="col-md-4" id="directionsPanel3">
<h3 class="directions-discription" id="directions-info3"></h3>
</div>
How about this using floats. You can apply the float which is the pull-left helper class to the div.col-md-4 and then they won't stack upon each other.
Updated JS fiddle but you shouldn't need to float left in the CSS, couldn't get JS fiddle to pull bootstrap stuff. http://jsfiddle.net/4xEPr/7/
<div class="container">
<div class="row">
<div class="col-md-4 pull-left" id="directionsPanel1">
<h3 class="directions-discription" id="directions-info1"></h3>
</div>
<div class="col-md-4 pull-left" id="directionsPanel2">
<h3 class="directions-discription" id="directions-info2"></h3>
</div>
<div class="col-md-4 pull-left" id="directionsPanel3">
<h3 class="directions-discription" id="directions-info3"></h3>
</div>
AND CSS
div.col-md-4 {
border: 1px solid #333;
width: 200px;
background-color: red;;
}

Resources