<div> height percentages not working - html

I've got a bunch of nested divs (I know, probably not ideal for this use, but it's just a temporary solution). I'm trying to make the child divs different heights by percentage, but it's not working; the divs are just expanded to the minimum height needed to fit the text.
<div class="funnel" style="width:100%; height:600px">
<div class="container-header">
<p class="header"> Funnel Times </p>
</div>
<div class="outer" style="width: 100%; height:600px">
<div class="innercontainer" style="width: 50%; height:600px; float: left">
<center>
<div class="signups-indie inner" style="width: 80%; height: 10%; background-color: #BFCCD5">
<p class="funnelTimesText"> Sign-ups: 8 hours / 2.1% </p>
</div>
<div class="installs-indie inner" style="width: 80%; height: 10%; background-color: #9EB2BE">
<p class="funnelTimesText"> Installs: 2 days / 12.9% </p>
</div>
<div class="action1-indie inner" style="width: 80%; height: 10%; background-color: #4A5A66">
<p class="funnelTimesText"> Action 1: 2.5 days / 16.1% </p>
</div>
<div class="action2-indie inner" style="width: 80%; height: 10%; background-color: #333F47">
<p class="funnelTimesText"> Action 2: 5.2 days / 17.4% </p>
</div>
<div class="conversions-indie inner" style="width: 80%; height: 10%; background-color: #AF212F">
<p class="funnelTimesText"> Conversions: 8 days / 51.5% </p>
</div>
</center>
</div>
<div class="innercontainer" style="width: 50%; height:600px; float: left">
<center>
<div class="signups-team inner" style="width: 80%; height: 1.8%; background-color: #BFCCD5">
<p class="funnelTimesText"> Sign-ups: 10 hours / 1.8% </p>
</div>
<div class="installs-team inner" style="width: 80%; height: 10.9%; background-color: #9EB2BE">
<p class="funnelTimesText"> Installs: 2.5 days / 10.9% </p>
</div>
<div class="action1-team inner" style="width: 80%; height: 8.7%; background-color: #4A5A66">
<p class="funnelTimesText"> Action 1: 2 days / 8.7% </p>
</div>
<div class="action2-team inner" style="width: 80%; height: 13.1%; background-color: #333F47">
<p class="funnelTimesText"> Action 2: 5.2 days / 17.4% </p>
</div>
<div class="conversions-team inner" style="width: 80%; height: 65%; background-color: #AF212F">
<p class="funnelTimesText"> Conversions: 8 days / 51.5% </p>
</div>
</center>
</div>
</div>
</div>
Here's a fiddle as well, where you can see it's not working:
http://jsfiddle.net/3w08gdmf/

For you to use % height, each nested element must explicitly specify its height. It takes its height from its immediate parent. If the parent does not have a height specified (either absolute or relative), it will not work.
The center element in your code does not have a height specified.
http://jsfiddle.net/3w08gdmf/2/
.innercontainer center{
height: 100%;
}

Out of curiosity, why are using strictly HTML and not CSS to style the markup? If you do it this way, whenever you adjust anything you will have to manually change EVERYTHING in HTML. Secondly, percentage is the percent of the parent <div> basically this means that if you have <div id="A"> and <div id="B">, which is nested in <div id="A"> then <div id="B"> will be a % of <div id="A">.
In short:
HTML
<div id="A">
<div id="B"></div> <!-- See how B is nested WITHIN A -->
</div>
CSS
#A {
height: 100px; // Set Height
}
#B {
height: 80%;
// This is 80% of the parent DIV "A" which is = to 80px because 80% of 100 is 80
}
Hope this clears things up.
Edited the HTML for clarification and some punctuation editing.

Related

Div with absolute width is smaller than specified [duplicate]

