Bootstrap, allowing content to be responsive/flexible regardless of html layout - html

So I have a "mostly" functional system that works right now as a CMS: The user goes into an editor and chooses from one of four templates. Within the template they click on a section where they can add images, text or both.
I have a preview screen that shows them what they're making but the issue is that they can create something here where it looks like the image is fitting the space but when it's saved and shown on a huge display it creeps to the top and has a ton of white space below.
So I'm using TinyMCE and when the user saves the info it's saved as HTML in the database, and on my display page (code below) I have that database-driven html coming through a JSON object.
My thing is this: How can I use existing Bootstrap to make sure that regardless of which layout I'm using below (either full width, 2 half width, or a half width with 2 quarter-height half divs) the content within can be more responsive and flexible? I'm trying to get the displayed content to match more closely to what they see on the editor so that regardless of what computer they use to make it, it will be more responseive on the display
This is all of my css and html
html,
body {
height: 100vh;
width: 100vw;
overflow: hidden;
}
iframe{
height:100% !important;
width:100% !important;
}
.middle p{
max-height:100%;
}
.my-container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
width:100vw;
}
.my-container>.top [class^="col-"],
.my-container>.bottom [class^="col-"] {
background-color: #778899 ;
color: white;
text-align: center;
}
.my-container>.middle {
flex-grow: 1;
padding:30px;
/*background-image: url('images/bg_green.svg');*/
background-size: cover;
}
.my-container>.middle>* {
}
<div class="container-fluid my-container d-flex h-100">
<div class="row top">
<?php include 'banner.php'?>
</div>
<div class="row middle" id="middle" style="background-image: url();">
<!-- Full Page Divs -->
<div class="col-lg-12" id="fullColumn">
<div class="fullContent" id="fullContent" style="height: 100%; ">
</div>
</div>
<!-- End Full Page Divs -->
<!-- Half Page Divs -->
<div class="col-lg-6 leftColumn " id="leftColumn" style="align-items: center;">
<div class="leftContent" id="leftContent" style=" margin:auto; height: 100%; ">
</div>
</div>
<div class="col-lg-6 rightColumn" id="rightColumn">
<div class="rightContent" id="rightContent" style=" height: 100%; ">
</div>
</div>
<!-- End Half Page Divs -->
<!-- Quarter Page Divs -->
<!-- Left -->
<div class="col-lg-6" id="leftColumnQtr">
<div class="row" style="height:50%; padding-bottom: 15px;">
<div class="col-lg-12" style="height:100%;">
<div id="topLeftContent" style=" height: 100%; ">
</div>
</div>
</div>
<div class="row" style="height:50%; padding-top: 15px;">
<div class="col-lg-12" style="height:100%;">
<div id="bottomLeftContent" style=" height: 100%;">
</div>
</div>
</div>
</div>
<div class="col-lg-6" id="rightColumnQtrHalf" >
<div id="rightQtrContent" style=" height: 100%; ">
</div>
</div>
<!-- right -->
<div class="col-lg-6" id="rightColumnQtr">
<div id="leftQtrContent" style="height: 100%;">
</div>
</div>
<div class="col-lg-6" id="leftColumnQtrHalf" >
<div class="row" style="height:50%; padding-bottom: 15px;">
<div class="col-lg-12" style="height:100%;">
<div id="topRightContent" style=" height: 100%;">
</div>
</div>
</div>
<div class="row" style="height:50%; padding-top: 15px;">
<div class="col-lg-12" style="height:100%;">
<div id="bottomRightContent" style=" height: 100%;">
</div>
</div>
</div>
</div>
<!-- End Quarter Page Divs -->
</div>
<!-- End Row Middle -->
<div class="row bottom">
<?php include 'ticker.php';?>
</div>
</div>

