How to set padding Bootstrap when left element has float propery? - html

I have the following HTML code:
<div class="col-md-3 block">
<div class="col-md-4 photo">
<a target="_blank" href="https://www.facebook.com/app_scoped_user_id/1282701351808739/"><img src=""></a></div>
<div class="col-md-8"><h4><span style="font-weight: bold;">Gracie Huff</span></h4><p class="review-comment" style="line-height: 1.6;"><span>Oh my goodness! Your work is so precious and beautiful!!! I love what you do and I hope you continue to keep up the fabulous work!!! ❤❤</span></p>
Problem is that block col-md-4 has property float:left.
If text in block .col-md-8 is so long it comes to under block col-md-4 photo.
Sample here
So, how to fix this?
As solution I can set fixed height for element: div.photo

When using bootstrap col's you have space for a total of 12 inside a row.
Please take a look at the grid documentation. http://getbootstrap.com/css/#grid
So in your example 3 + 4 + 8 = 15 . So that's 3 too many. In my code example below i divided the page into 3 even columns. So you do 12/3 = 4 so you give each class col-md-4 . If you don't want even columns you can play with the numbers at the end. But never go above 12 or they will not fit into a single row.
Also the basic structure involves a container and a row.
If you want the container to be full-width you can add container-fluid instead of container to your top-level div.
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<a target="_blank" href="https://www.facebook.com/app_scoped_user_id/739844199505120/"><img src="https://fb-s-b-a.akamaihd.net/h-ak-xpf1/v/t1.0-1/p50x50/14724409_686756244813916_4119560930105375585_n.jpg?oh=0d295e97d3818a2ba788015d38385376&oe=590D81DC&__gda__=1494163569_54508491e4fd3d1197960c466dfee235"></a>
</div>
<div class="col-md-4">
<h4 class="strong"><strong>Anastasia Michelle Archuleta</strong></h4>
</div>
<div class="col-md-4">
<p class="review-comment" style="line-height: 1.6;">
<span>I can't stop looking at these cute creatures! I'm so in love with all of them! I'm saving up for one, what one is going to be a very hard decision that's for sure!</span>
</p>
</div>
</div>
</div>

Related

CSS div containers width

So check out the "About Us" and "Contact Us" pages here.
I'm having some difficulty in getting my DIV containers to align properly. I've never used DIV containers - last time I made a website it was based on tables and used Golive!
Anyway, the question should be fairly obvious - I want a 250x250 image on the left with the words to the right of the image and wrapping down below it (x3). The whole lot should be centred in the middle of the page with a max width of 1170 px. I just can't work out where it's gone wrong.
Likewise on the Contact Us page my 3 DIV containers are aligned vertically rather than across the screen taking up 33% each. All looks great in Dreamweaver live view but doesn't work in Chrome once uploaded.
I bet it's something simple but I really have no clue! I'll be super grateful if someone can point me in the right direction.
The problem is here in the below line of HTML
the div corresponding to Aviation & Automotive
<div class="col-xs-6 col-sm-6 col-md-3 templatemo_col12 templatemo_margintop10">
Replace that entire div using this
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-3 templatemo_col12 templatemo_margintop10">
<div class="item project-post">
<div class="templatemo_about_box">
<div class="square_coner">
<span class="texts-a"><i class="fa fa-paper-plane"></i></span>
</div>
Aviation & Automotive
</div>
<div class="col-xs-6 col-sm-6 col-md-3 hover-box">
<div class="inner-hover-box">
<p>Repairs, maintenance and add-ons. We specialise in one-off projects.</p>
</div>
</div>
</div>
</div>
</div>

How to put Bootstrap 3 Wells on the same row?

Here is my Bootstrap 3 jsFiddle, although you'll likely need to view it in full screen view in order to see it in all its glory.
As you can see, there are two TB3 "wells" called Herps and Derps. They are currently sitting on top of one another, and furthermore, they are wider than the navbar, jumbotron and footer wells.
I'd like these to both be next to each other on the same line/"row", and I'd like the two wells to be the same width of all the other contents. I'd also like to have a bit of padding (spacing) between the two wells so that they're not smushed right up next to each other.
My best attempt (from that jsFiddle above):
<div class="row">
<div class="span6">
<div class="well">Herps</div>
</div>
<div class="span6">
<div class="well">Derps</div>
</div>
</div>
...does not seem to be doing the trick. Any ideas where I'm going awry?
You need to use the col-x-y css styles for your wells for the appropriate screen size and columns. In this case, you could use col-sm-6 since you have two columns.
<div class="row">
<div class="col-sm-6">
<div class="well">Herps</div>
</div>
<div class="col-sm-6">
<div class="well">Derps</div>
</div>
</div>
JSFiddle
Bootstrap Grid System

Bootstrap grid positioning

