background color not filling entire div - html

I am having a problem in filling the entire center content (div) with a background color.
I want to fill element with id body-content with the blue color but its not actually stretching to full height.
HTML code
<div id="body-content">
<iframe id="promo-video" width="40%" height="315" src="" frameborder="0" allowfullscreen style="margin-bottom: 20px;"></iframe>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
var y_pos = $('#search-panel').position().top;
$('#promo-video').css('top',y_pos);
});
function sho(a){
if (a=='1'){
document.getElementById('criteria-1').style.display = "block";
document.getElementById('criteria-2').style.display = "none";
document.getElementById('criteria-3').style.display = "none";
}
else if (a=='2'){
document.getElementById('criteria-1').style.display = "none";
document.getElementById('criteria-2').style.display = "block";
document.getElementById('criteria-3').style.display = "none";
}
else if (a=='3'){
document.getElementById('criteria-1').style.display = "none";
document.getElementById('criteria-2').style.display = "none";
document.getElementById('criteria-3').style.display = "block";
}
}
</script>
<div id="search-boxes">
<div id="search-panel">
<form id="search-form" name="search-form" onsubmit="return false;">
<fieldset style="margin-bottom:8px;">
<legend><i>Find By</i></legend>
<input type="radio" name="sp" onclick="sho(1);" checked/>A
<input type="radio" name="sp" onclick="sho(2);"/>B
<input type="radio" name="sp" onclick="sho(3);"/>C
</fieldset>
<p>
<select name="spe" id="criteria-1">
<option value="g">G</option>
<option value="c">C</option>
<option value="ge">Ge</option>
</select>
<input type="text" style="width:97%;vertical-align:center;display:none;height:24px;padding-left:8px;" placeholder="Or find a.." id="criteria-2"/>
<input type="text" style="width:97%;vertical-align:center;display:none;height:24px;padding-left:8px;" placeholder="Or find b.." id="criteria-3"/>
</p>
<select name="city" style="width:49%;">
<option value="any-city">In City</option>
<option value="mumbai">Mumbai</option>
<option value="nyc">New York</option>
</select>
<select name="locality" style="width:49%;">
<option value="anywhere">Near Area</option>
<option value="vasant-vihar">Vasant Vihar</option>
<option value="andheri">Andheri</option>
</select>
<br><br>
<input type="submit" class="button_g" name="submit-search" value="Search for A">
</form>
</div>
</div><!-- End of Search boxes -->
</div><!-- End of body content -->
CSS code
#search-boxes{
margin: 40px;
display: inline-block;
float: right;
margin-right: 8%;
clear: both;
width: 450px;
}
#search-panel{
border: 6px solid #c6e7f8;
}
#search-panel{
text-align: center;
padding: 30px;
padding-top: 20px;
padding-bottom: 20px;
width: 400px;
background-color: #ffffff;
font-family: "Segoe UI Semibold", sans-serif;
}
#search-boxes select{
width: 100%;
height: 30px;
}
#promo-video{
position: absolute;
margin-left: 8%;
border: 6px solid #d9d9d9;
}
#body-content{
background-color: #e9f6fc;
/* background: linear-gradient(to bottom, #e9f6fc 50%, white);
background: -webkit-linear-gradient( to bottom, #e9f6fc 50%, white);
background: -moz-linear-gradient( to bottom, #e9f6fc 50%, white);
background: -o-linear-gradient( to bottom, #e9f6fc 50%, white);
*/ margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
padding: 40px;
vertical-align: middle;
}
I tried searching for the problem and found a solution, that clear should be used to make floating items behave normally. But that too doesn't work. What am I missing?
Another problem was with the linear gradient, I wanted blue to extend till 50% height, but that fills upto 90%, when the blue color fills the entire body-content.

Try this:
#body-content {overflow: hidden;}
That forces the body-content div to wrap around its floated contents. There are other methods for enclosing floats, but this tends to be the easiest.
Note, however, that because your iframe is set to position: absolute;, nothing will clear that except a height on the container, which is rarely a good idea. It would be better to float that too.

First off, that code doesn't generate anything like that screenshot for me (frame is on top of the search boxes and the blue background goes further down).
But replacing the position:absolute; in the #promo-video style to float: left; and adding another float:left to #search-boxes generated something similar to what you have.
In that situation, correcting your issue is simply a matter of adding <div style="clear:both;"></div> below the closing tag for search-boxes>
i.e.
Use floats to get the layout you want.

