Trouble resizing bootstrap 3 box to fit with image - html

Please see the first image below.
This is working great and is how I want it to look. However when the browser resizes it then looks like this.
As you can see the white background of the text block is bigger than of the image block. I want the image block to be the same height as the text block but unfortunately this is not working. I am using Bootstrap 3 to develop this and you can see my code for this below:
<div class="row" style="margin-bottom:30px;">
<div class="col-xs-12">
<div class="col-sm-3" style="padding:0;">
<img src="core/img/abb[square].jpg" class="img-responsive">
</div>
<div class="col-sm-9" style="background:#fff; height:218px; padding:7px 25px;">
<h2><a class="a-cl">Page title</a> <small>2.1 miles away</small></h2>
<p>Text content, summary of page here.</p>
Subscribed <i class="glyphicon glyphicon-ok" style="margin-left:4px;"></i>
</div>
</div>
</div>
Any help would be much appreciated. As you can see I have manually defined the height on <div class="col-sm-9"> and set height:218px. This obviously will not work dynamically as the page resizes.
Summary: I am looking for an effective way of making sure the height of the text block is the same as the image block using bootstrap 3.

Okay, this is with intrinsic ratios, it's not like the comments I made. However, the comment about the rows and columns and nesting are correct.
DEMO: http://jsbin.com/zodama/1/
http://jsbin.com/zodama/1/edit
Requires: jquery.matchHeight-min.js
https://github.com/liabru/jquery-match-height
jQuery (when the script is installed):
$(document).ready(function() {
$('.my-row [class*="col-"]').matchHeight();
});
The CSS, some of which is the aspect ratio and some of which is Bootstrap grid manipulation based on intimate knowledge of how it works.
.my-row {
border: 10px solid #ddd;
margin-left: 0;
margin-right: 0;
margin-bottom: 3%;
text-align: center;
}
.image img {
display: block;
max-width: 100%;
height: auto;
margin: 0 auto;
}
.my-row [class*="col-"] {
padding:0 0 10px 0;
}
#media (min-width:768px) {
.my-row {
border: 10px solid #ddd; /* remove this it's in the global */
text-align: left;
}
.my-row [class*="col-"] {
padding: 0;
min-height: 220px;
}
.my-row [class*="col-"]:last-child {
padding-left: 20px;
padding-bottom: 20px;
}
.image img {
display: block;
width: 100%;
height: 100%;
margin: auto;
-webkit-transition: all 2s ease-out;
transition: all 2s ease-out;
}
.image img {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.image {
position: relative;
height: 0;
padding-top: 56.25%;
}
}
#media (min-width:992px) {
.my-row [class*="col-"] {
min-height: 250px;
}
}
#media (min-width:1200px) {
.my-row [class*="col-"] {
min-height: 275px;
}
}
HTML
<div class="container">
<div class="row my-row">
<div class="col-sm-4 col-md-3 image">
<img src="http://lorempixel.com/320/320/sports"/>
</div>
<div class="col-sm-8 col-md-9">
<h2><a class="a-cl">Page title</a> <small>2.1 miles away</small></h2>
<p>Text content, summary of page here.</p>
Subscribed <i class="glyphicon glyphicon-ok"></i>
</div>
</div>
<div class="row my-row">
<div class="col-sm-4 col-md-3 image">
<img src="http://lorempixel.com/320/320/city"/>
</div>
<div class="col-sm-8 col-md-9">
<h2><a class="a-cl">Page title</a> <small>2.1 miles away</small></h2>
<p>Text content, summary of page here.</p>
<p>Text content, summary of page here.</p>
<p>Text content, summary of page here.</p>
<p>Text content, summary of page here.</p>
<p>Text content, summary of page here.</p>
Subscribed <i class="glyphicon glyphicon-ok"></i>
</div>
</div>

Related

CSS - aplying border-radius to a gif

