Having trouble creating a color palette - html

For my project, I'm creating an app that allows users to paint pictures.
I managed to create the canvas and paint brush, and already know how to work the Javascript and Jquery.
The only problem I'm having is with creating the color palette.
HTML
<div id = "colors">
<div style="background: #990000;"></div>
<div style="background: #CC0000;"></div>
<div style="background: #CC3300;"></div>
<div style="background: #FFCC00;"></div>
<div style="background: #FFFF00;"></div>
<div style="background: #CCFF00;"></div>
<div style="background: #66FF00;"></div>
<div style="background: #003300;"></div>
<div style="background: #33FFCC;"></div>
<div style="background: #3300CC;"></div>
<div style="background: #660033;"></div>
<div style="background: #660066;"></div>
<div style="background: #000000;"></div>
<div style="background: #ffffff;"></div>
</div>
application.css
#colors {
width: 180px;
height: 30px;
}
I created a fiddle
http://jsfiddle.net/fqfbprd7/1/
If I add some text to the div, like I did in the fiddle, I see the colors rendered, but they are all on their separate line. Similar to paint, this should be a color selection box, where there are 7 colors per line. Just the colors though, and no text.
I even set the width and height attributes for my colors div, to render a color box.

Here the updated fiddle:
http://jsfiddle.net/fqfbprd7/2/
#colors div {
width: 25px;
height: 30px;
float: left;
}

Target the DIV's inside #colors and use position property value of inline-block to get them to display next to eahch other.
#colors div {
display: inline-block;
}
#colors {
width: 180px;
height: 30px;
}
#colors div {
display: inline-block;
}
<div id ="colors">
<div style="background: #990000">A</div>
<div style="background: #CC0000">B</div>
<div style="background: #CC3300">C</div>
<div style="background: #FFCC00">D</div>
<div style="background: #FFFF00">E</div>
<div style="background: #CCFF00">F</div>
<div style="background: #66FF00">G</div>
<div style="background: #003300">H</div>
<div style="background: #33FFCC">I</div>
<div style="background: #3300CC">J</div>
<div style="background: #660033">K</div>
<div style="background: #660066">L</div>
<div style="background: #000000">M</div>
<div style="background: #ffffff">N</div>
</div>

Related

Precise line height in pre

I have a <pre> element and I need the line height to be exactly 15px (so it lines up with something else).
I've played around with font-size and line-height but they seem to interact in non-obvious ways. Can someone explain how they work and if it is possible to force exactly 15px line heights?
Ok it turns out that #ÁlvaroGonzález's suggestion does work in a simple test case I made. For some reason it is really giving me a line height of 16px in my actual file, so something else weird must be going on.
Shown here for 10px because coincidentally the default line height in Chrome seems to be exactly 15px.
.ruler {
width: 50px;
height: 10px;
}
pre {
margin: 0;
line-height: 1;
font-size: 10px;
}
<div style="display: flex; align-items: flex-start;">
<div>
<div class="ruler" style="background: red;"></div>
<div class="ruler" style="background: green;"></div>
<div class="ruler" style="background: blue;"></div>
<div class="ruler" style="background: red;"></div>
<div class="ruler" style="background: green;"></div>
<div class="ruler" style="background: blue;"></div>
<div class="ruler" style="background: red;"></div>
<div class="ruler" style="background: green;"></div>
<div class="ruler" style="background: blue;"></div>
</div>
<pre>
Why would
somebody mark
this question
as off-topic?
Whoever did
this you are
what is
wrong with
StackOverflow.
</pre>
</div>

Set Div to move below another Div as screen size shrinks

