Centralizing vertically and horizontally with Bootstrap - html

I have three elements arranged in a row. The left most is a button, then there's some images in id="slide" and then I have another div. The html looks like:
<div id="display">
<div class="row">
<div class="col-lg-3 col-lg-offset-1">
<div id="drawMenu" class="center-block">
<button type="button" class="btn btn-lg btn-danger" id="erase">Erase</button>
</div>
</div>
<div class="col-lg-4">
<div id="slide">
</div>
</div>
<div class="col-lg-3">
<div id="colorPicker" class="center-block">
<div class="color" id="white"></div>
<div class="color" id="yellow"></div>
<div class="color" id="green"></div>
<div class="color" id="blue"></div>
<div class="color" id="red"></div>
<div class="color" id="black"></div>
</div>
</div>
</div>
</div>
The issue is, I have the images in the center but I can't get the two elements on each side to be centralized vertically and horizontally. The CSS looks like:
.color{
height:30px;
width:30px;
margin: 2px;
border-radius: 50%;
}
#drawmenu{
text-align: center;
}
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
The only thing I believe is actually working is the text-align: center
Hopefully the image will explain what I'm looking for. Sorry about the quality. As good as I could get with paint. The grey parts on the sides are offsets.
http://i1028.photobucket.com/albums/y349/oqrgyikf/stackoverflow_zpsf3b6fa31.png
Thank you

add a class to those columns so you can target them more efficiently, and then the following CSS:
.row{display:block;}
.vertimid{display:inline-block; vertical-align:middle ; height:auto; min-height:100%;}
.vertimid img{width:100%; height:auto;}
See Bootply here

Related

Container-Fluid in Mobile

