I have this code:
<div class="col-sm-4">
<h4>{{$TagName->TagName}}</h4>
<img style="
width: 200px;
height: 200px;
";
class="img-responsive"; src="images/{{$TagName->TagName}}.jpg">
</div>
So my idea is to make(like this):
***text***
*imageeee*
Instead of:
text******
imageeee**
The * means the space that occupies, I dunno how to represent better the solution that I am seeking.
I used the text-align:center to div, and 2 display:block to the html elements but it doesn't work either.(I'm using also bootstrap if it counts)
Some ideas how to solve this?
The html
<div class="col-sm-4 text-center">
<h4>this is text</h4>
<img style="
width: 200px;
height: 200px;
";
class="img-responsive imageCentered"; src="https://upload.wikimedia.org/wikipedia/commons/1/1b/Square_200x200.png">
</div>
the css
.imageCentered{
margin:0 auto;
}
here is jsfiddle
here are two approaches to centering a column in Bootstrap 3:
Approach 1 (offsets):
The first approach uses Bootstrap's own offset classes so it requires no change in markup and no extra CSS. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2.
In markup this would look like:
<div class="row">
<div class="col-md-2 col-md-offset-5"></div>
</div>
Now, there's an obvious drawback for this method, it only works for even column sizes, so only .col-X-2, .col-X-4, col-X-6, col-X-8 and col-X-10 are supported.
Approach 2 (the old margin:auto)
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.
Since v3.0.1 Bootstrap has a built-in class named center-block that uses margin: 0 auto but is missing float:none. You can add that to your CSS to make it work with the grid system.
Related
I have created an html stuff with bootstrap 2.3.2 and not 3 The html is having one div with four child div's. The code is as given below
<div class="row-fluid column">
<div class="span3 testOne">Sample One
<br>Sample One
<br>Sample One
</div>
<div class="span3 testTwo">Sample Two
</div>
<div class="span3 testThree">Sample Three
<br>Sample Three
<br>Sample Three
</div>
<div class="span3 testFour">Sample Four
</div>
</div>
The code is working fine but I am facing two issues.
I am getting space in between the child div's
If one child div is big (containing more data) then the small div (containing less data) height is not proportional to the big one
what I expected to achieve is something like as shown below
Can anyone please tell me some solution for this
Note: I can't use flex since it wont work in IE8, also I need to use bootstrap 2.3.2 with proper responsive
JSFiddle
I would make a css tag such as .nomargin{margin-left:0px!important;} and add the class to the relevant divs testOne, testTwo, testThree, testFourand ensure the widths are set correctly
1) The first issue can be solved by downloading the development version of Bootstrap. This has LESS files. Here you can go to /less/variables.less. The variable #gridGutterWidth is set to '20px'. If you make this '0px', the width between the columns will disappear.
You have to compile the less files. You can find out how here: http://lesscss.org/
2) The second issue is harder to solve. It's probably best to use solution #1 (using negative margins) from here:
How can I make Bootstrap columns all the same height?
For css modify class as:
.column{
overflow: hidden;
}
.testTwo{
float: left;
margin-bottom: -99999px;
padding-bottom: 99999px;
}
.testThree{
float: left;
margin-bottom: -99999px;
padding-bottom: 99999px;
}
my html looks like this:
<div class="container">
<div class="header-content">
hello!
</div>
</div>
i've recently come into a situation where I need the 'header' to be 100% the window for a full-width background. usually i would do this css:
<div class="header-background-color">
<div class="container">
<div class="header-content">
hi!
</div>
</div>
</div>
unfortunately, i am fairly deep into a framework and can't wrap the container. i need to construct it within the container.
<div class="container">
<div class="header-background-color">
<div class="container">
<div class="header-content">
hi!
</div>
</div>
</div>
</div>
i can't figure out a way to accomplish this, and am wondering if this is possible.
if i use this css for header-background-color
background: blue;
left:0;
position: absolute;
width: 100%;
the element looks right, but the page flow is interrupted.
does anyone know if my target goal is reachable?
i made a bootply to illustrate this http://www.bootply.com/129060
You can use a child (>) selector to select the first container element and set its width to 100% and remove the padding.
.example-3 > .container {
width: 100%;
padding: 0;
}
This assumes you'll always have a wrapper around it with a unique class name (or use body if it's the first div), but this also allows you to remove the position: absolute which is causing the overlap and the height can stay dynamic.
See forked bootply: http://www.bootply.com/129065
I've added a button that inserts a paragraph into the div so you can see how it's not affected by changes in height.
Only thing I can think of is using a dumby element to maintain the vertical space (i.e. set the height), and then use absolute positioning on the full width content (as you mention). This is really ugly and won't be a good solution if the height of the content is dynamic.
See #content_dumby element in forked bootply: http://www.bootply.com/129063
I'm going to put 4 divs in a 100% width container side-by-side.
I saw this question and it was useful.
But my problem is that while using that solution, divs are stick to each other, but I need a little margin/space among them.
For example support a child div like this:
<div class="introwrapper"
style="width:25%;height:100%; float:left; margin-left:5px;">
</div>
Actually, I want to make these 4 divs placed side-by-side and make a space of 5 pixels between them, for the rest of the space remaining, make their width equal and the make the sum of widths of all these 4 divs and all 3 5px margins 100%.
How can I make this type of alignment?
I'm sorry for the confusion. I though a technique would work, that I have used frequently for centring objects, however it didn't.
Unfortunately, the only thing I can think of right now is an additional layer of containers/wrappers.
Essentialy:
Container width: 100%
Inner container: width: 25%;
Your object div padding-right: 5px; no width. It will be set automatically through the display: blockproperty, that a div has by default.
Here is the solution:
(Please note that sx.png is a 10x10 px transparent placeholder).
<div style="height: 160px; width: 100%; box-sizing:border-box; display:table;">
<div class="introwrapper" style="height:100%; width:25%;display:table-cell;">a</div>
<img src="../_imgs/sx.png" />
<div class="introwrapper" style="height:100%; width:25%;display:table-cell;">b</div>
<img src="../_imgs/sx.png" />
<div class="introwrapper" style="height:100%; width:25%;display:table-cell;">c</div>
<img src="../_imgs/sx.png" />
<div class="introwrapper" style="height:100%; width:25%;display:table-cell;">d</div>
</div>
<div class="internal-wrapper row-fluid">
<div class="Header span12">
<div class="HeaderTitle span6"></div>
<div class="span6"></div>
</div>
</div>
Now, when I do padding on internal-wrapper, I am expecting the padding to effect on the entire grid! inside it. But an overflow is occurring (I think, the right padding is not working)
.internal-wrapper {
padding-left: 30px;
padding-right: 30px;
}
The blue bar below represents Header class. The green box, represents padding! So, Its happening on left but not right
.row-fluid is 100% width. Because it's using a border-box layout, any padding you put is added to that 100%. See http://paulirish.com/2012/box-sizing-border-box-ftw/. However, setting it to use the content-box model will probably cause other problems in Bootstrap.
How to fix it - add an inner element with the padding.
<div class="row-fluid">
<div style="padding-left: 30px; padding-right: 30px;">
...
</div>
</div>
I can't see (or discern) from your post what's wrong, but here's my guess: By placing padding on an element that Bootstrap sizes, you've altered its width. Try putting margin on .Header instead.
If this doesn't help, please create a demo: http://jsfiddle.net/
I am trying to shift my style away from using tables to control formatting, but I haven't seen a simple css solution that does exactly the same thing as
<table><tr><td>aribitrary-html-A</td><td>aribitrary-html-B</td></tr><table>
All I want is to make sure aribitrary-html-A and aribitrary-html-B are aligned horizontally. I have tried various CSS concoctions using display: inline, clear: none, and float: left but they all have unwanted side-effects of moving my content around, while the table-tr solution just does what I want, regardless of what's in the arbitrary HTML, and regardless of what is in HTML that contains my table.
Am I missing something?
Why not use a grid system then like 960gs
You probably need this
<div id="wrap">
<div id="left">
content 1
</div>
<div id="right">
content 1
</div>
</div>
#wrap {
width: 50%; /* change this as you wish */
}
#left, #right {
display: block;
float: left;
}
You need to use <div>s and decent CSS. For people that aren't confident enough (or lazy, like me) Yahoos YUI CSS Grid Builder is invaluable! Enjoy!
Maybe this might help you?
<div style="width:400px;margin:0 auto;">
<div style="background-color:red;float:left;height:200px;width:200px;">
</div>
<div style="background-color:blue;float:right;height:200px;width:200px;">
</div>
</div>
Just don't put your css within style attributes like I did.
Just create two Divs and align the one you want to have on the left side.
Like so (update):
<div id="wrap" style=" width:300px;
margin:auto;
border: 1px solid black;
padding:1px">
<div id ="A" style="float:left;
border: 1px solid black;"> aribitrary-html-A </div>
<div id = "B" style="border: 1px solid black;"> aribitrary-html-A</div>
</div>
Update: I added a wrapper with a defined width. Also I used some borders to visualize the table-like layout. Hope that helps.
Wrap element in a div, set fixed width for the wrapper. Give each element in the div a width and set the margin to 0 auto.
Just set the CSS "float" property to left on every element you want to display horizontally, and make sure each of those elements have a set width.