separate div to 3 columns - javascript

I asked same question 2 days ago but now i still don't get it.
I have 1 div and i want it to be separate into 3 columns of div. I know how to do this for 2 column but, when i am trying 3 column(right, center and left) i get this:
Problem: The pink square is not in the center
Here is my code:
HTML:
<div id="our_services" class="container">
<h1>המוצרים שלנו</h1>
<div id="try">
<div id="product1">
</div>
<div id="product2">
</div>
<div id="product3">
</div>
</div>
</div>
CSS:
#our_services {
/*height: 450px;*/
text-align: center;
font-family: "open_sans_hebrewregular", "alefregular",arial,"Times New Roman";
color: black;
background-color: rgb(224,224,224);
overflow: auto;
margin: auto;
}
#try {
background-color: orange;
width: 50%;
height: 50%;
margin: auto;
}
#product1 {
width: 30%;
height: 75%;
background-color: green;
float: right;
margin: 5px;
}
#product2 {
width: 30%;
height: 75%;
background-color: pink;
float: right;
margin: 5px;
}
#product3 {
width: 30%;
height: 75%;
background-color: blue;
float: left;
margin: 5px;
}

Try with display:inline-block; instead.
exemple

#our_services {
/*height: 450px;*/
text-align: center;
font-family: "open_sans_hebrewregular", "alefregular", arial, "Times New Roman";
color: black;
background-color: rgb(224, 224, 224);
overflow: auto;
margin: auto;
}
#try {
background-color: orange;
width: 50%;
height: 50%;
margin: auto;
}
#product1 {
width: 30%;
height: 75%;
background-color: green;
float: left;
margin: 1.5%;
}
#product2 {
width: 30%;
height: 75%;
background-color: pink;
float: left;
margin: 1.5%;
}
#product3 {
width: 30%;
height: 75%;
background-color: blue;
float: left;
margin: 1.5%;
}
<div id="our_services" class="container">
<h1>המוצרים שלנו</h1>
<div id="try">
<div id="product1">
afs
</div>
<div id="product2">
asf
</div>
<div id="product3">
asf
</div>
</div>
</div>
You had float right as well on one of the boxes

use float left to 1st and 2nd div also. and give margin on percentage. I think this will solve your problem.

I don't know of any way you can do this purely with html/css techniques. You can arrange the items with javascript after the dom (or this part at least) has loaded.
On the other hand, this gets you a little closer to what you want, although the distances between rows won't be equal to the distances between firs/last row and beginning/end of the orange rectangle:
<div id="our_services" class="container">
<h1>המוצרים שלנו</h1>
<div id="try">
<div class="smth">
<div id="product1" class="product">
</div>
</div>
<div class="smth">
<div id="product2" class="product">
</div>
</div>
<div class="smth">
<div id="product3" class="product">
</div>
</div>
</div>
<style>
#our_services{
/*height: 450px;*/
text-align: center;
font-family:"open_sans_hebrewregular", "alefregular",arial,"Times New Roman";
color: black;
background-color: rgb(224,224,224);
overflow: auto;
margin: auto;
}
.smth {
width: 33%;
height: 75%;
float: left;
}
#try{
background-color:orange;
width:50%;
height:50%;
margin:auto;
}
.product {
width: 90%;
height: 100%;
margin: auto;
}
#product1{
background-color:green;
}
#product2{
background-color:pink;
}
#product3{
background-color:blue;
}
</style>
</div>

As far as I understand:
If you don't want any spaces between you'd have to set the width property to (100/3)%
It all depends on your layout of what you want, if you want margin spaces between them all so that they're equally spaced between each other and the edges of their container div you'll have to work out what to do there. So in the case now you have 30% width for each, that leaves you with 10% spacing width which you can spread to 2.5% for margin-left: of your first 2 divs and then for the 3rd div use 2.5% for margin-right: (for a space between the right side and the 3rd div) margin-left:
But as I said, it all depends on what exactly you want for your layout, so if this doesn't answer your question could you tell me more about your expected layout?
If you want a very simple fix based off of what you have at the moment you could set the margin: property to auto and that should center the middle div between what you have now.
Edit: You should also edit the float properties so that they all float one way.