I am trying to style the gif by giving it border-radius. However ther gif is smaller than the column itself so border-radius is aplied only to the right side of the gif. Could anyone help me out in applying it to the left side aswell? I dont want to change the background-size: contain!important; because then I will loose the proportions of the gif.
PS. Snippet breakes the row and the gif is in another row but it doesn't matter in this example.
.half-half-image-text {
padding: 70px 0px;
}
.half-half-image-text h1 {
color: #800000;
}
.half-half-image-text .content {
height: 100%;
display: flex;
align-items: center;
padding: 35px 0px;
}
.half-half-image-text .content p {
font-size: 22px;
}
.half-half-image-text .img {
min-height: 320px;
height: 100%;
border-radius: 10px;
}
<!-- begin snippet: js hide: false console: true babel: false -->
<div class="half-half-image-text">
<div class="container" >
<div class="row">
<div class="col-7 col-lg-7" style="padding-right:0">
<div class="content">
<p>At Fluid Automotive, our purpose is to make automotive parts easily accessible for everyone. Working with our partner brands, we aim to retail the highest quality parts, whilst maintaining a high level of customer satisfaction.</p>
</div>
</div>
<div class="col-5 col-lg-5" style="padding-right:0">
<a href="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif" data-gallery="portfolioGallery" class="portfolio-lightbox">
<div class="img customzoom s2" style="background-size: contain!important;box-shadow: none;
background: url('https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif')no-repeat center right;background-size:cover;" alt="Plan rozwoju" title="Plan rozwoju"></div>
</a>
</div>
</div>
</div>
</div>
You could add this style to portfolio-lightbox :
width: 240px;
display: block;
and change min-height:320px; to min-height:240px will solve your problem. Like below :
half-half-image-text {
padding: 70px 0px;
}
.half-half-image-text h1 {
color: #800000;
}
.half-half-image-text .content {
height: 100%;
display: flex;
align-items: center;
padding: 35px 0px;
}
.half-half-image-text .content p {
font-size: 22px;
}
.half-half-image-text .img {
min-height: 240px;
height: 100%;
border-radius: 10px;
}
.portfolio-lightbox {
width: 240px;
display: block;
}
<div class="half-half-image-text">
<div class="container" >
<div class="row">
<div class="col-7 col-lg-7" style="padding-right:0">
<div class="content">
<p>At Fluid Automotive, our purpose is to make automotive parts easily accessible for everyone. Working with our partner brands, we aim to retail the highest quality parts, whilst maintaining a high level of customer satisfaction.</p>
</div>
</div>
<div class="col-5 col-lg-5" style="padding-right:0">
<a href="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif" data-gallery="portfolioGallery" class="portfolio-lightbox">
<div class="img customzoom s2" style="background-size: contain!important;box-shadow: none;
background: url('https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif')no-repeat center right;background-size:cover;" alt="Plan rozwoju" title="Plan rozwoju"></div>
</a>
</div>
</div>
</div>
</div>
Simply use an image tag.
.imgradius {
border-radius: 10px
}
<img class="imgradius" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif"></img>

I have 2 columns with <div> and the widths keep edging each other out