so I'm trying to make a bootstrap website but I don't really know how to customize the widths and position of these grids. I'm a bootstrap beginner. Could you please help me? It DOESN'T have to be accurate so bad but I need to keep the layout.
How it should look like:
http://i.imgur.com/WAE161o.png
HTML:
<div style="margin-top:200px;" class="container">
<div class="row clearfix">
<div class="col-md-4 column">
</div>
<!--THIS ONE IS FOR THE MIDDLE, CENTERED AD-->
<div class="col-md-4 column">
</div>
<div class="col-md-4 column">
</div>
</div>
<div class="row clearfix">
<div class="col-md-2 column">
</div>
<!--THIS ONE IS FOR BUTTONS STICKED TO THE POST ON THE LEFT-->
<div class="col-md-1 column">
</div>
<!--THIS ONE IS FOR THE POST AND BUTTONS STICKED ON THE BOTTOM-->
<div class="col-md-4 column">
</div>
<!--THIS ONE IS FOR THE SIDEBAR-->
<div class="col-md-3 column">
</div>
<div class="col-md-2 column">
</div>
</div>
</div>
From Bootstrap 3.0 release
col-vp-push-x = push the column to the right by x number of columns, starting from where the column would normally render -> position: relative, on a vp or larger view-port.
col-vp-pull-x = pull the column to the left by x number of columns, starting from where the column would normally render -> position: relative, on a vp or larger view-port.
vp = xs, sm, md, or lg
x = 1 thru 12
So the answer to your question is push/pull columns. For example, your ad row should be like this:
<div class="row">
<div class="col-sm-8 col-sm-pull-2 col-sm-push-2 advertisement">
your center column
</div>
</div>
and so on. See fiddle here
If you need specific columns with pixel-specific widths, you can't use the Bootstrap grid. The Bootstrap grid is broken into 12 equal sized columns. You can still use Bootstrap, just not the grid part. There is some limited customization that can be done with the grid system, but I don't think it can approach what you are trying to do. You'll need to use custom CSS to position the site how you want it.
If you just want something similar and don't care about exact widths, then you should follow the grid documentation. You are moving in the right direction but when you have nested columns you need to make sure you wrap in a row, which you don't have. You can also use the col-md-offset-* styles to shift columns so you don't have to "use" all 12 columns. For example for the main part of the site you might want the first column to be ".col-md-3 .col-md-offset-4" and the second ".col-md-3".

Bootstrap 3 Grid System

I am migrating a project of mine from bootstrap 2 to bootstrap 3. Now, I am having some problem with the grid layout that I can't understand. I have a col-md-12 and I wanna add 3 columns of equal width in this larger div. Logically, the 3 columns should each be col-md-4. However, when I add the 3 columns (divs) of class col-md-4, they don't fit and one of them gets pushed down and some space is left at the end after the 2nd one.
Please someone help me understand something that I may be missing. Thank you.
It sounds like the issue is padding. Bootstrap automatically adds padding when you have nested col-xx-# classes. If you have col-md-4 as a direct child of a col-md-12 bootstrap will add padding and your third col-md-4 will end up on a new line.
What you're doing:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="col-md-4">
1/3
</div>
<div class="col-md-4">
2/3
</div>
<div class="col-md-4">
3/3
</div>
</div>
</div>
</div>
To address this, either add a new class="row" above your first col-md-4 or simply remove the col-md-12 like this:
<div class="container">
<div class="row">
<div class="col-md-4">
1/3
</div>
<div class="col-md-4">
2/3
</div>
<div class="col-md-4">
3/3
</div>
</div>
</div>
Bootstrap's column layout can only be 12 "units" in width.
To archieve columns of equal width, you should split 12 equally (sum of * in col-md-* should be 12).

Bootstrap: adding gaps between divs

If my page uses the Bootstrap class row, col-md-x and such to arrange the content, what would be the proper way to create a distance between each div containing a whole element semantically speaking?
I am adding a div with a padding between the divs to simulate the gap, is this a good tactic or is there a better one?
Starting from Bootstrap v4 you can simply add the following to your div class attribute: mt-2 (margin top 2)
<div class="mt-2 col-md-12">
This will have a two-point top margin!
</div>
More examples are given in the docs: Bootstrap v4 docs
Adding a padding between the divs to simulate a gap might be a hack, but why not use something Bootstrap provides. It's called offsets. But again, you can define a class in your custom.css (you shouldn't edit the core stylesheet anyway) file and add something like .gap. However, .col-md-offset-* does the job most of the times for me, allowing me to precisely leave a gap between the divs.
As for vertical spacing, unfortunately, there isn't anything set built-in like that in Bootstrap 3, so you will have to invent your own custom class to do that. I'd usually do something like .top-buffer { margin-top:20px; }. This does the trick, and obviously, it doesn't have to be 20px, it can be anything you like.
I required only one instance of the vertical padding, so I inserted this line in the appropriate place to avoid adding more to the css. <div style="margin-top:5px"></div>
The easiest way to do it is to add mb-5 to your classes. That is <div class='row mb-5'>.
NOTE:
mb varies betweeen 1 to 5
The Div MUST have the row class
An alternative way to accomplish what you are asking, without having problems on the mobile version of your website, (Remember that the margin attribute will brake your responsive layout on mobile version thus you have to add on your element a supplementary attribute like #media (min-width:768px){ 'your-class'{margin:0}} to override the previous margin)
is to nest your class in your preferred div and then add on your class
the margin option you want
like the following example:
HTML
<div class="container">
<div class="col-md-3 col-xs-12">
<div class="events">
<img src="..." class="img-responsive" alt="...."/>
<div class="figcaption">
<h2>Event Title</h2>
<p>Event Description.</p>
</div>
</div>
</div>
<div class="col-md-3 col-xs-12">
<div class="events">
<img src="..." class="img-responsive" alt="...."/>
<div class="figcaption">
<h2>Event Title</h2>
<p>Event Description. </p>
</div>
</div>
</div>
<div class="col-md-3 col-xs-12">
<div class="events">
<img src="..." class="img-responsive" alt="...."/>
<div class="figcaption">
<h2>Event Title</h2>
<p>Event Description. </p>
</div>
</div>
</div>
</div>
And on your CSS you just add the margin option on your class which in this example is "events" like:
.events{
margin: 20px 10px;
}
By this method you will have all the wanted space between your divs making sure you do not brake anything on your website's mobile and tablet versions.