Check the example below:
Code:
#our_services {
text-align: center;
font-family: "open_sans_hebrewregular", "alefregular", arial, "Times New Roman";
color: black;
background-color: rgb(224, 224, 224);
overflow: auto;
margin: auto;
}
#try {
background-color: orange;
width: 50%;
height: 50%;
margin: auto;
}
#product1 {
width: 31%;
height: 200px;
background-color: green;
float: left;
margin: 1%;
}
#product2 {
width: 31%;
height: 200px;
background-color: pink;
float: left;
margin: 1%;
}
#product3 {
width: 31%;
height: 200px;
background-color: blue;
float: left;
margin: 1%;
}
<div id="our_services" class="container">
<h1>המוצרים שלנו</h1>
<div id="try">
<div id="product1">
</div>
<div id="product2">
</div>
<div id="product3">
</div>
</div>
</div>
Example

add the following css:
html, body {
width: 100%;
height: 100%;
}
and add the following properties to #our_services css:
width: 100%;
height: 100%;
further set box-sizing: border-box; and margin: 0% 0% 0% 2.5%; (top as you need, right 0%, bottom as you need and left 2.5%) for the prouctu divs. Btw. you should extract common style to a product class and apply the class on the product divs...

One nice solution is to use display:table and display:table-cell. Which will works for 2 and 3 div both.
HTML:
<div id="our_services" class="container">
<h1>המוצרים שלנו</h1>
<div id="try">
<div id="product1" class="product">
</div>
<div id="product2" class="product">
</div>
<div id="product3" class="product">
</div>
CSS:
#our_services {
background-color: rgb(224, 224, 224);
color: black;
font-family: "open_sans_hebrewregular","alefregular",arial,"Times New Roman";
height: 450px;
margin: auto;
overflow: auto;
text-align: center;
}
#try {
background-color: orange;
display: table;
height: 50%;
margin: auto;
width: 50%;
border-collapse: separate;
border-spacing: 10px;
}
.product{
display: table-cell;
height: 75%;
margin: 5px;
width: 30%;
}
#product1 {
background-color: green;
}
#product2 {
background-color: pink;
}
#product3 {
background-color: blue;
}
Check Fiddle here.

Related

Hiding and Toggle 3 different Div Class

I have three different span.class's that I want to show content for whenever they are clicked. Those div classes are:
<div id="one">
<span class="aboutme"> <p>About me</p></span>
<span class="skills"> <p>Skills</p></span>
<span class="goals"><p>My Goals</p></span>
</div>
I do want the span.aboutme to show on page load up, but hide whenever these other classes are clicked.
here's what I have so far in jsfiddle, but it's not working out.
https://jsfiddle.net/ispykenny/m4n8fzfp/
<div class="thirdwrapper">
<div class="wrapperthree">
<div id="one">
<span class="aboutme"> <p>About me</p></span>
<span class="skills"> <p>Skills</p></span>
<span class="goals"><p>My Goals</p></span>
</div>
<div id="two">
<span class="aboutmecontent">
<p>content for about me
</span>
<span class="skillscontent"> <p>content for skills</p> </span>
<span class="goalscontent"> <p>cotent for goals</p></span>
</div>
</div>
</div>
</div>
.thirdwrapper{
width: 100%;
height: auto;
min-height: 400px;
background-color: #F2F2F2;
margin-top: 0px;
padding-top: 0px;
}
.wrapperthree{
max-width: 1050px;
min-height: 400px;
min-width: auto;
height: auto;
margin-left: auto;
margin-right: auto;
overflow: hidden;
margin-top: 0px;
padding-top: 0px;
}
.wrapperthree p{
margin-top: 0px;
padding-top: 0px;
}
#one{
max-width: 525px;
width: auto;
height: auto;
max-height: 400px;
border:1px solid white;
float: left;
font-size: 80px;
padding: 0;
margin: 0;
padding-top: 60px;
font-family: 'Lora', serif;
}
#one p{
text-align:center;
width:400px;
padding: 0;
margin: 0;
}
#two{
max-width: 525px;
width: auto;
height: auto;
min-height: 400px;
overflow: hidden;
margin-top: 0px;
padding-top: 60px;
padding-left: 60px;
}
span.aboutme p {
background-color:#666;
}
.skills p{
background-color: #999;
}
.goals p{
background-color: #333;
}
.skillscontent p{
display: none;
}
.goalscontent p{
display: none;
}
Here, you basically just need to check which class is being clicked, and first hide them, and then show the one you would actually like to show (if the classes always match up.)
fiddle: https://jsfiddle.net/m4n8fzfp/3/
$('#one span').click(function () {
var that = $(this);
var className = that[0].className;
console.log($(this)[0].className);
$('#two').children('span').children('p').hide();
$('#two').find('.' + className + 'content p').show();
})
So you basically want tabs. This can be easily achieved using jQuery:
https://jsfiddle.net/m4n8fzfp/4/
What you're basically doing is associating each content span with it's appropriate link using the data-tab directive and adding and removing the current class with the appropriate display attribute.