Related

Text and Box Alignment

I'm new at this so please bear with me. I'm trying to align the text and their input fields - just like this example - by using the label class in the CSS file (please check below) but for some reason it is not working and I can't figure out what I'm doing wrong. Could someone please help me out?
Here's my code:
/* Set main division background color, color, width, padding, border-radius, box-alignment */
.mainD {
background-color: white;
color: black;
width: 500px;
padding: 20px;
border-radius: 25px;
box-align: center;
}
/* Set fieldset in the center with no border */
fieldset {
border: none;
text-align: center;
}
/* Aligns texts and their fields */
label {
display: inline-block;
text-align: right;
}
<div class="mainD">
<h1>Interest Calculator</h1>
<fieldset>
<!---Input box for the amount--->
<label for="principal">Amount
<input type="number" id="principal"></label>
<br><br>
<!---Slider for the interest rate--->
<label for="rate" onchange="updateRate()">Interest Rate
<input type="range" id="rate" min="1" max="10" step="0.25" value="5.25">
<span id="rate_val">5.25</span>%</label>
<br><br>
<!---Dropdown box for the years--->
<label> No. of Years
<select id="years">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></select></label> (additional code..)
</fieldset>
</div>
You can make use of flexbox to align the items vertically and horizontally. Then use justify-content to space them evenly as well to achieve the effect you want in the picture. See the snippet below:
/* Set main division background color, color, width, padding, border-radius, box-alignment */
.mainD {
background-color: white;
color: black;
width: 500px;
padding: 20px;
border-radius: 25px;
box-align: center;
}
/* Set fieldset in the center with no border */
fieldset {
border: none;
text-align: center;
}
/* Aligns texts and their fields */
label {
display: flex;
align-items: center;
justify-content: space-between;
}
.input {
display: flex;
width: 300px;
justify-content: flex-start;
align-items: center;
}
<div class="mainD">
<h1>Interest Calculator</h1>
<fieldset>
<!---Input box for the amount--->
<label for="principal">Amount
<div class="input"><input type="number" id="principal"></div>
</label>
<br><br>
<!---Slider for the interest rate--->
<label for="rate" onchange="updateRate()">
Interest Rate
<div class="input">
<input type="range" id="rate" min="1" max="10" step="0.25" value="5.25">
<span id="rate_val">5.25</span>%
</div>
</label>
<br><br>
<!---Dropdown box for the years--->
<label> No. of Years
<div class="input">
<select id="years">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</label>
</fieldset>
</div>
i center everything just to prove it actually center i added border feel free to remove it after
/* Set main division background color, color, width, padding, border-radius, box-alignment */
.mainD {
background-color: white;
color: black;
width: 500px;
padding: 20px;
border-radius: 25px;
box-align: center;
}
/* Set fieldset in the center with no border */
fieldset, h1 {
border: 2px solid #ff8197;
text-align: left;
margin: auto auto auto auto;
width: 60%;
}
/* Aligns texts and their fields */
label {
display: inline-block;
text-align: right;
}
<div class="mainD">
<h1>Interest Calculator</h1>
<fieldset>
<!---Input box for the amount--->
<label for="principal">Amount
<input type="number" id="principal"></label>
<br><br>
<!---Slider for the interest rate--->
<label for="rate" onchange="updateRate()">Interest Rate
<input type="range" id="rate" min="1" max="10" step="0.25" value="5.25">
<span id="rate_val">5.25</span>%</label>
<br><br>
<!---Dropdown box for the years--->
<label> No. of Years
<select id="years">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></select></label> (additional code..)
</fieldset>
</div>

Form Inputs Not Aligned

