Bootstrap Image Sizing In Column - html

I am currently having an issue with Bootstrap that involves html content in one column and an image in another.
For example, I have this html:
<div class="container-fluid main">
<div class="row">
<div class="col-xs-12 col-md-12 col-sm-12 col-lg-5 new-offers-text">
<h2>The new Tivoli now with half price specification upgrades</h2>
<ul>
<li>Half price upgrade from an SE to an EX model - saving <strong>£825</strong></li>
<li>Half price upgrade from an EX to an ELX – saving <strong>£700</strong></li>
</ul>
<p>Offer available until 31st October 2015 and on <strong>petrol engines</strong> only.</p>
<div class="clear spacer"></div>
<h3>Tivoli PCP</h3>
<p>SsangYong Tivoli is now available through a PCP giving you peace of mind.</p>
<p><strong>And for a limited time only, Tivoli EX petrol manuals purchased through PCP are eligible for 3 years free servicing</strong></p>
<p>With low monthly payments and SsangYong providing a Guaranteed Future Value for your vehicle you have three options on completion of your contract:</p>
<ul>
<li>Option 1 - Pay final payment & keep the car</li>
<li>Option 2 - Return the car</li>
<li>Option 3 - Trade in against a new SsangYong</li>
</ul>
<p>Talk to us about tailoring a personal quotation to meet your needs.</p>
</div>
<div class="col-xs-12 col-md-12 col-sm-12 col-lg-7">
<img src="/media/wysiwyg/porto/cmspages/ssangyong/tivoli/towing.jpg" class="manufacturer-logo">
</div>
</div>
</div>
As you can see I have an image in the col-lg-7, the issue I am now having is that when the page is scaled down horizontally I get a large area of white space because the content container get's narrow.
Here is an example: http://puu.sh/kJRsm/86562deefe.jpg
How do you combat this issue because on large screens the layout looks absolutely fine, it's just when the container starts to get narrow that the white space area get's larger?
I think I could combat the issue by making the col-7 div 100% height of the row and maybes take out the img tag and just add a css background with a cover size property on it however I'm wondering if there are any other ways?

I think the best way to do this is using flexbox https://philipwalton.github.io/solved-by-flexbox/demos/grids/ and check that Vertically Centered Grid Cells section.
Other way is, if you don't have to display all that text on sm or md size you can set hidden-sm or hidden-md on part of text and maybe create some read more link or something. For more info check out this http://getbootstrap.com/css/#responsive-utilities.
And maybe the third way is as you said to create div and inside put that picture and maybe use
.div {
overflow: hidden;
}
.div img {
height: 100%;
width: auto;
}
//OR
.div {
background-size: cover;
background-position: center;
}
Maybe there is some better way to do this and i would also like to learn about it but those are the options that i know and i had similar problem many times.

There are two ways to remove the white space.
One is to remove the divs we used to separate the text and image and float the image to right or left & give it a "width" and "max-width:100%" so on the large screens, It takes the image's width and the image will cover an area and the rest of space will be used by text. Don't remember to use the inside the to work like this.
Here is the example : http://www.w3schools.com/css/tryit.asp?filename=trycss_layout_float
the Second option is to test in all the screen sizes (lg-md-sm-xs) Forget sm&xs if you set the image to be 12 columns. You will have to reduce the image width to arrange the text with it on col-md.Regardsnabeel

Related

Containters not aligning properly in Bootstrap project