Spacing between images

I have 3 images side-by-side, I would like to know how to get some spacing between them. I have tried everything, margins, padding and I don't know what to do.
.content1 {
background-image: url("http://www.thefreeloves.com/prototype/test/wp-content/uploads/2014/02/album-title.jpg");
color: white;
text-align: center;
width: 100%;
height: 20%;
display: block;
float: left;
}
.text1 {
font-family: "Goudy Old Style", Optima, sans-serif;
font-size: 40px;
margin-bottom: 0;
margin-top: 45px;
}
.text2 {
font-size: 30px;
color: #6CB9D9;
}
.album1 {
float: left;
width: 31%;
text-align: center;
}
.album2 {
display: inline-block;
width: 31%;
text-align: center;
}
.album3 {
float: right;
width: 31%;
text-align: center;
}
.album {
width: 100%;
overflow: hidden;
background-color: #191919;
}
<div class="content1">
<h3 class="text1">Our Latest Album<span class="slash"> / </span><span class="text2">Fresh from the house of Music Club Band</span></h3>
</div>
<div class="album">
<div class="album1">
<img src="http://www.thefreeloves.com/prototype/test/wp-content/uploads/2015/02/FDA9133-650x385.jpg" alt="album1">
</div>
<div class="album2">
<img src="http://www.thefreeloves.com/prototype/test/wp-content/uploads/2015/02/FDA9099-650x385.jpg" alt="album2">
</div>
<div class="album3">
<img src="http://www.thefreeloves.com/prototype/test/wp-content/uploads/2015/02/FDA0373-650x385.jpg" alt="album3" class="album4">
</div>
</div>
You set your wrapping div's to 31% but you didn't change the size of your images so they were flowing outside the wrappers. If you set Overflow: hidden; on your album1, album2 and album3 div's you'll see that your margins are working on the divs but you'll only see part of your images. if you set the imgs themselves to a width of 100% as below you'll see it works.
.content1 {
background-image: url("http://www.thefreeloves.com/prototype/test/wp-content/uploads/2014/02/album-title.jpg");
color: white;
text-align: center;
width: 100%;
height: 20%;
display: block;
float: left;
}
.text1 {
font-family: "Goudy Old Style", Optima, sans-serif;
font-size: 40px;
margin-bottom: 0;
margin-top: 45px;
}
.text2 {
font-size: 30px;
color: #6CB9D9;
}
.album1 {
float: left;
width: 31%;
text-align: center;
margin: 1%;
}
.album2 {
display: inline-block;
width: 31%;
text-align: center;
margin: 1%;
}
.album3 {
float: right;
width: 31%;
text-align: center;
margin: 1%;
}
.album {
width: 100%;
overflow: hidden;
background-color: #191919;
}
.album img { width: 100%; }
<div class="content1">
<h3 class="text1">Our Latest Album<span class="slash"> / </span><span class="text2">Fresh from the house of Music Club Band</span></h3>
</div>
<div class="album">
<div class="album1">
<img src="http://www.thefreeloves.com/prototype/test/wp-content/uploads/2015/02/FDA9133-650x385.jpg" alt="album1">
</div>
<div class="album2">
<img src="http://www.thefreeloves.com/prototype/test/wp-content/uploads/2015/02/FDA9099-650x385.jpg" alt="album2">
</div>
<div class="album3">
<img src="http://www.thefreeloves.com/prototype/test/wp-content/uploads/2015/02/FDA0373-650x385.jpg" alt="album3" class="album4">
</div>
</div>
In each div tag, just place the following style = "margin-right: 20px;". So for example, for the first image, change it ot this
div style = "margin-right: 20px;" class="album1">
You don't need to use float, you can simply set the display of the albums to inline-block, and set the text-align of their parent to center. Note that the three images there are too wide to be in one line, so you'll have to adjust that yourself.
.album1 img, .album2 img, .album3 img {
//set img width and height here
}
.album1 {
display: inline-block;
//add padding/margin here
}
.album2 {
display: inline-block;
//add padding/margin here
}
.album3 {
display: inline-block;
//add padding/margin here
}
.album {
width: 100%;
overflow: hidden;
background-color: #191919;
text-align:center;
}