Here's a solution based on what I could get about what you wanted. One thing I'd Strongly recommend is not setting width and height before the initial layout is structured. once the skeleton is ready you can start messing with it.
NOTE: I used bootstrap 4.2.1 for testing this.
"//maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
-- SOLUTION --
I removed all your styles to make things simpler, the styles below are for display purpose only. Feel free to play with it.
<style>
div {
background-color: #00333333;
margin: 0;
padding: 5px;
min-height: 20px;
}
div.row {
background-color: #ff000033;
}
</style>
HTML code
<div class="container-fluid">
<div class="row top">
<h2>something in top</h2>
</div>
<div id="middle">
<div class="row">
<!-- Full Page Divs -->
<div class="col-sm-12">
<h1> FULL PAGE </h1>
</div>
</div>
<!-- End Full Page Divs -->
<!-- Half Page Divs -->
<div class="row">
<div class="col-sm-6">
<h1> left half </h1>
</div>
<div class="col-sm-6">
<h1> right half </h1>
</div>
</div>
<!-- End Half Page Divs -->
<!-- Quarter Page Divs -->
<!-- Left -->
<div class="row">
<div class="col-sm-6" id="leftColumnQtr">
<div class="row">
<div class="col-sm-12">
<h1>topLeftContent</h1>
</div>
<div class="col-sm-12">
<h1>bottomLeftContent</h1>
</div>
</div>
</div>
<div class="col-sm-6" id="rightColumnQtrHalf">
<div class="col-sm-12">
<h1>Right half</h1>
</div>
</div>
</div>
<!-- right -->
<div class="row">
<div class="col-sm-6" id="rightColumnQtrHalf">
<div class="col-sm-12">
<h1>Left half</h1>
</div>
</div>
<div class="col-sm-6" id="leftColumnQtr">
<div class="row">
<div class="col-sm-12">
<h1>top right Content</h1>
</div>
<div class="col-sm-12">
<h1>bottom right Content</h1>
</div>
</div>
</div>
</div>
<!-- End Quarter Page Divs -->
<!-- BONUS: may be this is what you wanted too -->
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-sm-6">
<div class="col-sm-12">
<h1>top Left Content</h1>
</div>
<div class="col-sm-12">
<h1>bottom Left Content</h1>
</div>
</div>
<div class="col-sm-6" id="rightColumnQtrHalf">
<div class="col-sm-12">
<h1>Right half</h1>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-6">
<div class="col-sm-12">
<h1>Left half</h1>
</div>
</div>
<div class="col-sm-6">
<div class="col-sm-12">
<h1>top right Content</h1>
</div>
<div class="col-sm-12">
<h1>bottom right Content</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End Row Middle -->
<div class="row bottom">
<h2>something in bottom</h2>
</div>
</div>
Let me know if this is what you intended.

Related

Horizontally aligning elements in a div

I am trying to align three elements in a div in such a way that the image is inline with h1 while the p tag is beneath the h1 tag.
.valign{
position:relative;
top: 50%;
transform: translateY(-50%);
vertical-align: middle;
}
.banner{
position: relative;
height: 100vh;
width:100vw;
background: #eee;
}
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<img src="img/logo.png" style="height: 150px;width: 150px">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p>
</div>
</div>
</div>
</div>
</div>
Here is an image for reference:
This is how the elements must be arranged
This is how the elements are looking right now:
This is a screenshot of the webpage
Any help would be appreciated.
Try this
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<div class="float-xs-left float-sm-left float-md-left">
<img src="img/logo.png"></div>
<div class="float-xs-left float-sm-left float-md-left">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p></div>
</div>
</div>
</div>
</div>
</div>
the class value for float is based on bootstrap 4
Try this html
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<div style="float:left">
<img src="img/logo.png" style="height: 150px;width: 150px"></div>
<div style="float:left">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p></div>
</div>
</div>
</div>
</div>
</div>
Use floats, Bootstrap provides pull-left and pull-right helper classes, so use it on the two parts of your layout to have them side-by-by.
You need to add some margins here and there to make it look good.
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<div class="row">
<div class="pull-left">
<img src="img/logo.png" style="height: 150px;width: 150px">
</div>
<div class="pull-left">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
https://jsfiddle.net/n8o1w3cq/

Side bar has undefined height and misplaced image