I have two Div's, the left one is a sidebar of sorts (but it does not extend the full height of the screen), and the right one is the content Div that should occupy as much of the screen as possible and collapse/move underneath the sidebar as the screen shrinks. Right now I have the sidebar set up how I expect it to be, but the Content Div begins to overlap the Sidebar as the page shrinks and does not move below.
I have tried different position: parameters (fixed,absolute,relative) different width/min-width values, as well as different values for float. I have everything in html styling right now for simplicity. The css files that were being used seemed to be interfering with functionality so I attempted to override them via styling directly within the HTML.
<body style="padding-top: 5px; padding-bottom: 20px; padding-left: 15px; padding-right: 15px; min-height: 80%; min-height: 50vh;">
<h3 class="text-center"> Title </h3>
<div class="SideContainer" style="background-color: green;position:absolute;left:0; top:80; bottom: 400;width: 20vw;min-width: 200px;max-width: 300px;padding: 3px;">
<div style="background-color: red;width: 100%;">Keys</div>
<div style="background-color: blue;">Error Box</div>
<div style="background-color: grey;border: none;width: 100%;border-radius: 3px;">File Menu Button</div>
<p> Enter Display Name</p>
<div style="background-color: yellow;">Name Box</div>
<p> Users Viewing </p>
<div style="background-color: orange;">User box</div></div>
<div class="ContentContainer" style="background-color: gold;position: relative;float: left;left:20vw; top: 25;width:80%;min-width: 400px;margin-right: 3px;padding: 8px;">
<div style="background-color: purple;border: 1px solid;border-radius: 4px;line-height: 2.6;padding: 3px;margin-bottom: 6px;">Doc Title</div>
<div style="background-color: maroon;min-height: 150px;border: 1px solid;border-radius: 4px;padding: 3px;">Doc Content</div></div><body>
Content div should shrink, and at a certain point, move below the Sidebar div.
<body style="padding-top: 5px; padding-bottom: 20px; padding-left: 15px; padding-right: 15px; min-height: 80%; min-height: 50vh;">
<h3 class="text-center"> Title </h3>
<div style="display: flex; flex-flow: row wrap;">
<div class="SideContainer" style="background-color: green;left:0; top:80; bottom: 400;width: 20vw;flex-grow: 1;padding: 3px;min-width: 200px;max-width: 300px">
<div style="background-color: red;width: 100%;">Keys</div>
<div style="background-color: blue;">Error Box</div>
<div style="background-color: grey;border: none;width: 100%;border-radius: 3px;">File Menu Button</div>
<p> Enter Display Name</p>
<div style="background-color: yellow;">Name Box</div>
<p> Users Viewing </p>
<div style="background-color: orange;">User box</div>
</div>
<div class="ContentContainer" style="background-color: gold;float: left;left:20vw; flex-grow: 4;top: 25;margin-right: 3px;padding: 8px;min-width: 200px;">
<div style="background-color: purple;border: 1px solid;border-radius: 4px;line-height: 2.6;padding: 3px;margin-bottom: 6px;">Doc Title</div>
<div style="background-color: maroon;min-height: 150px;border: 1px solid;border-radius: 4px;padding: 3px;">Doc Content</div>
</div>
</div>
<body>
I got your code working using Display:flex, it's a good idea to also separate your code into html and css and use classes references in the HTML. There is a lot of benefits to this including easier to maintain, cleaner, and also makes it easy to follow etc.

Bootstrap grid, middle content stuck to top of page