How to create two columns (one with two rows and other with one) without using fixed sizes?

I've successfully created two columns with various number of rows, however, I don't want to use fixed sizes. Is it possible without Javascript?
Here's my code:
HTML:
<body>
<div class='table'>
<div class='cell'>
<div class='row'>test</div>
<div class='row'>test</div>
</div>
<div class='cell'>
test
</div>
</div>
</body>
CSS:
body
{
font-size: 20px;
color: white;
background-color: black;
}
.table
{
width: 100%;
height: 500px;
background-color: yellow;
}
.row
{
background-color: red;
height: 50%;
}
.cell
{
width: 50%;
float: left;
height: 100%;
background-color: blue;
}
Preview: https://jsfiddle.net/XyYND/22/
You just need to add height:100% to your other elements.
Here's an updated fiddle: https://jsfiddle.net/XyYND/23/
And the CSS:
html {
height:100%;
}
body
{
font-size: 20px;
color: white;
background-color: black;
height:100%;
}
.table
{
width: 100%;
height: 100%;
background-color: yellow;
}
.row
{
background-color: red;
height: 50%;
}
.cell
{
width: 50%;
float: left;
height: 100%;
background-color: blue;
}
And the HTML:
<body>
<div class='table'>
<div class='cell'>
<div class='row'>test</div>
<div class='row'>test</div>
</div>
<div class='cell'>
test
</div>
</div>
</body>
You could use flexbox (Fiddle link):
.table
{
display: flex;
width: 100%;
height: 500px;
}
.cell
{
flex: 1;
height: 100%;
background-color: blue;
}
flex: 1; will make the divs take as much space as possible.

How to fill remaining div?

Well i have the following: http://jsfiddle.net/a9VDa/12/
I am trying to make the jquery tree fill the remaining contents of the div "a" but also include a scroll if there isn't enough space.
<div class="a">
<div class="b"></div>
<div class="c" id="tree"></div>
</div>
My suggested solution: http://jsfiddle.net/Bt2sL/2/
Without orange part scrolling.
HTML
<div class="b"></div>
<div class="a">
<div class="c" id="tree"></div>
</div>
CSS
.a {
height: 60px;
background-color: red;
height: auto;
overflow: scroll;
height: 200px; // adjust this to your need
}
.b {
height: 22px;
background-color: coral;
}
.c {
background-color: lightblue;
}
Can you just make div b fixed and add some padding to a with overflow scroll set?
.a {
height: 60px;
background-color: gray;
position: relative;
overflow: scroll;
padding-top: 22px;
}
.b {
position: fixed;
top: 0;
height: 22px;
background-color: coral;
}
.c {
background-color: lightblue;
height: auto;
overflow: scroll;
}

Text Will Not Fill Up Div

