laying out divs horizontally with content within it - html

I am trying to layout my div holding three divs within it. The application uses Bootstrap. They don't seem to be laying out properly with all text or buttons in the center. I am using a separator between the second and third boxes. The application also uses another class content-header which is from the proui library used elsewhere in the application and borrowed here for maintaining the same look and feel across the application.
This is the simplified HTML
<!--FIXED PANEL-->
<div class="content-header fd">
<!-- first box-->
<div class="col-md-6 fdc" style="display:block; visibility:visible">
first box
</div>
<!--second box-->
<div class="col-md-2 fdc" >
second box
<span class="pipe_separator">|</span>
</div>
<!--third box-->
<div class="col-md-4 fdc text-left">
third box
</div>
</div>
Here is the CSS
.fd{
position: fixed;
top: 70px;
width:100%;
background-color: #141313ad;
z-index: 1
}
.fdc{
display: inline-block;
*display: inline; zoom: 1;
vertical-align:middle;
background-color: #141313e5;
height: 75px;
border-color: black;
}
.pipe_separator{
font-size: 40px;
}
}
</style>
here is what it looks like
As you can see the content of the boxes are not aligned. I want the third div and its contents to be where I have drawn it out with the number 3 within. The separator just about to its left where I have drawn the green line and the second div to the left of the separator and the first div to the left of the second div. The main div holding these three layers acts as a fixed panel below the page header. How do I make them align together and sit as I have described.

Simplest hack is to put them in a table with no borders. It will work as follows:
<div class="content-header fd">
<table borders="0">
<tr><td>
<!-- first box-->
<div class="col-md-6 fdc" style="display:block; visibility:visible">
first box
</div>
</td>
<td>
<!--second box-->
<div class="col-md-2 fdc" >
second box
<span class="pipe_separator">|</span>
</div>
</td>
<td>
<!--third box-->
<div class="col-md-4 fdc text-left">
third box
</div>
</td>
</tr>
</table>
</div>

Related

Bootstrap stretch contents on entire screen

I am using bootstrap for responsive design.
I want contents to auto-fill depend on the screen size (Which bootstrap allows in-built). Although it is not working when I am connecting to the big monitor (22 inch)
See as below:
Picture 1 (on my Laptop); Covers the entire screen
Picture 2 on Big Monitor (Notice the empty area in the bottom)
(Between Header 6 and End of Browser window)
I expect Headers and contents will be displayed big to cover the entire screen
HTML as below:
<div class="container-fluid">
<div class="row" >
<table class="table">
<tr>
<td><img alt="Bootstrap Image Preview" src="Images/Logo.png"></td>
<td align="right"><img alt="Bootstrap Image Preview" src="Images/Header_RequestExpress.png"></td>
</tr>
</table>
</div>
<div class="row" style="border:1px solid; color:Red;">
<div class="col-md-4" style="border:1px solid; color:green;">
<h2>Categories</h2>
<!--Images Carousel Here-->
</div>
<div class="col-md-8">
<div class="row" style="border:1px solid; color:blue;">
<div class="col-md-12">
<h2>Locations</h2>
<!--Images Carousel Here-->
</div>
</div>
<div class="row" style="border:1px solid; color:Maroon;">
<div class="col-md-12">
<h2>Location Current Requests</h2>
<h1>Header 1</h1>
<h2>Header 2</h2>
<h3>Header 3</h3>
<h4>Header 4</h4>
<h5>Header 5</h5>
<h6>Header 6</h6>
</div>
</div>
</div>
</div>
Apply height:100vh;to the container div.
In your example, on your laptop it was just lucky to appear that way, with the content you filled as you didn't put any rule for the page to be full-height.
You either have to proportion .table and .row vertically.
Example:
.table {
height: 30vh;
}
.row {
height: 70vw;
}
Or let's say the table height is 100px and you want the other part to be filled for the rest of the screen, you can apply:
.table {
height: 200px;
}
.row {
height: calc(100vh - 200px);
}
NOTE I'd suggest you add another class as well to the div .row as that class can be used other places as well, as the Bootstrap provides it.

How to center text inside a bootstrap grid