What ends up happening is that the two columns cannot cohabitate next to each other without shrinking the width by about 2%. Doing that causes the edges to not align with the header and it just looks off. Is there something I am missing about 'width' or 'padding'?
This is what I am trying to emulate: https://www.w3schools.com/howto/howto_css_blog_layout.asp
This is what ends up happening (before changing the width by -2%):
What happens when I have to change the width:
body {
padding: 20px;
background: #f1f1f1;
}
.header {
padding: 30px;
font-size: 40px;
text-align: center;
background: white;
}
.leftcolumn {
float: left;
width: 75%;
}
.rightcolumn {
float: left;
width: 25%;
padding-left: 20px;
}
.card {
background-color: white;
padding: 20px;
margin-top: 20px;
}
.row:after {
content: "";
display: table;
clear: both;
}
.footer {
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
}
#media(max-width: 800px) {
.leftcolumn,
.rightcolumn {
width: 100%;
padding: 0;
}
}
<div class="header">
<h2>Harry's Den</h2>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>I love the World</h2>
<h5>Helloo!</h5>
<p>Text!</p>
</div>
<div class="card">
<h2>Wow this works so far!</h2>
<h5>I am just happy to have a semi-functional blog!</h5>
<p>Yay! I do not have much to say other than I am happy to have made it this far. Hopefully this will help!</p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Me!</h2>
<p>University: Texas Tech University</p>
<p>Major: Computer Engineering (BS)</p>
<p>Minor: Mathematics</p>
<p>Interests: Energy Infrastructure and Space Exploration Efforts</p>
</div>
<div class="card">
<h3>Popular Post</h3>
</div>
<div class="card">
<h3>Follow Me!</h3>
Twitter
<br/>
Facebook
</div>
</div>
</div>
<div class="footer">
<h2>Developed by Barry Allen</h2>
<h2>Quantum Enterprise Projects</h2>
</div>
Here is the information from the MDN Web Doc.
By default in the CSS box model, the width and height you assign to an
element is applied only to the element's content box. If the element
has any border or padding, this is then added to the width and height
to arrive at the size of the box that's rendered on the screen. This
means that when you set width and height you have to adjust the value
you give to allow for any border or padding that may be added.
The box-sizing property can be used to adjust this behavior:
content-box gives you the default CSS box-sizing behavior. If you set an element's width to 100 pixels, then the element's content
box will be 100 pixels wide, and the width of any border or padding
will be added to the final rendered width.
border-box tells the browser to account for any border and padding in the values you specify for width and height. If you
set an element's width to 100 pixels, that 100 pixels will
include any border or padding you added, and the content box
will shrink to absorb that extra width. This typically makes it
much easier to size elements.
You have to use box-sizing:border-box to include border, padding and margin everything included in the width of your element.
Read more information in MDN Web Docs
* {
box-sizing:border-box;
}
* {
box-sizing:border-box;
}
body{
padding: 20px;
background: #f1f1f1;
}
.header{
padding: 30px;
font-size: 40px;
text-align: center;
background: white;
}
.leftcolumn{
float: left;
width: 75%;
}
.rightcolumn{
float: left;
width: 25%;
padding-left: 20px;
}
.card{
background-color: white;
padding: 20px;
margin-top: 20px;
}
.row:after{
content: "";
display: table;
clear: both;
}
.footer{
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
}
#media(max-width: 800px){
.leftcolumn, .rightcolumn{
width: 100%;
padding: 0;
}
}
<div class="header">
<h2>Harry's Den</h2>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>I love the World</h2>
<h5>Helloo!</h5>
<p>Text!</p>
</div>
<div class="card">
<h2>Wow this works so far!</h2>
<h5>I am just happy to have a semi-functional blog!</h5>
<p>Yay! I do not have much to say other than I am happy to have made it this far. Hopefully this will help!</p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Me!</h2>
<p>University: Texas Tech University</p>
<p>Major: Computer Engineering (BS)</p>
<p>Minor: Mathematics</p>
<p>Interests: Energy Infrastructure and Space Exploration Efforts</p>
</div>
<div class="card">
<h3>Popular Post</h3>
</div>
<div class="card">
<h3>Follow Me!</h3>
Twitter
<br/>
Facebook
</div>
</div>
</div>
<div class="footer">
<h2>Developed by Barry Allen</h2>
<h2>Quantum Enterprise Projects</h2>
</div>
Here is the Fiddle Link. You can expand and shrunk the size of the screen and check it out how it is reacting.
Padding and border are counted in the width. So you have to subtract them.
In your case you can do
.rightcolumn {
width: calc(25% - 20px);
}

Why is my bootstrap overlapping?