This is a continuation of a small project I started on over the weekend (I raised a query re H1 header size). I've got this as far as I want to take it at this stage (simple to-do list - non-functional at the moment). I added a navbar and designed an imported my own logo (in the menu bar and at the bottom of the screen). I've included the code from a codepen but for some reason (not sure at the moment) it hasn't pulled through the background colour and logo PNG hence why I've included a screenshot too.
However, the issue is that I cannot locate where I'm going wrong with regard to the containers not lining up: you can see the first two containers (with one row each - with the ADD rect which I'm going to change to a box and the 'You have '3' complete tasks:" rect box) then the five containers/rows below that are offset from those above.
The code for the "container-row-col" is (as far as I can tell) the same, but would placing all these rows in one container (containing all the 7 rows plus their columns) make a difference?
Maybe the media queries need to be looked at?
<div class="row">
<div class="col-8 col-md-6 white-rect mr-4 mb-2 ">|.............................................
</div>
<div class="col-6 col-md-4 white-rect center-block">ADD</div>
</div>
</div>
Here's a snippet of the container-row-col code with a codepen link below. I can only apologise for the amount of commenting out I've done...part of my learning process I guess.
Many thanks.
Codepen
Screen Shot of Full Page as it appears in my browser
You have too many nested containers. Just put all your .rows into one parent .container or add some style to the nested .containers witch will remove the extra padding. Something like this:
.container .container {
padding: 0;
}

How To Clear Bootstrap 4 Floats with Media Queries

I'm trying to set up 2 columns in Bootstrap 4 - one column will be an image and the other column a description. My image is portrait and so I need the image to float to the right in order to properly align with the description. This all works fine. However, I also need the columns to split into 2 rows on smaller devices. When this happens, my image is now still floated to the right and I would want it to be centered so it looks properly aligned.
How do I clear a Bootstrap 4 float when a certain breakpoint is hit?
Here is my HTML:
`
<div class="products">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 leftimage">
<img class="img-fluid deviceImage penguinPop float-right" src="img/penguinPop.png" alt="Penguin Pop">
</div>
<div class="col-lg-8 appinfo" style="margin-top:6em">
<h2>Penguin Pop</h2>
<p>Penguin Pop is a fun and challenging arcade game! Dapper Dan returns in another entertaining physics based game. Don't let Dan hit the ground or it's game over. Keep him safely in the air by tapping under him, but watch out! Those bubbles that are rising are dangerous! If they float all the way to the top of the screen you lose one of three lives. Tap them before they reach the top to get extra points! Earn stars by playing the game and spending them in the in-game store! The store includes several different penguins to play with. </p>
</div>
</div>
</div>
</div>
`
Assuming that you want to put them on top of each other
try this
First add a new class for example like i did mediaQuery
<img class="img-fluid deviceImage penguinPop float-right mediaQuery" src="img/penguinPop.png" alt="Penguin Pop">
I did the style and the css in a separate file because it's really annoying to put it inside the html
#media only screen and (max-width: 600px) {
.mediaQuery {
margin-right: 50%;
}
}
Try it in a css file because personally it didn't work with me as a css attribute.... and of course you know that you've to link the css file first

Trouble with responsive and absolute positioning

I'm currently building a page for case studies that includes a main banner image followed by 3 rows of 3 sub images. Each image is added through the background-image property so the divs can stay the same height. The divs have a hover container over top that I would like to always be on top, but when I get to my break point (850px and below) it is hard, without precise pixels, to keep the cover on top of the container. Is there an easier way to do this, than what I am doing?
Here is the basic HTML structure I am using
<div class="study-list">
<a href="#">
<div class="study-block left">
<div class="left-case-cover">
<div class="case-study-title">A Bridge For Kids Raises Scholarship Funds For Students Using Dxxx's Fundraising Software</div>
<div class="case-study-cta">Click here to read more</div>
</div>
<div class="study study1"></div>
</div>
</a>
<a href="#">
<div class="study-block center">
<div class="center-case-cover">
<div class="case-study-title">A Bridge For Kids Raises Scholarship Funds For Students Using Dxxx's Fundraising Software</div>
<div class="case-study-cta">Click here to read more</div>
</div>
<div class="study study2"></div>
</div>
</a>
<a href="#">
<div class="study-block right">
<div class="rightt-case-cover">
<div class="case-study-title">A Bridge For Kids Raises Scholarship Funds For Students Using Dxxx's Fundraising Software</div>
<div class="case-study-cta">Click here to read more</div>
</div>
<div class="study study3"></div>
</div>
</a>
I'm almost positive this isn't working due to the fact that the covers have to be absolutely positioned over the case-studys. Is there a better way to go about this, or can any of you help me make this work? It looks good for screen sizes 851px and higher, just need to figure out a way to get this working in mobile.
Here is a Fiddle of my current problem, it may help to expand it into fullscreen.
Thank you for the help!
Things I have tried:
• I have tried to make the container that holds the cover a certain width then overflow:hidden to hide the excess hover, but this hasn't worked.
• I've tried to do this with precise pixels but this has also failed me.
Try adding position: relative; to the parent of cover DOM. Also ensure the cover starts from top: 0, left: 0 and ends as bottom:0 and right:0.
You might have to do a clearfix for proper alignments for ensuring overlapping of successive DOMS don't happen. (for <850px resolution alone). Adding this for generic HTML might end up screwing your desktop resolution.

