Resizing two images at the same line on Bootstrap 3 - html

I'm trying to put two images at the same line with Bootstrap, using two different columns. I aligned them, used some background color two see the result, etc.
But, when I change the resolution to see the responsive effect, they not resize by equal! the images haven't the same width, but yes, the same height. Does anyone have a guess?
Here is the HTML:
.coresq {
background-color: #131313;
}
.cordir {
background-color: #AAAAAA;
}
.top-shows {
margin-left: 0;
margin-right: 0;
}
.top-shows [class^="col-"] {
padding-right: 0;
padding-left: 0;
}
<div class="container">
<div class="row top-shows">
<div class="col-xs-4 coresq ">
<img src="img/slogan_part_1.jpg" alt="imagem" class="slogan_l img-responsive"/>
</div>
<div class="col-xs-8 cordir">
<img src="img/slogan_part_2.jpg" alt="imagem" class="slogan_r img-responsive"/>
</div>
</div>
</div>
When the display reduces, the responsive properties don't resize equally. Shouldn't? Aren't they at the same line?

You have two different column sizes.
col-xs-4 and col-xs-8
you need to use same solumn size for both images if you want them to have same width.
col-xs-6 and col-xs-6 would be the sizes you are looking for.

One image is using double cols (xs-8) than the other (xs-4), so when resizing, the smaller column gets eaten.
Try resizing this external JSFIDDLE with equal cols
(Also, make sure the images are equal size as in the fiddle above)

After some research, I have looking about Flex, that can do it, and saw the new version of bootstrap (4, but still in alpha).
I've reading a lot about, and decided to test. It works! Exactly the way I asked before, with little changes on code.
Well, the custom css is the same, but the Bootstrap is 4 (alpha, for testing) and the HTML is here:
<div class="container">
<div class="d-flex flex-row">
<div class="col-xs-4 coresq ">
<img src="img/slogan_part_1.jpg" alt="imagem" class="slogan_l img-fluid"/>
</div>
<div class="col-xs-8 cordir">
<img src="img/slogan_part_2.jpg" alt="imagem" class="slogan_r img-fluid"/>
</div>
</div>
</div>
.
PS: I don't know why, but the code on snippet preview is cutting the last div ending the code. There is a single point on finish.

Related

Bootstrap 3.0: Full-Width Color Background, Compact Columns in Center