I'm trying to build a CMS style html template so that a user can drop content into a template.
I'm using bootstrap grid to create the template but I'm having some issues.
Basically I'm shooting for a main body container, which has a sticky top, a sticky bottom, and then the main middle section filling the rest of the space which houses other areas.
IN this case, the middle section has 2 areas at 50%, one to the left and one to the right.
The problem is my middle section is currently stuck to the very top of the page along with the top section but I need it to fill up the middle the way that I've structured it but I"m not sure how I should change positioning.
Here's the current block:
<head>
<style type="text/css">
html,body{
height:100%;
}
</style>
</head>
<div class="container-fluid" style="text-align: center; height:100%; border: 1px solid red;">
<div class="row top">
<div class="col-lg-12" style=" background-color: #A0A0A0;position: absolute; height: 15%;">
<p style="color: white">Top</p>
</div>
</div>
<div class="row middle">
<div class="col-lg-6" style=" background-color: #A0A0A0">
<p style="color: white">Left</p>
</div>
<div class="col-lg-6" style=" background-color: #A0A0A0;">
<p style="color: white">Right</p>
</div>
</div>
<div class="row bottom">
<div class="col-lg-12" style=" background-color: #A0A0A0; bottom:0; position: absolute; height: 10%;">
<p style="color: white">Bottom</p>
</div>
</div>
</div>
You're making it hard on yourself. Here are a few things you could change to get the desired result and also make it easier for yourself to control and contain your CSS. I've added .my-container class to .container-fluid to keep the changes from applying to other pages, but that's totally optional:
html,
body {
height: 100%;
}
.my-container {
display: flex;
flex-direction: column;
border: 1px solid red;
height: 100%;
}
.my-container>.top [class^="col-"],
.my-container>.bottom [class^="col-"] {
background-color: #A0A0A0;
color: white;
text-align: center;
}
.my-container>.middle {
/* make middle section push header and footer at the margins of available space */
flex-grow: 1;
}
.my-container>.middle>* {
border: 1px solid red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid my-container">
<div class="row top">
<div class="col-lg-12">
<p>Top</p>
</div>
</div>
<div class="row middle">
<div class="col-lg-6">
<p>Left</p>
</div>
<div class="col-lg-6">
<p>Right</p>
</div>
</div>
<div class="row bottom">
<div class="col-lg-12">
<p>Bottom</p>
</div>
</div>
</div>
I also:
removed inline styles
removed position:absolute (otherwise you'll need to keep header and footer height in sync with <body> or .container-fluid top and bottom paddings which allow all your content to be visible)
used flex to position the header and footer
removed % height which is considered very bad UI (consider what happens on mobile when you rotate the screen - how it affects an element with height:15%).

Bootstrap layout with mystery pulls and pushes

I trying to make uncommon layout with bootstrap, but pulls and pushes works in wierd way. Look at it:
http://jsfiddle.net/tfgdveop/1/
<div class="container" style="background: white">
<div class="row">
<div class="col-xs-3" style="background: red; height: 300px;">catalog</div>
<div class="col-xs-9" style="background: blue; height: 50px;">bNNER</div>
<div class="col-xs-3 col-xs-push-6" style="background: yellow; height: 500px;">News</div>
<div class="col-xs-6 col-xs-pull-3" style="background: green; height: 280px;">Catalog</div>
<div class="col-xs-6 col-xs-pull-6" style="background: pink; height: 100px;">Promo</div>
</div>
</div>
I need pink promo block 9 cols width, but if i made it wider 6, it fall under news block.
I changed order a bit and Yellow News to float to right. I also removed all unnnecessary pulls and pushes. Here is the result:
http://jsfiddle.net/tfgdveop/3/
<div class="container" style="background: white">
<div class="row">
<div class="col-xs-3" style="background: red; height: 300px;">catalog</div>
<div class="col-xs-9"style="background: blue; height: 50px;">bNNER</div>
<div class="col-xs-6"style="background: green; height: 280px;">Catalog</div>
<div class="col-xs-3 pull-right"style="background: yellow; height: 500px;">News</div>
<div class="col-xs-9" style="background: pink; height: 100px;">Promo</div>
</div>
</div>
Is this what you are looking for?

Css fix - chart items in a div improper alignment

Code here - http://jsfiddle.net/Cd2Ek/
html -
<div id="main-div" style="height: 250px; margin-left: 10px;">
<div class="sub-div">
<div class="">0%</div> <div class="d1" val="0" style="height: 0%"></div>
<div class=""><small>L1</small></div>
</div>
<div class="sub-div">
<div class="">0%</div> <div class="d1" val="0" style="height: 0%"></div>
<div class=""><small></small></div>
</div>
<div class="sub-div">
<div class="">33%</div> <div class="d1" val="1" style="height: 33%"></div>
<div class=""><small>L3</small></div>
</div>
<div class="sub-div">
<div class="">0%</div> <div class="d1" val="0" style="height: 0%"></div>
<div class=""><small></small></div>
</div>
<div class="sub-div">
<div>67%</div> <div class="d1" val="2" style="height: 67%"></div>
<div class=""><small>L5</small></div>
</div>
</div>
If you see the output in jsfiddle, the bars are going below the main-div. I think you can guess the actual requirement, all bars should be position from bottom, and if the % is 50, then frm bottom, bar should be upto 50% height of the main div, along with label, % indication.
I think this is what you need - fiddle. I've rearranged your code quite a lot to simplify how it works, but basically it uses absolute positioning to get the bars to stick to the bottom. Please let me know if anything is unclear.
Each bar now uses the HTML:
<div class="bar-container">
<div class="bar" style="height:50%">
<span class="percentage">50%</span>
<span class="label">L1</span>
</div>
</div>
Change your css with below one
.sub-div {
margin-right: 6%;
display: inline-block;
height: 250px;
border: 1px solid green;
**vertical-align:top;**
}
Try above code...
CSS
You missed aligning the bars add this line in you .sub-div css class
vertical-align: top;
DEMO