I am designing a stat board for a call center and I am having trouble getting 2 elements to size up correctly. I have used an automatic text resizer called FitText(link below). I have gotten every other element to work with FitText except the 100% and 100 listed in the code. I cannot figure out why the 100% and the 100 just stay so small compared to the sizes of the divs they are contained in. Both containers are 100% width. I have played around with hundreds of CSS combinations to no avail. Any help will be greatly appreciated. Via the requests below, here is the JSFiddle link.
http://jsfiddle.net/neggly/57tVW/
CSS
#wrap {
position: absolute;
height:100%;
width:100%;
margin:0 auto;
background-color: black;
}
#statuscolorwrap
{
background-color: aqua;
float: left;
width: 1%;
height: 100%;
}
#numberwrap
{
background-color: #ff0;
float: left;
width: 20%;
height: 100%;
}
#announcementwrap
{
background-color: coral;
float: left;
width: 79%;
height: 100%;
}
#queuewrapper
{
height:40%;
width:100%;
float: top;
background-color: darkorchid;
}
#queuecolors
{
height:40%;
width:100%;
float: top;
background-color: cadetblue;
}
#queuepercentage
{
height: 50%;
width: 100%;
float: top;
background-color: chartreuse;
}
#queueholding
{
height: 50%;
width: 100%;
float: bottom;
background-color: crimson;
}
#topcolor
{
height: 50%;
width: 100%;
float: top;
background-color: darkseagreen;
}
#bottomcolor
{
height: 50%;
width: 100%;
float: bottom;
background-color: moccasin;
}
#datetimewrapper
{
width:100%;
height:5%;
float: top;
background-color: deepskyblue;
}
#messages
{
width: 100%;
height: 60%;
float: top;
background-color: darkorchid;
overflow-y: auto;
}
.messagewrapper
{
width: 100%;
height: 100px;
float:top;
background-color: azure;
}
.messageimportance
{
float:left;
width: 5%;
height: 100%;
background-color: darkslategrey;
}
.messagesubject
{
float:left;
width: 95%;
height: 100%;
background-color: blanchedalmond;
}
h1
{
font: Helvetica, sans-serif;
margin:0;
padding:0;
text-align: center;
}
h2
{
font: Helvetica, sans-serif;
margin:0;
padding:0;
text-align: center;
}
h3
{
font: Helvetica, sans-serif;
font-weight: bold;
margin:0;
padding:0;
text-align: center;
}
#anpicturewrap
{
float:top;
width:100%;
height:45%;
background-color: darkcyan;
}
#antextwrap
{
float:top;
width:100%;
height:50%;
background-color: darkkhaki;
overflow-y: auto;
}
img
{
max-width: 100%;
max-height: 100%;
display:block;
margin:auto;
}
h4
{
font: Helvetica, sans-serif;
margin: 0;
padding: 0;
text-align: left;
}
#text
{
width: auto;
margin-left: 40px;
margin-right:40px;
margin-bottom: 30px;
}
.subjecttext
{
height: 100%;
width:100%;
margin-left: 10px;
margin-right: 10px;
margin-top: auto;
margin-bottom: auto;
}
HTML
<html>
<head>
<title>Virginia Summary</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="reset.css"/>
<link rel="stylesheet" href="base.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="js/libs/jquery/jquery.fittext.js" type="text/javascript"></script>
</head>
<body>
<div id="wrap">
<div id="numberwrap">
<div id="queuewrapper">
<div id="queuepercentage">
<div class="subjecttext">
<h1 id="fittext1">1</h1>
</div>
</div>
<div id="queueholding">
<h1 id="fittext2">100</h1>
</div>
</div>
<div id="messages">
<div class="messagewrapper">
<div class="messagesubject">
<div class="subjecttext">
<h2 id="fittext3">Enter Subject here</h2>
</div>
</div>
<div class="messageimportance">
</div>
</div>
</div>
</div>
<div id ="statuscolorwrap">
<div id="queuecolors">
<div id="topcolor">
</div>
<div id="bottomcolor">
</div>
</div>
</div>
<div id="announcementwrap">
<div id="datetimewrapper">
<h3 id="fittext4">12/12/2014 18:00</h3>
</div>
<div id="anpicturewrap">
<img src="images/pic.jpg" alt=""/>
</div>
<div id="antextwrap">
<div id="text">
<h4 id="fittext5">sample text</h4>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$("h1").fitText(1);
$("#fittext2").fitText(1.2);
$("#fittext3").fitText(1.2);
$("#fittext4").fitText(1.2, {minFontSize: '20px', maxFontSize: '30px'});
$("#fittext5").fitText(1.2);
</script>
</body>
</html>
https://github.com/davatron5000/FitText.js
Default margins on headings and some of the margins you have set are causing some of the alignment issues. If you switched some of that to padding, and used box-sizing:border-box; on some of those divs, it would make things a bit easier to style:
div {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
http://www.paulirish.com/2012/box-sizing-border-box-ftw/
In the JS fiddle example, it doesn't look the Javascript to resize the text is actually being called on anything. When I turn on JQuery in the fiddle and then actually call the text-resize stuff on your elements it does work to resize the elements.
$(document).ready( function(){
jQuery("#fittext1").fitText(.2);
jQuery("#fittext2").fitText(.3);
jQuery("#fittext3").fitText(.6);
jQuery("#fittext4").fitText(1, {minFontSize: '20px', maxFontSize: '30px'});
jQuery("#fittext5").fitText(1.2);
});
Edit: I updated some of your CSS so it worked the way you might have expected it to. I moved normalize to the top of your CSS, since it should be the first thing added. You will probably want to add some space and things in some of the boxes, but since I added the border-box, you can just do this with padding on the percentage sized elements.
http://jsfiddle.net/57tVW/2/

Categories

Resources