Bootstrap container-fluid not working for grids

The code is linked below with JSFiddle.
The problem was when I decrease the screen size the div blocks should be in the same line with decreased width instead they are going one below the other. (once check it by increasing the screen width).
The other one I want to highlight is that the code for showing
read more option for text/paragraph when we decrease the block size. That is when we click on read more the block size should increase and show the remaining text. It would be very helpful if someone suggests code for this.
The code is
.center{
float: none;
padding:0px;
margin-left: auto;
margin-right: auto;
}
div.allign{
height:170px;
margin:15px;
text-align:center;
}
div.content{
height:200px;
background-color:#fff;
background-color:#F4F1EE;
}
<div class="container-fluid">
<div class="row-fluid content">
<div class="col-md-1 "></div>
<div class="col-md-3 allign">
<h3>Get Started</h3>
<p>How it works?</p>
<p>It's very easy and simple,just sign up for free and get started with your account.
It's easy to reserve or cancel a book from anywhere.</p>
</div>
<div class="col-md-3 allign">
<h3>About library</h3>
<p>location,Directions,Books info...</p>
<p>Total books:1124<br />journals:130<br />.</p>
</div>
<div class="col-md-3 allign">
<h3>No text books?</h3>
<p>Dont worry here we go...</p>
<p>Reserve your books from online by just one click.
Read online/offline by downloading pdf files.</p>
</div>
</div>
</div>
Click here for a JSFiddle example
https://jsfiddle.net/nvpqfxbj/6/
Thanks in advance.
You are using the "md" grid size on those elements so they will become full width below 991px. If you want to maintain the columns on all devices, then use the "xs" columns.
Instead of 'col-md-3' and 'col-md-1' use 'col-xs-3' and 'col-xs-1'. However, you don't need the empty first column because BS address it with offsetting columns.
Also, the margins set from .allign will override the margins BS uses on the columns and you'll have problems unless you remove it. If you need the margins, use another container div nested inside the col-* containers.
BOOTPLY EXAMPLE: http://www.bootply.com/EfOZtUQqcs
This is the basic principle all responsive grid systems are built upon and you're going to struggle unless you understand this basic concept. It's all covered in the BS3 documentation.
http://getbootstrap.com/css/#grid
As for your "read more" problem. The code you provided is not the culprit. There is something going on server-side or JS that is causing this and you've provided no server-side or JS code.
This works for me.
Bootstrap 5
<div class=".container-fluid">

Bootstrap 3 grid, does it *really* matter how many columns are in a row?