So I've come across an issue with my input box going out of bounds and I have no idea how to fix it. My select box and input box have the exact same CSS code. I've tried using max-width and vertical-align but both didn't work. Also tried using display: inline-block.
The difference between the 2 are exactly 4px even though both are set to 80% width
HTML
<form class="container_filterSelection">
<label>Product Category</label>
<select class="categorySelect">
<option value="0"></option>
<option value="1">Drills</option>
<option value="2">More Drills</option>
<option value="3">Give me them drills</option>
</select><br>
<label>Address</label>
<input type="text" class="locationSelect">
<button class="submit">Submit</button>
</form>
</html>
CSS
form {
width: 75%;
margin: auto;
background: white;
}
/* Category Dropdown */
.categorySelect {
width: 80%;
margin: 16px 10%;
padding: 16px 0;
}
/* Location Input */
.locationSelect {
width: 80%;
margin: 0 10% 16px 10%;
padding: 16px 0;
}
Try like this:
form {
width: 75%;
margin: auto;
background: white;
}
/* Category Dropdown */
.categorySelect {
width: 80%;
margin: 16px 10% 16px 10%;
padding: 16px 0;
}
/* Location Input */
.locationSelect {
width: 80%;
margin: 0 10% 16px 10%;
padding: 16px 0;
box-sizing: border-box;
}
<form class="container_filterSelection">
<label>Product Category</label>
<select class="categorySelect">
<option value="0"></option>
<option value="1">Drills</option>
<option value="2">More Drills</option>
<option value="3">Give me them drills</option>
</select><br>
<label>Address</label>
<input type="text" class="locationSelect">
<button class="submit">Submit</button>
</form>
Adding box-sizing: border-box; to .locationSelect appears to fix it. The browser's user agent stylesheet appears to be adding this property to select elements but not to input, so to make them look the same, you need to correct for that.

html css sticky, etc

For the code below, I have two problems:
The background image cereal.jpeg was working, now for some reason, it's disappeared and I can't figure why. Because it used to work, I know the file name and location are correct.
My controls refuse to remain sticky!
div.container {
border-style: solid;
border-width: thin;
border-color: grey;
box-shadow: 10px 15px 8px black;
height: 1500px;
width: 700px;
}
div.container::before {
background-image: url("cereal.jpeg");
background-repeat: repeat;
opacity: 0.05;
}
div.controls {
float: left;
width: 140px;
border: 1px solid lightgrey;
position: -webkit-sticky; // Safari
position: sticky;
top: 0;
}
div.thePlots {
float: left;
border: 1px solid lightgrey;
width: 400px;
height: 1400px;
}
<div id=container class=container>
<div class=controls id=controls>
<label id="brand">Brand:</label>
<br>
<select size=7 id="brandOptions" multiple>
<option value=0 selected>All</option>
<option value=1>Kellog</option>
<option value=2>Post</option>
<option value=3>Quaker</option>
<option value=4>General Mills</option>
<option value=5>Tree House</option>
<option value=6>CPW</option>
</select>
<br><br><br>
<label id="barsLabel">Error Bars:</label>
<input id=barsPresent type=checkbox value="Error Bars" checked>
<br><br><br>
<label id="label">Elasticity<br>Means:</label>
<br>
<select id="plotY">
<option value="efm" selected="selected">efm</option>
<option value="enm">enm</option>
</select>
<br><br><br>
</div>
<div class=thePlots id=thePlots>
The Plots<br>
<div class="tooltip" id="tooltip"></div>
<div id="plotshare" class="plotshare"></div>
<div id="plotprice" class="plotprice"></div>
<div id="plotsugar" class="plotsugar"></div>
<div id="plotmushy" class="plotmushy"></div>
</div>
</div>
opacity is too low.
Remove float:left;
Your div.controls element is sticking just fine, but it's sticking to the top of your container element. If you put it outside out your container element you will see it stick to the top of the page as desired.
Also, you will need to remove the // safari from your css. The correct syntax for commenting in css is /* comment */
For the background issue, there is no content for your background to display behind. You will need to add something to the before in order for the background to show.
Check this working fiddle which solves both problems
: https://jsfiddle.net/c5vrhf7t/1/

html: have form adjust width to contents?