This question already has an answer here:
flex items ignoring width
(1 answer)
Closed 1 year ago.
I am trying to have a number of columns with exact widths, and their heights split evenly between some number of elements. For some reason, despite my indicating an exact 200px width on each column, they are instead getting a computed width of 162px somehow.
Chrome dev tools is showing some weird arrow thing indicating that it it was shrunk from it's intended size for some reason. I've even tried removing all of the content from the div's as possible so as to rule out some weird interaction with the size of children.
The HTML content for the relevant area is this:
div {
background: rgba(255, 0, 0, .1);
}
<div style="display: flex;">
<div style="width: 200px; margin-right: 100px;">
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
</div>
<div style="width: 200px; margin-right: 100px;">
<div style="height: 100px;"></div>
<div style="height: 100px;"></div>
<div style="height: 100px;"></div>
<div style="height: 100px;"></div>
</div>
<div style="width: 200px; margin-right: 100px;">
<div style="height: 200px;"></div>
<div style="height: 200px;"></div>
</div>
<div style="width: 200px; margin-right: 100px;">
<div style="height: 400px;"></div>
</div>
</div>
Including some dev-tools highlighting (showing the arrow thing I described) it is rendering like this (the "round" labels at the top are not in the HTML content above but are properly 200px + 100px margin):
I have never seen anything like this before, especially those arrow things from the dev tools. Is there something obvious I'm missing or something I should look for to diagnose this?
Setting display: flex turns the sizing of child elements over to the flex container. If you don't want the individual elements to resize, set flex-grow: 0, flex-shrink: 0, and flex-basis: 200px. You can do all three using the flex shorthand:
flex: 0 0 200px;
.container {
display: flex;
}
.container > * {
flex: 0 0 200px;
margin-right: 100px;
}
div {
background: #cccccccc;
}
<div class="container">
<div style="width: 200px; margin-right: 100px;">
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
<div style="height: 50px;"></div>
</div>
<div style="width: 200px; margin-right: 100px;">
<div style="height: 100px;"></div>
<div style="height: 100px;"></div>
<div style="height: 100px;"></div>
<div style="height: 100px;"></div>
</div>
<div style="width: 200px; margin-right: 100px;">
<div style="height: 200px;"></div>
<div style="height: 200px;"></div>
</div>
<div style="width: 200px; margin-right: 100px;">
<div style="height: 400px;"></div>
</div>
</div>
This is the default behaviour for Flexbox. If you add up all your widths, so 200 width + the 100 margin, you get 300 * 4 = 1200px. If your viewport is smaller than 1200px then the browser will try to calculate the best width it can to fit all your div along the main axis. thus you are getting 162 + 100 * 4 is just shy of 1200. Try resize your viewport or the browser screen to bigger than this and you should get the expected behaviour.
The arrow you are seeing is Chrome dev tools way of telling you your original width has been made smaller to fit all content.

Why my interface look differently in browser and google device toolbar?

my interface in Google chrome browser (Is normal, I set it like this)
But when I click the inspect and click google device toolbar, the interface look like:
.btn {
position: absolute;
top: 85%;
left: 50%;
transform: translate(-50%, -50%);
cursor: pointer;
}
.div_hover {
background-color: #F9F7F2;
}
<div style="width: 80%; margin: auto;">
<div class="div_hover" style="width: 473px; height: 200px; margin: auto;">
<p style="font-size: 18px;">Dear Customer</p>
<hr>
<p style="font-size: 11px">Welcome.......</p>
<hr>
<p style="font-size: 11px">bla..bla...</p>
<hr>
</div>
<div style="width: 49%; margin: auto; position: relative;">
<img src="https://www.rspcasa.org.au/wp-content/uploads/2019/01/Adopt-cat-mobile-banner-600x300-fit-constrain-q70-mobile_banner_image.jpg">
<form action="https://www.google.com/">
<input type="image" src="https://www.freepngimg.com/thumb/download_now_button/25399-6-download-now-button-thumb.png" class="btn" />
</form>
</div>
</div>
How can I make it both same?
Well, you are currently setting the div have the width of 49% but <img> doesn't have any width set. That is causing the image to be its original size. If you want to display the image in the same way for different screen width, you should do something like this:
<div style="width: 80%; margin: auto;">
<div class="div_hover" style="width: 473px; height: 200px; margin: auto;">
<p style="font-size: 18px;">Dear Customer</p>
<hr>
<p style="font-size: 11px">Welcome.......</p>
<hr>
<p style="font-size: 11px">bla..bla...</p>
<hr>
</div>
<div style="width: 473px; margin: auto; position: relative;">
<img width="100%" src="https://www.rspcasa.org.au/wp-content/uploads/2019/01/Adopt-cat-mobile-banner-600x300-fit-constrain-q70-mobile_banner_image.jpg">
<form action="https://www.google.com/">
<input type="image" src="https://www.freepngimg.com/thumb/download_now_button/25399-6-download-now-button-thumb.png" class="btn" />
</form>
</div>
</div>
As you see, don't give the custom width to the second child div. If you have to give the width as 49% for second div, then give the width for <img> as well.
https://jsfiddle.net/2epL85r1/

Centering icons on website

I have a problem.
I would like to center three icons on a website like so:
http://prntscr.com/cte4kt
Including the text under it.
I have searched on google, but I had no good results.
If somebody could show a simple example that would be really greatfull.
this is what I tried:
<div class="testDiv">
<img style="width: 100px; height: 100px;" src="https://s21.postimg.org/jc5m4w0av/search.png">
<h3>Insert text</h3>
<h4>This is an actual test<br>
I really mean it lol.
</h4>
<img style="width: 100px; height: 100px;" src="https://s21.postimg.org/jc5m4w0av/search.png">
<h3>Insert text</h3>
<h4>This is an actual test<br>
I really mean it lol.
</h4>
<img style="width: 100px; height: 100px;" src="https://s21.postimg.org/jc5m4w0av/search.png">
<h3>Insert text</h3>
<h4>This is an actual test<br>
I really mean it lol.
</h4>
CSS:
http://pastebin.com/v0cc1cXg
Thankyou.
I think you already know some basic HTML/CSS stuff so I'd recommend you use some of popular front-end frameworks like Bootstrap or Zurb Foundation. It's almost copy/paste only thing.
You can use something like bootstrap or primercss which give you classes to add rows and columns to layout your content.
You could also create your own like the example I did here
<div class="container">
<div class="row">
<div class="col3 center">
<div class="inner-container">
<i>icon</i>
<div>text</div>
</div>
</div>
<div class="col3">
<div class="inner-container">
<i>icon</i>
<div>text</div>
</div>
</div>
<div class="col3">
<div class="inner-container">
<i>icon</i>
<div>text</div>
</div>
</div>
</div>
</div>
.container {
position: relative;
width: auto;
height: 200px;
}
.row {
width: 100%;
height: 100%;
}
.col3 {
float: left;
width: 33.3%;
height: 100%;
background: grey;
}
.inner-container {
position: relative;
top: 30%;
text-align: center;
}
Basically you need to create some type of layout container(width:100%) with three columns split by thirds(width:33.3%). Then inside each of those columns you position the contents with (text-align:center) to horizontally center align the content and vertically align it via something like top:30% or if you could also do an inline-block with vertical-align: middle.