I have a form layout that has bootstrap 3 form groups on it. I want these form groups in a single column on < small, 2 columns on tablet size break and 4 column on larger screens.
I have it apparently working perfectly, however after doing some reading here what I did seems to violate the supposed rule that every column in a row must add up to 12. However every tutorial and docs I could find always use weasel words like "should" or "ideally" when saying it should add up to 12. There doesn't seem to be a clear guidance here.
I defined my groups like this:
<div class="row">
<div class="form-group col-md-6 col-lg-3" ><!--....etc-->
and I currently have 4 of these in each row. This means that the 4 * col-lg-3 adds up to 12 but the 4 * col-md-6 form group divs adds up to 24 not 12.
However this doesn't seem to matter and it works perfectly at each breakpoint.
Should I be concerned? Does it matter in any way? Surely I'm not supposed to do two completely different layouts that duplicate all these controls once each for col-md-6 and col-lg-3 on the same page?
No, there's nothing to mandate that the bootstrap grid must add up to 12 columns.
It's just a preference / stylistic thing.
Less than 12 Columns -> Aligns Left:
If you have less than twelve of the columns filled, by default they will left align, leaving empty space to the right.
The following code:
<div class='row'>
<div class="col-xs-2">Hi</div>
<div class="col-xs-2">Hi</div>
</div>
.row > div {
background: lightgrey;
border: 1px solid grey;
}
Results in this: (Demo in Fiddle)
More than 12 Columns -> Wraps:
If the total adds to more than 12 columns, as long as the columns are within a row class, they will just wrap to additional rows. A good use case would be a photo grid system where you would like to add tons of photos but don't know how many rows you'll have and would still like to define the number of columns.
The following code:
<div class='row'>
<div class="col-xs-6">Hi</div>
<div class="col-xs-6">Hi</div>
<div class="col-xs-6">Hi</div>
<div class="col-xs-6">Hi</div>
</div>
Results in this: (Demo in Fiddle)
Other than that, sometimes it's the case that 12 column layouts look better, but you don't have to use them; it's not a sudoku :)
4 * col-md-6 will create 2 "rows" on a medium screen. Since you are wrapping everything in a .row it will function as expected. If you removed that then things will nest next to each other
e.g.
<div class="row">
<div class="col-sm-2">Hello</div>
</div>
<div class="row">
<div class="col-sm-2">Hello</div>
</div>
will produce 2 rows with 1 column each that are each 16.67% as wide as the parent row and floating left because a row has 100% width. Column widths are specified by col-**-(number/ 12) as a percentage (2/12 = 0.166667)
<div class="col-sm-2">Hello</div>
<div class="col-sm-2">Hello</div>
will produce 1 row with 2 columns that are each 16.667% as wide as the parent object. So you could forgo the .row if you did
<div class="col-sm-12 col-md-6 col-lg-3></div>
<div class="col-sm-12 col-md-6 col-lg-3></div>
<div class="col-sm-12 col-md-6 col-lg-3></div>
<div class="col-sm-12 col-md-6 col-lg-3></div>
This will create: Small Screen ( 4 rows full width columns) Medium Screen( 2 rows 2 columns each 50% width) Large Screen ( 1 row 4 columns each 25% width)
I've seen a lot of website use "col-xs-12 col-md-10 col-md-offset-1" lately. The offset centers the content, yet each row is filled with just 11 cols.
If the next element is a col-1 it must include col-offset-1 as well (Forcing a total of 13, moving the col-1 with offset-1 to the next row, aligning nicely). If the next element is wider, it still needs the offset (To skip the first column).
On the CSS side of it, it all works with percentages. If the total width of the columns is over 100% it has to force the next element on a new line.
U can easily play with this concept by making a html file with a whole lot of divs.
Add the following css to the divs (bootstrap basics)
body > div {
margin: 0;
padding: 0;
float: left;
width: 8.333333% (or 1/12th)
}
Then u can change the size of indivual divs to see what happens. It might be easier to play with round values (eg. 10%/20%), just sticked to bootstrap here.
Hope this gives you an understanding of how the browser handles the bootstrap grid (which you just made a basic version of)
The Bootstrap docs on columnwrapping also give a nice example.