Vertically align divs across bootstrap columns - html

I'm new to html and css so bear with me here. I have a row in bootstrap with two columns. I want to vertically align divs in the left column with divs in the right column. How can I do this?
Concretely, I want to have divs with text on the left that explain certain elements on the right. For example, imagine reading a book but on the left margin of the page there are callouts that define words aligned next to those words.
The content in the right column is dynamic. I know certain divs will be present, I just don't know exactly where they will be vertically.
Here is a jsfiddle: http://jsfiddle.net/dylanlingelbach/C73ap/. It should be a fairly minimal repro of what I am trying to do. In my actual case the breaks are html content that I don't know the size of.
I'm using bootstrap 2.
I'd prefer to do this without javascript if possible. I am sure I can do it dynamically by finding the location of the div in the right column and dynamically adjusting the absolute position of the div in the left column to it but I feel like a pure CSS solution would be more elegant.
HTML:
<div class="modal">
<div class="modal-header">
<button type="button" class="close cancel" aria-hidden="true">×</button>
<h2 id="invite-modal-label">Some text</h2>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span3">
<div class="one">
Align with #anchor1
</div>
<div class="two">
Align with #anchor2
</div>
</div>
<div class="span9 padded">
Content
<br/><br/><br/><br/><br/><br/>
<div id="anchor1">
#anchor1
</div>
<br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/>
<div id="anchor1">
#anchor2
</div>
<br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/>
Text at the end
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success confirm">Send</button>
<button class="btn btn-danger cancel">Cancel</button>
</div>
</div>
CSS:
#import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
.modal {
width: 60%;
left: 5%;
margin: auto auto auto auto;
}
.one {
border:1px solid black;
}
.two {
border:1px solid black;
}
UPDATE:
I don't want to reformat my html. The content in the right column is rendered separately. Essentially this data is displayed in several places not all of which will have the left column. I'd like to keep my code that renders the content of the right column separate from the rest of the markup.

For each item that you want to vertically align they need to be in their own rows:
<div class="row-fluid">
<div class="span6"></div>
<div class="span6">content content content content content content content content content content content content content content content content content content</div>
</div>
<div class="row-fluid">
<div class="span6">Align with #anchor1</div>
<div class="span6">#anchor1</div>
</div>
Here is the correct jsfiddle

You should probably rework your HTML to support more of the format you are trying to achieve.
I would suggest dividing up each anchor label and it's content into it's own row.
What I did was break up each section into it's own .fluid-row, like this:
<div class="modal">
<div class="modal-header">
<button type="button" class="close cancel" aria-hidden="true">×</button>
<h2 id="invite-modal-label">Some text</h2>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span3">
<div class="one">Align with #anchor1</div>
</div>
<div class="span9 padded">
Content for anchor 1
<br /><br /><br /><br /><br /><br />
</div>
</div><!-- end .row-fluid -->
<div class="row-fluid">
<div class="span3">
<div class="two">Align with #anchor2</div>
</div>
<div class="span9 padded">
Content for anchor 2
<br /><br /><br /><br /><br /><br />
</div>
</div><!-- end .row-fluid -->
</div>
<div class="modal-footer">
<button class="btn btn-success confirm">Send</button>
<button class="btn btn-danger cancel">Cancel</button>
</div>
</div>
You can see the results of this here: http://jsfiddle.net/C73ap/38/

Related

Grid layout for Bootstrap

I'm having a hard time styling my columns in a certain way. I have 2 rows containing 2 columns each of the same size.
A B
C D
I'm supposed to add a longer column that encompasses both rows next to it.
A B E
C D E
With E having the equal length of both rows. I tried separating two divs and floating each to its corresponding sides to no avail.
My code:
.announcements{
width: 300px;
height: 500px;
background: #FFFFFF;
box-shadow: 0 4px 4px 0 rgba(0,0,0,0.08);
float: right;
}
.btn-links{
width: 300px;
height: 160px;
background: #FFFFFF;
box-shadow: 0 4px 4px 0 rgba(0,0,0,0.08);
border-radius: 5px;
}
<div class="container-fluid bg-content">
<div class="content">
<div class="content-heading">
<h1> Welcome, </h1> <!--Name of user-->
<h4> What do you want to do today? </h4>
</div>
<div class="quick-links">
<div class="row">
<div class="col-md-4">
<button class="btn-links"></button>
</div>
<div class="col-md-4">
<button class="btn-links"></button>
</div>
<div class="panel announcements">
</div>
</div>
<div class="row">
<div class="col-md-4">
<button class="btn-links"></button>
</div>
<div class="col-md-4">
<button class="btn-links"></button>
</div>
</div>
</div>
</div>
</div>
However, this code produces:
ABCD being rectangle boxes, E being the long column on the right. How can I fix this that we can put more rectangle boxes on the left side and the right panel stays floating on the side? Thanks in advance.
What you want is the following, and you can check it out at this fiddle, but make sure that the window is big enough that the 4/12 of md size fits on the right otherwise responsiveness will cause it to fall bellow.
If you want to make it so that it stays on the right for smaller sizes, you would want to replace col-md... with col-sm... or add the col-sm...
<div class="container-fluid bg-content">
<div class="content">
<div class="content-heading">
<h1> Welcome, </h1> <!--Name of user-->
<h4> What do you want to do today? </h4>
</div>
<div class="quick-links">
<div class="row">
<div class="col-md-8">
<div class="col-md-6">
<button class="btn-links"></button>
</div>
<div class="col-md-6">
<button class="btn-links"></button>
</div>
<div class="col-md-6">
<button class="btn-links"></button>
</div>
<div class="col-md-6">
<button class="btn-links"></button>
</div>
</div>
<div class="col-md-4 panel announcements">
hello there
</div>
</div>
</div>
</div>
</div>
You go from the outside in. First you have a row that contains the whole thing with one div being 8/12 of the row, and the other div in it being 4/12 for the panel announcements. Then, within the first 8/12 div you have two rows, each having two divs with each having 6/12 of that space.