I have a list like that:
I open a hidden div to show details about list items like that:
It's ok for large screen but in mobile info div goes so below. Is it possible to open info div as %100 (Container-Fluid) under that item in mobile like that:
If it's possible what is the keywords or can you show an example? Thanks in advance.
I have created a sample where you need to create two locations with the same div contents, one for mobile (.mobile-content) and one for desktop (.desktop-content).
The way you style it is when the mobile is visible, the desktop is hidden and vice versa. You can hide and show element using the Bootstraps 4 .d-x-none and .d-x-block.
The only thing left is you have to implement the click mechanism when you click on the circles......
Example (view this in full page):
.main-box {
text-align:center;
}
.circle{
flex-basis:33%;
}
.circle img{
background:pink;
border-radius: 50%;
max-width:100%;
}
.mobile-content{
flex-basis:100%;
}
.desktop-content{
text-align:center;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<div class="main-box container-fluid d-flex justify-content-center flex-wrap flex-lg-nowrap">
<div class="circle px-2"><img src="https://dummyimage.com/200x200/4d204d/ffffff" /></div>
<div class="circle px-2"><img src="https://dummyimage.com/200x200/4d204d/ffffff" /></div>
<div class="circle px-2"><img src="https://dummyimage.com/200x200/4d204d/ffffff" /></div>
<div class="mobile-content p-2 d-lg-none">
<p>description comes here</p>
</div>
<div class="circle px-2"><img src="https://dummyimage.com/200x200/4d204d/ffffff" /></div>
<div class="circle px-2"><img src="https://dummyimage.com/200x200/4d204d/ffffff" /></div>
</div>
<div class="desktop-content p-4 d-none d-lg-block">
<p>description comes here</p>
</div>
In bootstrap 4, for equal columns in all devices try like this
<div class="row">
<div class="col">
1 of n
</div>
<div class="col">
1 of n
</div>
<div class="col">
1 of n
</div>
.....
<div class="col">
n of n
</div>
</div>
#circle {
width: 50px;
height: 50px;
background: red;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col" id="circle">
</div>
<div class="col" id="circle">
</div>
<div class="col" id="circle">
</div>
<div class="col" id="circle">
</div>
<div class="col" id="circle">
</div>
</div>

How to stack Bootstrap row inside of another row?

I have a Bootstrap page on which I'm trying to stack different boxes.
Imgur - Image of boxes (sorry, not enough rep to upload images directly)
The green boxes are the ones currently in position, and the red ones are the ones I am having issues with. I'm using the following code (simplified) to get the green boxes:-
<div class="container">
<div class="row">
<div class="col-xs-3" style="height:100px; background-color:green;">
</div>
<div class="col-xs-3" style="height:100px; background-color:green;">
</div>
<div class="col-xs-6" style="height:200px; background-color:green;">
</div>
</div>
</div>
I'm basically trying to create another two <div class="col-xs-3" style="height:100px; background-color:green;"> that will go underneath the current two, while also keeping the large box to the right.
I thought it would be an easy fix with a new row, or using float:left / right, but none of that seems to be working out.
One way to do it would be to make two 50% width columns and then divide the column on the right into two rows with two more columns in each:
.green-lrg {
background-color:green;
height:215px;
}
.green-sml {
background-color:green;
height:100px;
}
.red-sml {
background-color:red;
height:100px;
}
.col-xs-6 .row {
padding-top:15px;
}
.col-xs-6 .row:first-child {
padding-top:0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<!-- LEFT COLUMN -->
<div class="col-xs-6">
<div class="green-lrg"></div>
</div>
<!-- RIGHT COLUMN -->
<div class="col-xs-6">
<div class="row">
<div class="col-xs-6">
<div class="green-sml"></div>
</div>
<div class="col-xs-6">
<div class="green-sml"></div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="red-sml"></div>
</div>
<div class="col-xs-6">
<div class="red-sml"></div>
</div>
</div>
</div>
</div>
</div>
Here is simple example.
HTML
<div class="container">
<div class="row">
<div class="col-xs-6 box box-big">
</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-6 box box-small">
</div>
<div class="col-xs-6 box box-small">
</div>
<div class="col-xs-6 box box-small">
</div>
<div class="col-xs-6 box box-small">
</div>
</div>
</div>
</div>
</div>
and CSS:
.box {
background-color:green;
border:5px solid white;
}
.box-big {
height:200px;
}
.box-small {
height:100px;
}

How to align an image horizontally center within a div?

I have this below HTML Code:
<div class="col-sm-12 col-md-12">
<div class="answer-picture col-xs-12" id="bookListDiv">
<div id="loadme" style="display:block; margin:0 auto">
<img src="~/images/loader.gif" />
</div>
</div>
</div>
I tried this and lot more but couldn't align it to center.
apply style text-align:center to div as:
<div class="col-sm-12 col-md-12">
<div class="answer-picture col-xs-12" id="bookListDiv">
<div id="loadme" style="display:block; margin:0 auto;text-align:center">
<img src="~/images/loader.gif"/>
</div>
</div>
</div>
Add only this css to #loadme{text-align:center;}
<div class="col-sm-12 col-md-12">
<div class="answer-picture col-xs-12" id="bookListDiv">
<div id="loadme" style="display:block; text-align:center">
<img src="~/images/loader.gif" />
</div>
</div>
</div>
Do This ..
<div class="col-sm-12 col-md-12">
<div class="answer-picture col-xs-12" id="bookListDiv">
<div id="loadme" class="text-center" style="display:block; margin: 0 auto !important;">
<img src="~/images/loader.gif" />
</div>
</div>
</div>
The DIV containing your IMG should be a display: block;
The image should be a display: inline-block; or its initial state;
By default images or any display: inline-block; objects are much treated like text, so you'll have to assign text-align: center; to your DIV;
Hope this helps you in future.
In css,
#loadme { display:grid; align-items:center;}
Using CSSGrid

Container alignment to the edge of browser window

I have a div that goes to the edge with the browser and would ilke to add content that is aligned to the centered container in the center of the page. I've crated a row with a col-md-6 that I filled with a background color but when I add the container, the content gets aligned to the edge of the browser not to the container's edge.
I am using Bootstrap and really need your help. If I did not articulate the issue properly, I've attached an image that should help.
Thanks for your help.
.login-msg-box {
background: rgba(0,0,0,0.5);
margin-top: 200px;
height: 400px;
}
<div class="row">
<div class="col-md-6 login-msg-box">
<div class="container">
<h2 class="msg-heading-line">LOG IN</h2>
</div>
</div>
</div>
Image shows the current situation and the desired situation
As you did a margin-top for the .login-msg-box, you could for example add a margin-left to your .container. Here's the result :
.login-msg-box {
background: rgba(0,0,0,0.5);
margin-top: 200px;
height: 400px;
}
.container {
margin-left: 200px;
}
<div class="row">
<div class="col-md-6 login-msg-box">
<div class="container">
<h2 class="msg-heading-line">LOG IN</h2>
</div>
</div>
</div>
You can add any number of offset to div
<div class="row">
<div class="col-md-6 col-md-offset-6 login-msg-box">
<div class="container">
<h2 class="msg-heading-line">LOG IN</h2>
</div>
</div>
</div>
I think you are looking for something like this https://jsfiddle.net/neya0v76/1/
I switch everything to xs so it looks right in the fiddle and just restructered your html
<div class="row">
<div class="col-xs-6 login-msg-box">
<div class="row">
<div class="col-xs-6">
</div>
<div class="col-xs-6">
<h2 class="msg-heading-line">LOG IN</h2>
<input type="text"/>
<input type="text"/>
</div>
</div>
</div>

Background image not spanning the entire container-fluid

I am new to this bootstrap. I have a background image which i want to put in the container fluid. How to do it.
This is my code:
<div class="image_outer">
<div class="container-fluid">
<div class="row-fluid">
<div class="span5">
<div class="fl navi"> One TwoP </div>
</div>
<div class="span2"">
<div id="image1"><img src="/Something/something.jpg" alt="" /></div>
</div>
<div class="span5">
<div class="fr navi"> Three Four </div>
</div>
</div>
</div>
</div>
The corresponding classes are
.image_outer{width:100%;margin:0 auto; background:url(Something/something_bg.jpg) repeat-x; height:128px;}
.fl{float:left;}
.fr{float:right;}
.mr30{margin-right:100px; font-family: ee_nobblee,arial;}
.navi a{ font-size:22px; color:#6D6E70; margin-top:50px; float:left; font-weight:normal; font-family:ee_nobblee,arial;}
.navi a:hover { text-decoration:none; color:#858687;}
Try This CSS:
.image_outer {
width:100%;
margin:0 auto;
background:url(Something/something_bg.jpg) repeat-x;
height:128px;
background-position:cover;
}
Use your code like this and I hope this will work for image
.image_outer{width:100%;margin:0 auto;
background:url(../Something/something_bg.jpg) repeat-x;
height:128px;}
I might be wrong, you are floating children. you need to clear the float so that the background takes up the height specified.
<div class="row-fluid">
<div class="span5">
<div class="fl navi"> One TwoP </div>
</div>
<div class="span2"">
<div id="image1"><img src="/Something/something.jpg" alt="" /></div>
</div>
<div class="span5">
<div class="fr navi"> Three Four </div>
</div>
<div style="clear:both"></div>
</div>