I have a grid divided into 2. One side holds an image and the other side some text. Currently it looks as follows:
I want to make it look as follows:
I am looking to get rid of the black spot and center the text. There is no issue in centering it horizontally but unable to do it vertically to fit nicely in relation to the image. Please advice if there is any pre built class already available in bootstrap or I need to rewrite additional CSS.
The following are my current html and css.
HTML
<div class="col-md-6 custom-info">
<img src="img/test.jpg" class="img-responsive center-block">
</div>
<div class="col-md-6 custom-info text-center" style="text-align: left;">
<h1>Discover Our Latest Colourful addition</h1>
<h3>Explore our range of text text text text.</h3>
<h3>View the menu.</h3>
</div>
CSS
.custom-info{
background-color: #c0d023;
padding: 30px;
}
After Editing:
You may try this.
HTML
<div class="row xclassrow">
<div class="col-md-6 custom-info">
<img src="http://i.imgur.com/VpelmxT.png?1" class="img-responsive center-block">
</div>
<div class="col-md-6 custom-info text-left">
<div class="content">
<h1>Discover Our Latest Colourful addition</h1>
<h3>Explore our range of text text text text.</h3>
</div>
<h3>View the menu.</h3>
</div>
CSS
.xclassrow{
background-color:#C0D123
}
.content {padding:40px 0px}
.custom-info{
background-color: #c0d023;
padding: 30px;
}
Hope this works. Do comeback if still any issue.!!
EDIT : Removed the xclass and wrap the content in a new class. Check DEMO
TLDR;
Use display:table with display:table-cell to accomplish vertical centering of elements.
For newer browser you can use flexbox. I will demonstrate both approaches here.
Old but secure way (may not work for you here)
What I do most of the time is define 2 helper classes called t and td
*This works if you have a defined height of the containing element
The code then looks something like this:
HTML
<div class="col-md-6 custom-info text-center" style="text-align: left;">
<div class="t">
<div class="td">
<h1>Discover Our Latest Colourful addition</h1>
<h3>Explore our range of text text text text.</h3>
<h3>View the menu.</h3>
</div>
</div>
</div>
CSS
.t {
display: table;
height: 100%;
}
.td {
display: table-cell;
vertical-align: middle;
height: 100%;
}
Jsfiddle
Old and even more secure way
Since you know that your 2 columns are 6+6 and that makes 12 columns total width.
Make 1 long element col-md-12 and make a table inside it (either with regular table elements or the helper classes i used in the above example.
HTML
<div class="col-12 specific-class">
<div class="t">
<div class="td">
<img src="http://static.adzerk.net/Advertisers/d936d243e9de4c989a6c95b031eb11d6.png" alt="">
</div>
<div class="td">
<h1>Discover Our Latest Colourful addition</h1>
<h3>Explore our range of text text text text.</h3>
<h3>View the menu.</h3>
</div>
</div>
</div>
CSS
.specific-class .td {
width: 50%;
background: rgba(0,0,0,.2);
}
.t { display: table; height: 100%; width: 100%; }
.td { display: table-cell; vertical-align: middle; height: 100%; }
Jsfiddle
Note: added vertical align to the image to remove small spacing under it
The mighty flexbox (the future looks bright)
Flexbox is a sight for sore eyes for us fe-devs and will be an integral building block of the future www.
HTML
<div class="col-12 specific-class">
<div class="fl-element">
<img src="http://static.adzerk.net/Advertisers/d936d243e9de4c989a6c95b031eb11d6.png" alt="">
</div>
<div class="fl-element">
<h1>Discover Our Latest Colourful addition</h1>
<h3>Explore our range of text text text text.</h3>
<h3>View the menu.</h3>
</div>
</div>
CSS
.specific-class {
display: flex;
align-items: center;
}
.specific-class .fl-element {
width: 50%;
}
Jsfiddle

How do you use CSS column / grid to setup a text and image collage layout?

I am using older Skeleton css version, it is a 16 column grid system. I am trying to setup similar layout as in this picture.
http://imgur.com/sIV2aYo
I am pretty new to CSS, is using two containers (one inside another) a proper method?
Here is a sample code of what I been trying, but not working out too well =(
<div class="container">
<div class="eight columns alpha">
<div class="image">
<img alt="" src="images/coffee.jpg">
</div>
</div>
<div class="eight columns omega">
<div class="container">
<div class="eight columns">
<img alt="" src="images/plate.jpg">
</div>
<div class="eight columns">
<img alt="" src="images/macaro.jpg">
</div>
<div class="text area">
<p class="quote">"One of my favorite parts of using Square Register is being able to talk to customers while I am swiping their cards."</p>
<p class="name">Norm Mui, Coffee Foundry</p>
</div>
</div> <!-- 2nd container -->
</div>
</div> <!-- 1st container -->
Thanks in advance.
I don't know your CSS, but maybe this helps you:
HTML:
// The class "columns" is your "block" (div) that needs the content. I've made a CSS with a background-color, height and width.
// In that div "columns we create new "columns, numbered by 1,2 and 3. I've floated all the text to the left and gived it a margin. The first, second and the third a margin of 15px ( top, right, buttom and left ).
// In the div column "columns" I have made a textarea with also a margin of 15px. The vertical-align is for a top vertical align. with the display we means that it needs to be in the block, with a margin of 40% ( it takes 40% of the block).
<div id="container">
<div class="columns">
<div class="eight-columns-1">
<img alt="" src="http://ww1.prweb.com/prfiles/2014/04/10/11752526/gI_134971_best-image-web-hosting.png">
</div>
<div class="eight-columns-2">
<img alt="" src="http://www.causingeffect.com/images/made/images/example/cow_100_100_c1.jpg">
</div>
<div class="eight-columns-3">
<img alt="" src="http://www.causingeffect.com/images/made/images/example/cow_100_100_c1.jpg">
</div>
<div class="textarea">
<p class="quote">"One of my favorite parts of using Square Register is being able to talk to customers while I am swiping their cards."</p>
<p class="name">Norm Mui, Coffee Foundry</p>
</div>
</div>
</div>
CSS:
.columns {background-color:yellow; width: 530px; height: 285px;}
.eight-columns-1 {float:left; margin: 15px;}
.eight-columns-2 {float: left; margin: 15px;}
.eight-columns-3 {float:left; margin: 15px 15px 15px 0px;}
.textarea {vertical-align:top; margin: 15px; display:inline-block; width: 40%;}

CSS: creating a certain layout using bootstrap

I'm trying to create a certain layout using bootstrap:
But unable to achieve 2 main principles in my layout:
in the first row, div 2 should be 'sticked' to the bottom of it's column (relayed on div1's height).
in the second row, i have 3 divs i want to align at center (while using bootstrap grid system!)
edit: regarding the 2nd row: i tried using 3 columns lets say 3-col for each div (since i want the margin on the right and left) but i remain with an offset of 3 more which i cant divide equally.
so i decided changing it to col-4 with a margined container, that's my solution to it:
<div class="container" style="padding: 0 80px;">
<div class="row">
<div class="col-xs-4">
<div style="border:solid 1px black;">Div1</div>
</div>
<div class="col-xs-4">
<div style="border:solid 1px black;">Div2</div>
</div>
<div class="col-xs-4">
<div style="border:solid 1px black;">Div3</div>
</div>
</div>
</div>
http://jsfiddle.net/tomico/y7xesq6v/
Hope anyone could explain how can i handle this 2 issues
Would this suffice?
.div1{position:relative;margin-top:20px;float:left;}
.div2{position:absolute;float:left;right:0px;top:40px;}
As for the 3 div row, i would wrap those three up with another div, to center just that one div containing the other three divs.
// Classes
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
// Usage as mixins
.element {
.center-block();
}
from : Bootstrap Source
You could just use a margin-top with % for .div2
.div2 {margin-top:50%}
For your second issue what's been said above will work,
here's how the code should look:
<div class="row">
<div class="wrap">
<div class="col-xs-4">
<div style="border:solid 1px black;">Div1</div>
</div>
<div class="col-xs-4">
<div style="border:solid 1px black;">Div2</div>
</div>
<div class="col-xs-4">
<div style="border:solid 1px black;">Div3</div>
</div>
</div>
then add CSS for wrap
.wrap {width:50% ; margin:0 auto } //or 800px or whatever

Bootstrap Columns inside Row different renderings

I have multiple rows that I would like to line up all in the same fashion.
<div class="row">
<div class="col-md-3">
<div class="img-circle index circle partner-circle box-shad"></div>
</div>
<div class="col-md-9">
<h2 class="partner-heading">Stuff </h2>
<hr />
<p class="lead">This is some text</p>
</div>
</div> <!-- row -->
But the h2 text is not lining up properly in relation to the other elements as shown in this picture:
The site is HERE if you would like to see it live. Can you help me figure out why the styling is inconsistent between the elements?
change (in your style.css)
.circle1, .circle3 {
margin: 39px 0 41px;
}
to this
.circle {
margin: 39px 0 41px;
}
then all the Images Line up with the rightside content