css and html - why does a div which is float-left get placed on the line below?

I have HTML like this:
<div style="float: left; font-family: arial; padding-top: 40px; width: 655px; ">
<div style="float: left;">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" style="border: none;" />
</div>
<div style="float: left; ">
<p>
<h1>mobile business plan, <br />
business ideas, fundraising<br /> and marketing apps
</h1> <!-- font-size: 200%; -->
</p>
</div>
<div style="clear:both;"></div>
And it looks like this. Here is a test page:
http://problemio.com/index_test.php
The blue B is supposed to be on the same line with the text. But possibly because the original image size is very big, it is getting screwed up in size.
Here is the css for the img:
img#above_fold_img
{
width: 30%;
height: 30%;
}
Would anyone know how to make the image and text appear on the same line?
Thanks!
You need to specify a width for both of the child <div>s. According to Chrome DevTools, the first <div> (with the child image) is 512px wide. width: 30%; on img#above_fold_img uses 30% of its parent div.Example:
<div style="float: left; width: 256px; height: 256px; margin: 0">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" style="border: none; width: 256px; height: 256px" />
</div>
<div style="float: left; width: 393px; margin: 0; margin-left: 5px">
<p>
<h1>mobile business plan, <br />
business ideas, fundraising<br /> and marketing apps
</h1> <!-- font-size: 200%; -->
</p>
</div>
I kept all styles inline in my example, but using CSS is better. Also, the 'b' image is 512x512px. If you can shrink it, you will reduce load times.
I think just giving an answer helps but op wanted to know why as well..
You should declare a width on the image that contains the #above_fold_img so that the div takes on the same width that way you can do this
<div style="float: left; font-family: arial; padding-top: 40px; width: 655px;">
<div style="float: left;margin-right:20px">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" width="154">
</div>
<div style="float: left;">
<p></p>
<h1>mobile business plan, <br>
business ideas, fundraising<br> and marketing apps
</h1> <!-- font-size: 200%; -->
<p></p>
</div>
<div style="clear:both;"></div>
</div>
Also you should try not to use <p></p> as spaces but use <br/> to do that
Change your div to have a width of 30% and the image to have a width of 100% or 90% for astetic reasons, so:
<div style="float: left; font-family: arial; padding-top: 40px; width: 655px;">
<div style="float: left; width: 30%;">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" style="border: none;" />
</div>
and CSS:
img#above_fold_img
{
width: 100%;
height: 100%;
}

HTML to split a section into two columns

I am trying to split the page into two sections. One left area and right will be the content page. I have the following html but looks like it is not working. Any ideas, what I am not doing right?
<div id="wuiMainArea">
<div id="wuiMainContent">
<div id="wuiLeftArea">
<div id="wuiLefthandNavRoot">
<h2 class="wui-hidden">Section Navigation</h2>
<h3 class="wui-navigation-title"><p>Applications</p><p> </p></h3>
<div id="tree" style="float: left; width: auto; background-color: #f2f4f5;"> </div>
</div>
</div>
<div id="wuiInpageNav">
<div class="wui-inpage-container" id="in_100">
<p>This is the div I will be using for charts </p>
</div>
</div>
</div>
</div>
Like this
<div id="wuiMainArea" style="border: 1px solid;">
<div id="wuiMainContent" style="border: 1px solid;">
<div id="wuiLeftArea" style="border: 1px solid;float: left;">
<div id="wuiLefthandNavRoot">
<h2 class="wui-hidden">Section Navigation</h2>
<h3 class="wui-navigation-title"><p>Applications</p><p> </p></h3>
<div id="tree" style="float: left; width: auto; background-color: #f2f4f5;"> </div>
</div>
</div>
<div id="wuiInpageNav" style="border: 1px solid; float: left;">
<div class="wui-inpage-container" id="in_100">
<p>This is the div I will be using for charts </p>
</div>
</div>
<div style="clear: both;"></div>
</div>
</div>
#wuiMainArea, #wuiMainContent{
margin: 0 auto;
width: 960px;
}
#wuiLeftArea, #wuiInpageNav{
/* use half of the main content div's width */
/* -2 because of 1px-border on both sides */
width: 478px;
display: inline-block;
float: left;
}
It'll be better to use CSS styling HTML.
Define the widths to fit your needs. Also I recommend using classes instead of ids when appling same styles to multiple elements.