I'm sure I'm overcomplicating this in my head, but is the following layout possible using the standard bootstrap 3 grid system?
Header and sub header can fill 12 columns. Then Image, probably fixed height, spans 8-col then a side bar which spans 4-col. The problem is the side bar has an undefined height and the underneath of the image is content.
So far got something like:
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-8">
image
</div>
<div class="col-md-4">
Navigation down right
</div>
<div class="col-sm-8">
Content
</div>
</div>
Layout
According to your image
You should use the following layout (Click the "Full page" button to see it in action. Also, ignore the CSS. It's just for testing purposes):
#import url(https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css);
[class*='col-'] > div:not(.row) {
background: #DDD;
margin: 0.25em 0;
padding: 0.5em;
text-align: center;
height: 5em;
}
.red [class*='col-'] > div:not(.row) {
background: #C55;
color: #FFF;
height: auto;
}
[class*='col-sm-4'] > div:not(.row) {
height: 9em;
}
<div class="container">
<div class="red row">
<div class="col-sm-12">
<div>HEADER</div>
</div>
<div class="col-sm-8">
<div>SUB HEADER</div>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<div class="row">
<div class="col-sm-12">
<div>IMAGE</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div>LEFT COL</div>
</div>
<div class="col-sm-6">
<div>RIGHT COL</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div>SIDEBAR</div>
</div>
</div>
</div>
Essentially you want a nested row with 6 wide columns for a 12 column grid layout.
Bootstrap row has only twelve spans. I see that 8 + 4 + 8 = 20 > 12, so the "content" div will be at a new line...
And you can't put col-sm-x with col-md-x in the same row...
My suggestion: split into two rows
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-8">
image
</div>
<div class="col-md-4">
Navigation down right
</div>
</div>
<div>
<div class="col-sm-8">
Content
</div>
</div>
But If you want all of it in the same row:
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-5">
image
</div>
<div class="col-md-2">
Navigation down right
</div>
<div class="col-md-5">
Content
</div>
</div>
And if you want a side section, you can cascade rows:
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
Image
</div>
</div>
<div class="row">
<div class="col-md-12">
Content
</div>
</div>
</div>
<div class="col-md-4">
Navigation down right
</div>
</div>

How to overlap panel from one row to another row?

I have these panels inside different rows. To easily show my problem, and my desired output, here's a visual...
At the left side is the problem I encounter, and at the right side is the desired output. I was wondering how it's possible to make the right panel overlap to the other row.
My html's structured something like this, which is all inside a .container-fluid(if that contributes to the problem)...
<div class="row">
<div class="col-md-6">
<div class="panel"> <!-- top-left panel --> </div>
</div>
<div class="col-md-6">
<div class="panel"> <!-- right panel --> </div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel"> <!-- bottom-left panel --> </div>
</div>
</div>
I'm using bootstrap.
p.s. sorry for the html "sample", not familiar yet on how to use the html snippet
Use flex
.flex{
display:flex;
}
.flex-1{
flex:1;
}
.height-50{
height:50px;
}
.margin-r-15{
margin-right:15px;
}
.border-1px{
border:1px solid black;
}
<div class="flex">
<div class="flex-1 margin-r-15">
<div class="height-50 border-1px" >
</div>
<div class="height-50 border-1px">
</div>
</div>
<div class="flex-1 border-1px">
</div>
</div>
You can code left div's in one wrapper and right one in another.
HTML
<div class="row">
<div class="col-md-6">
<div class="panel">
//top left panel
</div>
<div class="panel">
// bottom left panel
</div>
</div>
<div class="col-md-6">
<div class="panel">
// right panel
</div>
</div>
</div>
According to your visual above html will be fine but heights are not managed in this.
If you wish to have same height of right box according to left main box then use follwing code
HTML
<div class="row main">
<div class="col-md-6 inner">
<div class="panel">
//top left panel
</div>
<div class="panel">
// bottom left panel
</div>
</div>
<div class="col-md-6 inner">
<div class="panel">
// right panel
</div>
</div>
</div>
CSS
.main{
display:flex;
}
Please try like this:
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-12"></div>
</div>
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
</div>
Please try this:
<div class="row">
<div class="col-lg-8 col-md-8 col-xs-12 col-s-12">
<div class="col-lg-12 col-md-12">
//Your Content Here
</div>
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
//Your Content Here
</div>
</div>
<div class="col-lg-4 col-md-4 col-xs-12 col-sm-12">
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
//Your Content Here
</div>
</div>
</div>
If you can use separate columns (as shown in Gaurav's answer) that will work. If the height of the panels is unknown (variable) here isn't really a simple way. Another option is to put all your cols in a single row and use CSS3 column-width..
.row {
-moz-column-width: 50em;
-webkit-column-width: 50em;
-moz-column-gap: .1em;
-webkit-column-gap: .1em;
}
.col-md-6 {
float:none;
display: inline-block;
margin: .1em;
width: 100%;
}
http://www.bootply.com/6ynLAwenzq

Put two objects in the same row with bootstrap

I have here my example in fiddle. I am using bootstrap. What I want to do is have the '150' and the 'points' be in the same row right next to each other. Is this possible? How can I do this?
My html looks like this:
<div class="container">
<div class="row">
<div class="col-md-6">
<h4>Content Submissions: </h4>
</div>
<div class="col-md-6">
<div class="col-md-4 pull-right">
<h2>user name</h2>
<div class="row-fluid">
<h2><strong>150 </strong></h2>
<p><small>Points</small></p>
</div>
Account Settings
</div>
</div>
</div>
</div>
Use following css:
.row-fluid {
display: flex;
}
h2 {
margin-top: 0;
}
Working Fiddle
.row-fluid {
display: flex;
align-items: center;
}
h2 {
margin-top: 0;
margin-right: 10px;
}
hi i have made few changes to your html, try this
<div class="container">
<div class="row">
<div class="col-md-6">
<h4>Content Submissions: </h4>
</div>
<div class="col-md-6">
<div class="col-md-4 pull-right">
<h2>user name</h2>
<div class="row-fluid">
<div class="col-lg-6 col-xs-6">
<h2><strong>150 </strong></h2>
</div>
<div class="col-lg-6 col-xs-6">
<p><small>Points</small></p>
</div>
</div>
Account Settings
</div>
</div>
</div>
</div>
<style>
h2{margin:0;}
</style>

fixed column in bootstrap is not working

I am trying to make a fixed column ( header- containing a image) with full width using bootstrap. Below this column there is another row containing three column( another image in the middle div). When I run my code the things get messy and also other contents passes above the fixed column which should be pass below it. Someone please help me. I am new to bootstrap. Here is my code
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div id="header"><img class="img-responsive" src="images/profile.jpg"></div>
</div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6"><img class="img-responsive" src="images/helpUs.jpg"></div>
<div class="col-sm-3"></div>
</div>
</div>
Here is CSS
.container-fluid{
background-color:#B8DB4D;
}
#header{
position: fixed;
width:100%;
background-color:red;}
Bootstrap has a convention for what you're describing, which can be accomplished by using the .navbar-fixed-top class on the content which should be sticky/fixed to the top of the page.
The only requirement for this to work as expected is that your <body> element has its padding-top property set to the expected height of the .navbar-fixed-top nav element. (in this example, the image 150px tall, so we set the body's padding-top to that height). This way, no content will be hidden behind the nav on page load (only when the user scrolls).
.container-fluid {
background-color: #B8DB4D;
}
#header {
position: absolute;
background-color: red;
}
body {
padding-top: 150px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<img class="img-responsive" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=header%20img&w=350&h=150">
</div>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<img class="img-responsive" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=other%20img&w=350&h=150">
</div>
<div class="col-sm-3"></div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<img class="img-responsive" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=other%20img&w=350&h=150">
</div>
<div class="col-sm-3"></div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<img class="img-responsive" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=other%20img&w=350&h=150">
</div>
<div class="col-sm-3"></div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<img class="img-responsive" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=other%20img&w=350&h=150">
</div>
<div class="col-sm-3"></div>
</div>
</div>