right aligning a bootstrap footer

I have a footer that is set up as follows:
<hr>
<footer>
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-primary" onclick="window.location.href='Glossary.html'">Glossary</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='Bibliography.html'">Bibliography</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='For_Help.html'">Where To Go For Help</button>
</div>
<div class="col-md-6 col-md-offset-6" style="padding-top: 5px">
<div class="panel panel-default">
<div class="panel-body col-xl-1">
<p> For questions or concerns regarding this webpage, contact: <strong>checkeredflags#gmail.com</strong></p>
<p>© 2017 Checkered Flags</p>
</div>
</div>
</div>
</div>
</footer>
How could I set it up such that the buttons are on the left, and the 2 paragraph tags are aligned with the buttons, however pulled to the right side of the screen? Currently the div with the paragraphs sits underneath the buttons. Ideally they would only go underneath when the screen size was small enough
Try This
<div class="panel-body col-xl-1">
<div class="pull-right">
<p> For questions or concerns regarding this webpage, contact:
<strong>checkeredflags#gmail.com</strong></p>
<p>© 2017 Checkered Flags</p>
</div>
</div>
Looks like the col-md-offset-6 class is pushing it down as well as the padding-top: 5px;.
See: https://codepen.io/anon/pen/ZJaJwe

How to get bootstrap col appear side by side

I am usually able to do this. But for some reason everything I've tried just isn't working.
I've tried
<div class="row">
<div class="col-md-8">
<button>Toronto</button>
<button>Markham</button>
<button>Petawawa</button>
</div>
<div class="col-md-4">
<p>date</p>
<p>date</p>
<p>date</p>
</div>
</div>
And similar variations, but I can't seem to get the date and the event location to line up.
The code where the issue is occuring:
<div id="Location">
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-12 aboutCopyContainer">
<p class="copyHeader" style="font-family: testFont;">Locations</p>
<p class="faqContent">Fall for the FEAST at an event near you!</p>
<div class="row">
<div class="col-md-6">
<div class="btnLocationCont">
<button class="btn btn-primary btn-lg locationBtn locationButtonText" style="font-family: AvenirNextLTPro-Condensed;" onclick="window.location.href='http://convio.cancer.ca/site/PageNavigator/UFE_ON_Oktoberfeast_Toronto.html'">Toronto</button>
<div class="locationDateCont">
<p class="locatDay eventTimeBut">14</p>
<hr style="margin:0px;" />
<p class="locatMonth eventTimeBut">Oct</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="btnLocationCont">
<button class="btn btn-primary btn-lg locationBtn locationButtonText" style="font-family: AvenirNextLTPro-Condensed;" onclick="window.location.href='http://convio.cancer.ca/site/PageNavigator/UFE_ON_Oktoberfeast_Petawawa.html'">Petawawa</button>
<div class="locationDateCont">
<p class="locatDay eventTimeBut">7</p>
<hr style="margin:0px;"/>
<p class="locatMonth eventTimeBut">Oct</p>
</div>
</div>
<div class="btnLocationCont">
<button class="btn btn-primary btn-lg locationBtn locationButtonText" style="font-family: AvenirNextLTPro-Condensed;" onclick="window.location.href='http://convio.cancer.ca/site/PageNavigator/UFE_ON_Oktoberfeast_Markham.html'">Markham</button>
<div class="locationDateCont">
<p class="locatDay eventTimeBut">22</p>
<hr style="margin:0px;"/>
<p class="locatMonth eventTimeBut">Oct</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here is the JS Fiddle of what's happening:
JSFiddle
and this is the website (under Locations section) to give you a better idea of what I'm trying to do (css styling etc applied).
Oktoberfeast Locations
Any suggestions are greatly appreciated! thank you for your time
You added fixed width inside bootstrap column child. And that width together with other element width exeeded bootsrap column width, so the class locationDateCont appeared underneath:
So, in your CSS file, remove that width from that class, and add this:
.btnLocationCont {
width: auto;
}
Hope this helps!
You probably don't want to do this that way. Reason being is on mobile devices they won't match up.
To keep them together and display on desktop and mobile you could do something like this:
<div class="row">
<div class="col-md-4">
<button>Toronto</button>
<p>date</p>
</div>
<div class="col-md-4">
<button>Markham</button>
<p>date</p>
</div>
<div class="col-md-4">
<button>Petawawa</button>
<p>date</p>
</div>
</div>
Fiddle:
https://jsfiddle.net/8t5mjhf8/4/
EDIT: To make sure the p's stay next to the buttons you need the following CSS. You will want to assign a class to the p's as to no interfere with other paragraphs.
p {
display: inline;
}