Hello I am just making a base template to help me make a website a lot better, I have just recently started using bootstrap and have noticed that when I resize my browser (for example to a mobile size) it is overlapping on my footer?
Does anyone know why this is happening?
Here are some images of when I add more text or resize:
Like I say I am fairly new to bootstrap and am most likely doing something really stupid which is easy to fix :)
Here is my css:
html, body { height:100% }
nav {
margin: 0;
padding: 0;
}
div {
display: block;
}
.col-centered {
float: none;
margin: 0 auto;
}
.center {
margin-left:auto;
margin-right:auto;
margin: 0 auto;
}
.left {
float: left;
}
.right {
float: right;
}
.container {
width: 100%;
margin: 0;
padding: 0;
height:100%;
background:red;
}
.content {
padding: 5rem 1.5rem;
text-align: left;
height:90%;
width:75%;
margin:0 auto;
background: green;
}
footer {
background: grey;
height:10%;
width:75%;
margin:0 auto;
}
Here is my main HTML:
<div class="container">
<div class="content">
<div class="row">
<div class="col-md-auto col-centered">
<h1>Base Template Title</h1>
<p>Text would go here...</p>
</div>
</div>
</div>
<?php include "footer.php" ?>
EDIT: I forgot to include the footer, if you think that I need to add this for you then please let me know.
Thank you very much for even looking at this post!
EDIT 2:
Here is the code for my footer:
<footer>
<div class="row">
<div class="col-md-auto">
<p class="float-right">Back to top</p>
<p>© 2017 Company, Inc. · Privacy · Terms</p>
</div>
</div>
</footer>
Here is the link to the website:
http://81.131.193.35/
Remove the height of .content
.content {
padding: 5rem 1.5rem;
text-align: left;
width: 75%;
margin: 0 auto;
background: green;
}
and also remove the height of .container
.container {
width: 100%;
margin: 0;
padding: 0;
background: red;
}
I would wrap the footer.php in a pair of divs and apply a row and col-md-auto class to it. It looks like the footer is maybe styled with an absolute or even a static display. This is making the footer not play along with the other divs
<div class="container">
<div class="content">
<div class="row">
<div class="col-md-auto col-centered">
<h1>Base Template Title</h1>
<p>Text would go here...</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-auto">
<?php include "footer.php" ?>
</div>
</div>
</div>

Twitter Boostrap 3 different sized Images not re-sizing correct and overlapping another column

I am trying my first Responsive design and have implemented Twitter Boostrap 3. I have got a side where I want to show an article with images and information.
I have created a Panel and inside the Panel I have on the left side a Main Image and Thumbnails below it with a Mouse Over Effect to replace the Main Image and on the right side an information box. Below 768 the two boxes will move below each other. Images can be uploaded, which means they can have different sizes.
I want a fixed height for the Main Image Box (#main-image-container), otherwise I would have a constant jumping, when I use the Mouse Over effect. Of course I also want to keep the ratio of width to height. And the maximum width of the Main Image Box should be the max column width of the left columns and not overlap the Info Box on the right and the Thumbnail Box (#thumb-container) max-width should be the same as the #main-image-container.
It looks like that I have pretty much managed to get it working for <1200 and up around 530 on a landscape image. Above 1199, my picture width overlaps the Info Box and below the 530, the image width is not getting smaller anymore. I am trying to fix this now for a week, but can not find the solution. What do I do wrong here? I hope everybody understands my question and that my Sourcecode below helps.
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">title</h3>
</div>
<div class="panel-body">
<!-- Left Column of Advert -->
<div class="col-md-7 col-sm-7 item_gallery" id="gallery">
<div id="main-image-container" class="text-center">
<div class="main-img-box">
<img src="/uploads/tmp/mainimage.jpg" class="img-responsive" id="main-img" width="400">
</div>
</div>
<div id="thumb-container">
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage1.jpg" class="thumbnails">
</div>
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage2.jpg" class="thumbnails">
</div>
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage3.jpg" class="thumbnails">
</div>
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage4.jpg" class="thumbnails">
</div>
</div>
</div>
<!-- Right Column -->
<div class="col-md-5 col-sm-5">
Here is a Bookmark Link
<div class="panel panel-info">
<div class="panel-heading"><strong><span style="font-size:16px;"">
Some Information
</div>
<div class="panel-body">
<ul class="list-group">
<li>lots of infos</li>
<li>more infos</li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>Description</h4>
</div>
</div>
</div>
</div>
CSS
#main-image-container{
border: 1px solid #ccc;
width: 90%;
max-width: 90%;
height: 452px;
margin-bottom: 35px;
margin-top: 40px;
display: table;
}
.main-img-box{
display: table-cell;
vertical-align: middle;
float: none;
width: 90%;
max-width: 90%;
height: 452px;
}
// below is new
#main-img{
max-height: 450px;
}
#thumb-container{
max-width: 100%;
border: 1px solid #ccc;
margin-bottom: 30px;
display: table;
}
.thumb-img-box{
display: table-cell;
vertical-align: middle;
float: none;
padding: 0 10px 0 10px;
}
#media (max-width: 1199px) {
#main-image-container{
width: 100%;
height: 452px;
}
.main-img-box{
max-width: 100%;
height: 452px;
}
#main-img{
max-height: 452px;
max-width: 100%;
}
#thumb-container{
height:100px;
}
.thumbnails {
margin:0;
padding:0;
}
img {
width: 100%;
}
}
#media (max-width: 767px) {
#main-image-container{
width: 100%;
height: 352px;
}
.main-img-box{
width: auto;
max-width: 100%;
height: 352px;
}
#main-img{
max-height: 352px;
width: auto;
max-width: 100%;
}
#thumb-container{
max-height:100px;
width: 100%;
}
img{
width: 100%;
}
Hi in bootstrap you need to give display as inline-block then only images will be responsive.
img
{
display:inline-block;
width:100%;
}

