Bootstrap - section and div positioning - html

I am using a Bootstrap template to build a website. I have 2 questions I am struggling to solve:
1) When I put my HTML code into a < section >, automatically some sort of top margin/padding is applied to the section. There is no css code affecting the section.
I can't seem to be able to control how much padding/margin is applied at the top/bottom.
Would anyone know if this is normal and how can I control amount of spacing?
2) If I don't use the section but just the div to separate each portion of my code the text goes right at the top of my page with no spacing at all. I tried using some css but failed at any attempt. This my most recent and basic attempt (also failing)
.q2 {
position: relative;
margin-top: 20px;
}
Thanks for any help - I have tried adding and removing section, using the bootstrap grid, a table but it all still gets either squashed together (if I don't use sections) or way too far apart (if I use sections).
HTML code:
<section>
<div class="container">
<form action="sqlQuery.php" method="post" name="foundationsurvey">
<div class="row">
<div class="col-12 text-center pb-3">
<label for="Q1">Q1</label>
</div>
</div>
<div class="row">
<div class="col-sm-12 text-left ml-4">
<input type="radio" id="dry" required> <label for="dry"> Dry </label>
</div>
</div>
<div class="row">
<div class="col-12 text-left ml-4">
<input type="radio" id="normal" required> <label for="normal"> Normal</label>
</div>
</div>
</div>
<!--Q2-->
<div class="container">
<div class="row">
<div class="col-12">
<label for="Q2">Q2</label>
</div>
</div>
<div class="row">
<div class="col">
<input type="text" name="product1" placeholder="Brand, Product Name" required>
</div>
<div class="col">
<input type="text" name="product2" placeholder="Brand, Product Name" required>
</div>
</div>
</div>
</section>
</header>

Where is the q2 class applied?
try the following:
... <div class="container q2"> ...
all styles work:
section {
margin-top: 150px;
}
.q2 {
/* position: relative; */
margin-top: 20px;
}

Related

How to prevent Bootstrap classes from overlapping?

I have just started learning Bootstrap and am trying to implement it in a web page. But I am having trouble in preventing the bootstrap class divs from overlapping each other. On full screen, the web page looks like:
On reducing the width of the window by some amount, it becomes:
And making window almost as small as mobile screen I get this:
My html code for this is:
<body>
<div id="point" class="row container-fluid">
<div id="point_display" class="col-md-10">
</div>
<div id="point_info" class="row col-md-2">
<div class="col-md-8">
<h5>Current point position:</h5>
<p></p>
</div>
<div class="col-md-8">
<input type="checkbox" id="coordinate_transform" onclick="transformCoordinate(this.checked)"><span>Transform co-ordinate system</span></input>
</div>
<div class="col-md-8">
<h5>Transformation matrix:</h5>
<div id="transformMatrix">
</div>
</div>
</div>
</div>
<div id="control" class="row container-fluid">
<div id="slider" class="col-md-2">
<input type="range" value="0" min="0" max="100" oninput="changePosition(this.value)" onchange="changePosition(this.value)" />
</div>
<!--div id="coordinate" -->
<div class="col-md-3"><span>X: </span><input id="newX" type="number" step="0.0001" value=1 00></div>
<div class="col-md-3"><span>Y: </span><input id="newY" type="number" step="0.0001" value=1 00></div>
<div class="col-md-3"><span>Z: </span><input id="newZ" type="number" step="0.0001" value=- 300></div>
<!--/div-->
<div class="col-md-3"><button id="change_destination" onclick="setNewDestination()">Set New Destination</button></div>
<div class="col-md-3"><button id="reset_camera" onclick="resetCamera()">Reset Camera</button></div>
</div>
<script src="js/main_script.js"></script>
</body>
The black part of the page with axes and stuff is dynamically added to the div with id= point_display inside div point and the matrix is also dynamically added in the div with id = `transformMatrix"
Please help me figure out how to prevent the overlapping of the elements so that on reducing width, they just stack one below other.

Change position of containers in bootstrap

I'm still learning bootstrap and I would like to know what should I use move things inside a bootstrap container.
My question is a little bit strange but maybe with images and code it will be easier to understand.
I want to create a form in that precise position like in this image but I donĀ“t know how can to do it. I don't understand if I have to apply margins or padding neither if it is suppose to change/apply css in the row or in the container.
At this moment my website looks like this and my code is this one:
<div id="form">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-offset-7">
<form class="form-group">
<label for="testEmail">Email address</label>
<input type="email" class="form-control" id="testEmail" placeholder="Email">
</form>
</div>
</div>
</div>
</div>
Can you guys explain me how can I change my form position and how it is suppose to move things inside bootstrap?
Thanks
you can use offset like what you did. But here I prefer to create to Columns of divs inside row. please review this one: (see in full screen to check the layout)
form {
border-radius: 2px;
border: 1px solid green;
padding: 15px;
}
#form {
margin-top: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div id="form">
<div class="container">
<div class="row">
<div class="hidden-xs col-lg-3">test1</div>
<div class="col-xs-6 col-lg-3">test2</div>
<div class="col-xs-6 col-lg-4">
<form class="form-group">
<label for="testEmail">Email address</label>
<input type="email" class="form-control" id="testEmail" placeholder="Email">
</form>
</div>
<div class="hidden-xs col-lg-2">test3</div>
</div>
</div>
</div>
You can use bootstrap's offset class for positioning elements as you need. Here is the documentation for offset:
https://v4-alpha.getbootstrap.com/layout/grid/#example-offsetting-columns

Bootstrap - Align multiple select elements

So i am trying something very simple but can seem to figure it out. I have two select elements which I want to align horizontally with text in between. This is what I have: ( also on codepen )
<div class="row">
<div class="col-xs-2">
<select class="form-control input-sm">...</select>
</div>
<div class="col-xs-1"> vs </div>
<div class="col-xs-2">
<select class="form-control input-sm">...</select>
</div>
</div>
However I when I try to put a vs (versus) between them , if I use a <p> or <div> with no class defined the second select gets misaligned. If I wrap the vs in a div class=col-xs-1 the gap is too big and doesnt look nice. What would be the best way to get a vs between the 2 select while keeping the alignment and not having a huge space between 2 elements
I assume you are using Bootstrap looking at the CodePen. Bootstrap has a class for inline forms which you could use like this:
<div class="container">
<form action="" class="form-inline">
<div class="form-group">
<select class="form-control"><option>Select option</option></select>
</div>
<div class="form-group">vs</div>
<div class="form-group">
<select class="form-control"><option>Select option</option></select>
</div>
</form>
</div>
CodePen: http://codepen.io/anon/pen/ZOYjBm
I just tried with CSS
<div class="row">
<div class="col-xs-2 field">
<select class="form-control input-sm">...</select>
</div>
<div><span>vs</span></div>
<div class="col-xs-2 field">
<select class="form-control input-sm">...</select>
</div>
</div>
CSS:
div{
display:inline;
}
.field{
position:absolute;
}
span{
position:relative;
padding:0px;
}

Label of the control is jumping to the right side when resized

The generated HTML I have is this:
I put it in Bootply so you can just see and play with it easier, notice it has a small CSS section too:
http://www.bootply.com/NrxiDfZJdC
Problem is it is not "bootstrappy" enough! If you start making the window smaller the labels jump to the right side of the control.
What have I done that has caused this issue?
You have a couple of major problems here.
Right Alignment:
You have set this by adding .text-right on your labels. Obviously this was meant for the desktop view only. Take it off of your labels and use a min-width media query to set the alignment or override the alignment with max-width at small resolutions
Overflowing text boxes:
You didn't use a row. You should most always use a row because it corrects the padding wit negative left and right margins. You tried to fix this yourself by instead adding a class that removes the padding on the .col-sm-4. The padding is there for a reason and should not be removed. Even adding in the row and removing the .multi-row doesn't completely correct the issue, however. When you do that you run into the text inputs being too wide. That is because you added the 100% width to the inputs. This is not a bad thing per se, but it causes problems because you have used spans for your inner columns. spans are naturally collapsed in width. They don't fill their parents' container like divs do. Swap them for divs.
Weird "Ext" label:
This is because you added a margin-left: 85% to the label to simulate the right alignment that the others have. Just remove that margin and add text-right to this label like you have on all the other similar labels.
No padding:
After all that, you'll have no padding on smaller resolutions. Add a .container around your form.
In the end, you should have this: http://www.bootply.com/uiPpBytre3
Demo:
#import url(https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css);
.form-input{
width :100%;
}
#media(max-width: 768px) {
.form-group .text-right {
text-align: left;
}
}
<div class="container">
<form class="form-horizontal" role="form">
<br>
<div class="row form-group">
<div class="col-sm-offset-2 col-sm-1 text-right"><label class="control-label" for="Name">Name</label></div>
<div class="col-sm-4"><select class="form-control" id="nameadmin" name="nameadmin"><option>77881</option>
<option>77882</option>
<option>77883</option>
<option>77884</option>
<option>77885</option>
</select></div>
<div class="col-sm-4 col-sm-offset-1">
<div>
<input class="checkbox-inline" id="ShowEmailInFooter" name="ShowEmailInFooter" type="checkbox" value="true"><input name="ShowEmailInFooter" type="hidden" value="false">
<label class="control-label" for="Show_Email_in_Footer">Show Email in Footer</label>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-sm-offset-2 col-sm-1 text-right"><label class="control-label" for="Email">Email</label></div>
<div class="col-sm-4">
<input id="AdminEmail" name="AdminEmail" style="width:100%;padding-right:30px;" type="text" value="">
<span class="glyphicon glyphicon-envelope form-control-feedback" style="right: 10px; line-height: 27px; color: lightblue"></span>
</div>
<div class="col-sm-4 col-sm-offset-1">
<div>
<input class="checkbox-inline" id="ShowAdminPhone" name="ShowAdminPhone" type="checkbox" value="true"><input name="ShowAdminPhone" type="hidden" value="false">
<label class="control-label" for="Show_Admin_phone">Show Admin phone</label>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-sm-offset-2 col-sm-1 text-right"><label class="control-label" for="Phone">Phone</label></div>
<div class="col-sm-4">
<div class="row">
<div class="col-sm-5"><input class="form-input" id="AdminPhone" name="AdminPhone" type="text" value=""></div>
<div class="col-sm-2 text-right"><label class="control-label" for="Ext">Ext</label></div>
<div class="col-sm-5"><input class="form-input" id="AdminExt" name="AdminExt" type="text" value=""></div>
</div>
</div>
</div>
</form>
</div>
Add responsive text align class text-sm-right instead of text-right
#media (min-width: #screen-sm-min) {
.text-sm-right { text-align: right; }
}
bootply

How can I make an image span through multiple rows in Zurb-Foundation?

I'm trying to make a page via Foundation that lets users post articles, however, I'm having a problem. Here's what the page looks like: http://jsfiddle.net/60a2g5fn/ (be sure to expand the viewing window, or it will assume that you're on a mobile browser)
I'm required to post code after a JSFiddle link, so here's what the associated inputs/rows looks like.
<div class="row">
<div class="large-6 columns">
<label>Title
<input type="text" name="HK_NEWS_TITLE">
</label>
</div>
<div class="large-6 columns">
<label>Topstory Image</label>
<select name="HK_NEWS_IMAGE">
</select>
</div>
</div>
<div class="row">
<div class="large-3 columns">
<label>Slug
<input type="text" name="HK_NEWS_SLUG">
</label>
</div>
<div class="large-6 columns">
<label>Topstory Image Preview</label>
<img src="http://www.pattiknows.com/wp-content/uploads/2014/08/love-man-woman-silhouette-sun-sunset-sea-lake-beach-300x187.jpg">
</div>
</div>
The dropdown is where they can choose the images that uses PHP and Javascript to choose and append the image from a directory. Once they pick the image, it is appended under Topstory Image Preview, but it breaks the row and makes the slug have empty space below it.
Here's an image of the before, so you can compare. I want the image to be under Topstory Image Preview, but I don't want it to create unnecessary space below the Slug input bar.
Is there any way that I can do this? I've tried multiple things (aligning the image right out of the row, doesn't work. using css to make it the background-image, doesn't work). Any help would be appreciated.
Here's a way using which you can achieve what you're trying to do. For the mobile layout, I believe it appears fine as it is but for the desktop layout, you can set the position of the image to absolute using #media-queries so that there's no empty white space to the left side of the image.
Here's a demo (view as full page):
#media (min-width: 1025px) {
img#ts-preview {
position: absolute;
}
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/foundation/5.0.2/css/foundation.min.css" rel="stylesheet" />
<link href="http://cdnjs.cloudflare.com/ajax/libs/foundation/5.0.2/css/normalize.min.css" rel="stylesheet" />
<form method="POST" action="news">
<div class="row">
<div class="large-6 columns">
<label>Title
<input type="text" name="HK_NEWS_TITLE">
</label>
</div>
<div class="large-6 columns">
<label>Topstory Image</label>
<select name="HK_NEWS_IMAGE"></select>
</div>
</div>
<div class="row">
<div class="large-3 columns">
<label>Slug
<input type="text" name="HK_NEWS_SLUG">
</label>
</div>
<div class="large-6 columns">
<label>Topstory Image Preview</label>
<img id="ts-preview" style="padding-bottom:20px;" src="http://www.pattiknows.com/wp-content/uploads/2014/08/love-man-woman-silhouette-sun-sunset-sea-lake-beach-300x187.jpg">
</div>
</div>
<div class="row">
<div class="large-6 columns">
<label>Short Story
<input type="text" name="HK_NEWS_SHORT">
</label>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<label>News Content</label>
<textarea name="HK_NEWS_CONTENT"></textarea>
</div>
</div>
</form>