I was looking to make a striped business theme, similar to the one created by W3Schools. The theme can be found here. It is characterized by horizontal sections, separated by different background colors.
The one issue I had with it was that the columns in Services, Portfolio and Pricing, spanned pretty much the full width of the page, which I did not think looked great, particularly for the three pricing boxes, which i feel should be much narrower and still centered. Let's take those pricing boxes as the example for the purpose of the questions.
So, I embarked upon the task of squeezing these three pricing boxes into a narrower shape, centered on the page, while still maintaining the full-width alternating background color. I came up with three ways to do it:
1) Place a Container inside a Container-Fluid:
<div id="pricing" class="container-fluid">
<div class="container">
<div class="row">
<div class="col-sm-4 col-xs-12">
BlaBlaBla
</div>
...
</div>
</div>
</div>
2) Make the following additions/changes to the css and html:
.fixed-width {
display: inline-block;
float: none;
width: 300px;
}
.row-centered {
text-align: center;
}
-
<div id="pricing" class="container-fluid">
<div class="row row-centered">
<div class="col-sm-4 col-xs-12 fixed-width">
BlaBlaBla
</div>
...
</div>
</div>
3) 3x col-sm-2, with empty columns on each side
Keep the container-fluid layout, but instead of having three col-sm-4, I have an empty col-sm-3, three col-sm-2, and finally an empty col-sm-3 (for a total of 12 columns).
4) 3x col-sm-2, with offset-3 to center
Instead of having three col-sm-4, I have one col-sm-2 col-sm-offset-3, then two col-sm-2 (this does not add to 12, but i center with offset).**
The problem with both (3) and (4) is that once i shrink the browser window, the boxes become too small before they wrap to the next line (i.e. the text flows out of the box). In (4) it seems if i use container (as opposed to container-fluid), the boxes become too narrow in full-screen even.
What is the correct way of doing this? I assume this is an issue almost everyone making business websites stumbles across, yet I was not able to find the answer online having worked on it for hours.
Thanks in advance,
Magnus
Below follows what I think is the best way to solve this. I will divide it up in whether or not it is a background image or color we are looking to apply accross the full width.
CSS (formatting for illustration purposes and fixed width)
.content{
padding:20px;
border: 1px solid #269abc;
background:#d6ec94;
}
[class*="col-"] {
padding-top:10px; /* 15px side paddings automatically applied */
padding-bottom:10px;
border: 1px solid grey;
background: transparent;
}
.fixed-width {
display:inline-block;
float:none;
width: 300px;
}
The key here is the fixed-width class, and follows your approach (2). The other styles are just so you can try it and easily see how it works.
CSS (background image)
#one {
background-image: url([insert-url]);
background-repeat: no-repeat;
background-size: contain;
height:500px;
}
The key here is the background-size: contain element. As long as the width/height ratio of your background image is larger than the section's ratio, the image will fill the full background.
CSS (background color)
#two {
background-color: grey;
height:500px;
}
background-color works without any tweaks.
HTML
<section id="one">
<div class="container">
<div class="row text-center">
<div class="col-sm-4 fixed-width">
<div class="content">HERE</div>
</div>
<div class="col-sm-4 fixed-width">
<div class="content">HERE</div>
</div>
<div class="col-sm-4 fixed-width">
<div class="content">HER</div>
</div>
</div>
</div>
</section>
As seen, by adding a <section> around the container, you can apply the background image or color to the full width of the page.
IN Bootstrap,
Col-lg is large screen,
Col-sm is small screen,
Col-md is medium devices,
Col-xs is Small screen.
According to the browser ,we can use the all classes.In my experience we can use the col-lg-offset-3 for large screen,Remaining screen we should use without offset,like us,
UL list format:
<style>
ul{
margin:0;padding:0;
text-align:center;
}
ul li
{
display:inline-block;
text-align:center;
width:300px;
}
</style>
<ul>
<li>box1</li>
<li>box2</li>
<li>box3</li>
</ul>
whatever screen all list will come in center position of screen.
other format:
<div class="container">
<div class="row text-center">
<div class="col-lg-offset-3 col-lg-2 col-sm-4 col-md-4 col-xs-12">contenbox..</div>
<div class="col-lg-2 col-sm-4 col-md-4 col-xs-12">contenbox..</div>
<div class="col-lg-2 col-sm-4 col-md-4 col-xs-12">contenbox..</div>
</div>
</div>
we should use all classes to our business requirement.if we can alter-ate the various offset class for col-sm-offset-,col-md-offset.,
<div class="col-sm-4 col-xs-12">
Is the important line. The col-sm-4 is saying on small screens and above, take up 4 of 12 bootstrap columns. So, try decreasing this to 3 of 12 bootstrap columns, i.e. col-sm-3. Here it is within the example source code:
<div class="col-sm-3 col-xs-12">
<div class="panel panel-default text-center">
<div class="panel-heading">
<h1>Basic</h1>
</div>
<div class="panel-body">
<p><strong>20</strong> Lorem</p>
<p><strong>15</strong> Ipsum</p>
<p><strong>5</strong> Dolor</p>
<p><strong>2</strong> Sit</p>
<p><strong>Endless</strong> Amet</p>
</div>
<div class="panel-footer plan">
<h3>$19</h3>
<h4>per month</h4>
<button class="btn btn-lg">Sign Up</button>
</div>
</div>

Bootstrap - Columns will not stack vertically on xs

I must be missing something obvious here, but I am a beginner with Bootstrap and I have no idea what it could be. I'm trying to get this picture and the adjacent paragraph to stack vertically on xs screens. No matter what I do, they just line up alongside each other, pushing the picture to the edge of the screen. Here's a picture of what is happening, and my code.
<div class="row para-text vertical-align">
<div class="col-xs-12 col-md-8 col-md-push-4">
<p>text....</p>
</div>
<div class="clearfix visible-sm-block"></div>
<div class="col-xs-12 col-md-4 col-md-pull-8">
<img class="img-full" src="img/artesia1.jpg" alt="">
</div>
</div>
Here are the css styles I've added, in case those are causing problems
.para-text {
padding:15px;
}
.vertical-align {
display: flex;
align-items: center;
}
I would recommend not using your css classes that you posted. When I did a simple example with your html code but no css, it seems to work fine:
Please see: http://www.bootply.com/GCu0vDtk6K
Note: I also removed your:
<div class="clearfix visible-sm-block"></div>
Looks like my problem was using Flexbox. I've opted out of using it and am going to find a different way to vertical align the image so that I can have better browser support.

Bootstrap Column Reordering Sizing Problems