How to center text in panel-heading alongside a button pulled into the right

I created a panel heading in bootstrap and tried to center its text while having a button that's supposedly on the same horizontal axis as the text but pulled in the right but my output was:
The button wasn't horizontally aligned with the text
The text is centered between the left of the heading and the left of the button instead of being centered between the left and right side of the heading
Here's my code:
<div class='container'>
<div class='panel panel-default'>
<div class='panel-heading'>
<div class='panel-heading text-center'>
<h4>Present Schedule<button class='btn pull-right btn-danger' onclick="location.href='past_sched.php'">Go to Past Schedule</button></h4>
</div>
</div>
</div>
</div>
Here's a jsfiddle of the result: https://jsfiddle.net/63c0wn66/3/
Try this code. Put button outside h4
HTML
<div class='container'>
<div class='panel panel-default'>
<div class='panel-heading text-center panel-relative'>
<button class='btn btn-danger btn-right' onclick="location.href='past_sched.php'">Go to Past Schedule</button>
<h4>Present Schedule</h4>
</div>
</div>
</div>
CSS
.panel-relative{
position: relative;
}
.btn-right{
position: absolute;
right: 15px;
}
https://jsfiddle.net/63c0wn66/7/
1) Put your button outside h4
2) Apply for h4 property display: inline-block
<div class='container'>
<div class='panel panel-default'>
<div class='panel-heading text-center'>
<h4 class="myClass">Present Schedule</h4>
<button class='btn pull-right btn-danger' onclick="location.href='past_sched.php'">Go to Past Schedule</button>
</div>
</div>
</div>
.myClass {
display: inline-block;
}
JSFiddle

How to set child div to parent's height (100%)?

This is they layout of the page
Here's the code for this
<div class="newsContent row">
<div class="newsDate col-md-2">05 August 2014</div>
<div class="newsSeparator col-md-1">
</div>
<div class="newsDescription col-md-7">
<div class="row">
some dummy news
<div class="newsImage"><img alt="news2" src="/Images/News/news2.jpg">
</div>
</div>
</div>
<div class="newsActions col-md-2">
<div class="row">
<div class="col-md-4">
<button type="button" class="btn btn-default btn-lg edit-content" title="Edit the news" <span class="glyphicon glyphicon-pencil">
</span>
</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-default btn-lg delete-content" title="Delete the news">
<span class="glyphicon glyphicon-trash"></span>
</button>
</div>
</div>
</div>
</div>
Now as you can see this green line is this part
<div class="newsSeparator col-md-1">
</div>
and the class is
.newsSeparator
{
background: url('my_1X1_pixel_image.png');
background-repeat: repeat-y;
}
But it is not repeating. I just see a 1px image instead of this desired green line. Something like this.
Why is it not repeating in y, after I've set background-repeat: repeat-y;. How do I make this like the desired line that repeats along y, and stretch/size accordingly as per the parent div and the news content?
EDIT
This is not a duplicate of that. I have background image that I need to repeat along y-axis.
You could wrap news description and image into a single <article> element
Then you may assign a border-left to the new inserted element. Doing so you avoid to use empty markup for styling purpose only and you also improve the semantic of the page.
<article>
<div class="newsDescription col-md-7">
<div class="row">
...
</div>
</div>
<div class="newsActions col-md-2">
<div class="row">
...
</div>
</div>
</article>
CSS
article {
border-left: 1px green solid;
padding-left: ... /* give some space between border and contents */
}
You can set height:inherit to set child div's height same as parent div.