Elements go outside their parent container

I have an issue that I'm running into. I'm using the grid.css file. The classes that are not mentioned are empty.
So the problem is that when there are 3 columns with images that (in pixels) are realy big in the MAIN ARTICLE AREA. They go over the size of the container. And into the SIDEBAR area. How could I fix this issue?
I hope I'm clear enough, if not let me know, I fill fix it. :)
EDIT I figured out the issue. I had to add this to the css and now the images don't go over their size.
.related articles img{
width: 100%;
}
With this it works fine.
<section class="article">
<div class="row">
<!--MAIN ARTICLE AREA-->
<div class="col span-2-of-3 col-left">
<div class="related-articles">
<div class="col span-1-of-3">
<a href="#">
<img src="img/test_img.jpg" alt="test-img">
<h3>This is a test article, I'm just trying out new things and lets see how this goes.</h3>
</a>
</div>
<div class="col span-1-of-3">
<a href="#">
<img src="img/test_img.jpg" alt="test-img">
<h3>This is a test article, I'm just trying out new things and lets see how this goes.</h3>
</a>
</div>
<div class="col span-1-of-3">
<a href="#">
<img src="img/test_img.jpg" alt="test-img">
<h3>This is a test article, I'm just trying out new things and lets see how this goes.</h3>
</a>
</div>
</div>
</div>
<!--SIDEBAR STARTS-->
<div class="col span-1-of-3 col-right">
</div>
</div>
</section>
And the CSS
.row{
max-width: 1140px;
margin: 0 auto;
}
.article .col {
display: block;
float:left;
margin: 0.5% 0 0.5% 0;
}
.span-2-of-3 {
width: 66.13%;
}
.span-1-of-3 {
width: 32.26%;
}
.col-left{
border-top: 2px solid #f5f5f5;
float: left;
}
.col-right{
float: right;
/*THE HEIGHT AND COLOR IS JUST SO I KNOW HOW IT WILL LOOK*/
height:800px;
color:aqua;
}
JSfiddle:
https://jsfiddle.net/ua7o3pf9/
Corrected Code:
.col {
display: block;
float:left;
margin: 1% 0 1% 1%;
}
.span-2-of-3 {
width: 64.6%;
}
.span-1-of-3 {
width: 31.6%;
}
You calculated your widths and margins false. Fixed it for you. It must be 100% or below in total.
Edit:
Also fixed sidebar color for you: https://jsfiddle.net/ua7o3pf9/1/
Edit 2: Fixed Code for your edited question:
Fiddle:
https://jsfiddle.net/ua7o3pf9/9/
Code:
<div class="related-articles article">
You forgot to add the class article, this is why the float:left wasnt added to your cols.
Change your .col style to:
.col {
display: block;
float:left;
margin: 1% 0 1% 1%;
}