I'm trying to reorder the columns on my website via Bootstrap's method of reordering columns depending on the screen size which works fine for most of the responsive layouts I'm testing apart from 1.
The layout having problems is the Tablet Landscape Layout (1024 x 768) which displays like this:
Every other screen displays the blue div and the right div either with the red div on top if the screen is too small or on the right with the blue div aligning itself exactly next to it if the screen is large enough.
This is the code I'm using right now:
<div class="container">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<div class="row clearfix">
<div class="col-xs-12 col-sm-12 col-md-push-8 col-md-4 col-lg-push-8 col-lg-4 col-xl-push-8 col-xl-4" style="background: red">
Basket
</div>
<div class="col-xs-12 col-sm-12 col-md-pull-8 col-md-8 col-lg-pull-4 col-lg-8 col-xl-pull-8 col-xl-8" style="background: blue">
News
</div>
</div>
</div>
</div>
Does anyone know why the blue div is so far to the right on the Tablet Landscape layout rather than touching the red div like it should?
Some general markup issues:
First of all, there's no col-xl-*, so you can get rid of those.
Secondly, you don't need col-xs-12, since the default is for it take up the whole width unless otherwise specified.
Third, Bootstrap is mobile first, so larger sizes will override the existing smaller sizes, meaning if you don't intend on changing something, there's no need to specify the larger size again.
The actual issue is that col-*-pull-* is relative to where the element would be placed. Bear in mind, you haven't changed anything in the document flow. So the elements are positioned normally and then phase shifted with left or right. Since the blue container would normally start 4 columns over, you only need to pull it back by 4 columns, instead of 8.
The whole thing can be rewritten like this:
.red { background: red }
.blue { background: blue }
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<div class="container">
<div class="row ">
<div class="col-md-4 col-md-push-8 red"> Basket </div>
<div class="col-md-8 col-md-pull-4 blue"> News </div>
</div>
</div>

Bootstrap div respnsive table with multiple alignments at breakpoints

I'm having a bit of a hickup with bootstrap. Here's the deal:
I have a table made with divs with 4 fields, but I want them to have different alignments when they are being viewed on a mobile phone. Let me put the code of my table here to help explain:
<div class="table-responsive container text-center">
<div class="visible-md-block visible-lg-block row">
<div class="col-xs-4 col-md-3"><strong>From</strong></div>
<div class="col-xs-4 col-md-3"><strong>Points</strong></div>
<div class="col-xs-4 col-md-3"><strong>To</strong></div>
<div class="col-xs-12 col-md-3"><strong>Description</strong></div>
</div>
<div class="row">
<div class="col-xs-4 col-md-3">John doe</div>
<div class="col-xs-4 col-md-3">+20</div>
<div class="col-xs-4 col-md-3">Jane doe</div>
<div class="col-xs-12 col-md-3">Test Description</div>
</div>
</div>
There. If you are aware of bootstrap, you'll by now have realized the type of layout it will adopt. but I'll explain anyways:
When the viewport goes to a phone screen size I want the description column to go below the other ones.
Thing is, on that phone screen size I want to put the alignment diffrently from the centered one (that I defined on the table).
I want the "From" column aligned to the left, the "Points" column center aligned and the "To" column right aligned and the "Description" column to be center aligned while on larger viewports I want them to have a diffrent alignment. How would I pull such an effect off?
Also tips on weather I should use a table or keep using divs for this type of responsive coding are welcome :p
To accomplish the behavior you're after, you're likely going to need to come up with your own class, give it the majority of behaviors that col-xs-4 and col-md-3 have, and add your own home brewed styling to make the Description column fall below the other three for certain #media queries, etc.
media all and (max-width: 1000px) {
.custom-col-xs-4 {
float: left;
}
.costom-col-xs-4-lower {
clear: both;
}
}
Consider step 9 of this 10 step positioning tutorial when doing so: http://www.barelyfitz.com/screencast/html-training/css/positioning/

How can I center an column on bootstrap when it is an uneven number

I have the following scenario:
I have a <div class="row"> and then I have another <div class="col-lg-3"> where I will be putting the picture of a profile of an user. The problem is that I would like to center that picture to be in the middle of the available space, so I would normally do this:
<div class="row">
<div class="col-lg-3 col-lg-offset-x">
<img src="..." class="..." alt="..." title="..." data-size="...">
</div>
</div>
What would be the x value on the class of the <div class="col-lg-3 col-lg-offset-x"> If I wanted to center that div? Anybody has any idea how to do that?
Duplicate of Center a column using Twitter Bootstrap 3
"You can center any column size by using the proven margin: 0 auto; technique, you just need to take care of the floating that is added by Bootstrap's grid system. I recommend defining a custom CSS class like the following:
.col-centered{
float: none;
margin: 0 auto;
}
Now you can add it to any column size at any screen size and it will work seamlessly with Bootstrap's responsive layout :
<div class="row">
<div class="col-lg-1 col-centered"></div>
</div>
Note: With both techniques you could skip the .row element and have the column centered inside a .container but you would notice a minimal difference in the actual column size because of the padding in the container class."