please have a look at this simple jsfiddle:
--> JSFiddle
html:
<form>
<p>
<input id="I1" value="above left" size="40" />
<input id="I2" value="above right" size="10" />
</p>
<p>
<input id="I3" value="below right" size="10" />
<input id="I4" value="below left" size="20" />
</p>
</form>
css:
form {
overflow: hidden;
border: 3px solid red;
padding: 5px;
}
#I1,
#I2 {
background-color: orange;
float: left;
}
#I3,
#I4 {
background-color: yellow;
float: right;
}
what I want is the red border (= form width) auto-adjust to the width of the two top inputs (+ padding, of course).
I would then expect, that the second line inputs appear right-aligned below the first, so "above right" would be exactly above "below right", and "below left" beeing right left of it, like so:
11111111111111111111 2222222
4444444 3333333
Can this be done without tables?
Thx, Armin.
It most certainly can be done without tables :). You could set, for form:
form {
display: inline-block;
padding: ...;
}
This will prevent the form from expanding to the entire width of the screen. It will be as wide as the elements inside it, or, if you manually define its width, as wide as specified.
If you would like no elements to appear on either side of the form within the form's containing element, you can wrap it in a div or other block level element:
<div>
<form>
<!-- Rest of content -->
</form>
</div>
In order to remove the spacing above and below each p, as per your comment, remove their margin-top and margin-bottom, as they have a margin by default:
p {
margin-bottom: 0;
margin-top: 0;
}
I've organized and cleaned-up your code. The way to make the div adjust to its content is by using display: inline-block. I've also fixed the padding issue so now the entire content is padded equally to 5px.
JsFiddle
HTML:
<form>
<p>
<input id="I1" value="above left" size="40" />
<input id="I2" value="above right" size="10" />
</p>
<p>
<input id="I3" value="below right" size="10" />
<input id="I4" value="below left" size="20" />
</p>
</form>
CSS:
.border {
border: 3px solid red;
padding: 5px;
display: inline-block;
}
#I1 {
background-color: orange;
}
#I2 {
background-color: yellow;
}
.top-block,
.bottom-block {
width: 100%;
}
I have update this answer. Probably this is what you need, but there are other options but I don't think is the scope of this question.
CSS Code:
form {
overflow: hidden;
border: 3px solid red;
padding: 5px;
width: 400px; // limites de form size
}
#I1,
#I2 {
position: absolute;
background-color: orange;
}
#I3,
#I4 {
position: absolute;
background-color: yellow;
}
p {
display: block;
border: 1px solid blue;
position: relative;
height: 2em;
}
#I1,
#I4 {
right: 25%;
}
#I2,
#I3 {
right: 0;
}
See here the full code: https://jsfiddle.net/uv8yrrav/18/
hope this helps!

How to replace fixed values in responsible form css

Responsible form is created using code below.
If window is resized, it resizes itself automatically, captions and input elements stay aligned.
It contains fixed values 210px, 75px, 100px, 120 px is css below.
Is it reasonable and if yes, how to remove/replace those fixed values with something other
like percents or em's ?
input, select elements and jquery-ui autocomplete with dropdown button are used.
<form class='ui-widget-content form-document'>
<div class='form-field'>
<label class='form-label' for='nimi'>Customer name</label>
<span class='form-fullwidth'>
<input class='ui-widget-content ui-corner-all form-autocomplete' name='nimi' value='Karu Org AS' ></input>
<button type='button' class='form-combobutton' tabindex=-1 ></button>
</span>
</div>
<div class='form-field'>
<label class='form-label' for='Number'>Number</label>
<input class='ui-widget-content ui-corner-all form-fullwidth' name='Number' />
</div>
<div class='form-field'>
<label class='form-label' for='payterm'>Pay term</label>
<span id='span_Maksetin1_tingimus' class='form-fullwidth'>
<select class='ui-widget-content ui-corner-all form-fullwidth' name='payterm'>
<option value='' selected='selected'></option>
<option value='0'>0 days</option>
</select>
</span>
</div>
... lot of similar form-field divs
</form>
css:
.form-document
{
padding: 0.5%;
}
.form-field
{
display: inline-block;
margin: 2px;
width: 210px; /* label width + input field width */
}
.form-label
{
padding-left: 5px;
padding-right: 5px;
font-family: Arial, Helvetica, sans-serif;
font-size: smaller;
display: inline-block;
text-align: right;
width: 75px; /* determine by max caption width */
}
.form-fullwidth
{
width: 120px; /* 210-5-75 */
}
.form-autocomplete
{
width: 100px; /* 210-5-75-combobutton width*/
}
.form-combobutton
{
height: 1.09em;
margin: 0 0 0px;
padding: 0;
margin-left: -6px;
vertical-align: middle;
width: 1em !important;
}
Looks ok to me though I personally use ems in most cases.
You could also consider using a preprocessor like LESS if you want to use variables to avoid repetition. You can get LESS or SASS via nuget and there are zillions of tutorials out there.