How to make the map fit inside div boxes in display table - html

I want to render maps like this way by using display:table.
But it seems that it doesn't follow fixed height, making div bigger when I clicked a button
for showing 4 maps.
I set 50% height for map13 when clicked button #four.
Is there a way to make the map fit inside div boxes? or should I not use display:table?
function divideMap(divisionType) {
$('#map24').css('display', 'none');
$('#map3').css('display', 'none');
if (divisionType === 'four') {
$('#map13').css('height', '50%');
$('#map13').css('width', 'auto');
$('#map24').css('display', 'table-row');
$('#map3,#map4').css('display', 'table-cell');
} else if (divisionType === 'two vertical') {
$('#map3').css('display', 'table-cell');
} else if (divisionType === 'two horizontal') {
$('#map24').css('display', 'table-row');
$('#map4').css('display', 'none');
} else {
}
mainMap.updateSize();
}
html,
body {
height: 100%;
width: 100%;
margin: 0px;
overflow: hidden;
}
#header {
height: 10%;
width: 100%;
background-color: silver;
float: left;
}
#main {
height: 90%;
width: 100%;
}
#contents {
height: 100%;
width: 100%;
}
#fullscreen {
height: 100%;
width: 100%;
display: table;
table-layout: fixed;
}
#map13 {
display: table-row;
}
#map1 {
display: table-cell;
border: 1px solid black;
}
#map3 {
display: none;
border: 1px solid black;
}
#map24 {
display: none;
}
#map2 {
display: table-cell;
background-color: darkslategray;
border: 1px solid black;
}
#map4 {
display: table-cell;
border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="header">
<button onclick="divideMap('original')">reset</button>
<button onclick="divideMap('two vertical')">two vertical</button>
<button onclick="divideMap('two horizontal')">two horizontal</button>
<button onclick="divideMap('four')">four</button>
</div>
<div id="main">
<div id="contents">
<div id="fullscreen">
<div id="map13">
<div id="map1">
</div>
<div id="map3">
</div>
</div>
<div id="map24">
<div id="map2">
</div>
<div id="map4">
</div>
</div>
</div>
</div>
</div>

Related

How to set vertical height in CSS?

I need to give vertical height for the right element with full background. I tried by setting
height:100%;
max-height: 100%
but the element takes only content height
.full_container {
height: 350px;
border: 1px solid #ddd;
}
.pull-left {
float: left;
}
.width50 {
width: 50%;
}
.inline_height {
color: #fff;
padding: 10px;
background: #333;
}
.height100 {
padding: 10px;
height: 100%;
max-height: 100%;
background: #e8e8e8;
}
<div class="full_container">
<div class="clearfix">
<div class="pull-left width50">
<div class="inline_height">
Content height only
</div>
</div>
<div class="pull-left width50">
<div class="height100">
<div>I need to show this div element height to 100%</div>
</div>
</div>
</div>
</div>
Try giving the .clearfix class a display:flex and height:100%
.clearfix {
display: flex;
height: 100%;
}
Example below
.full_container {
height: 350px;
border: 1px solid #ddd;
}
.pull-left {
float: left;
}
.width50 {
width: 50%;
}
.inline_height {
color: #fff;
padding: 10px;
background: #333;
}
.height100 {
padding: 10px;
height: 100%;
max-height: 100%;
background: #e8e8e8;
}
.clearfix {
display: flex;
height: 100%;
}
<div class="full_container">
<div class="clearfix">
<div class="pull-left width50">
<div class="inline_height">
Content height only
</div>
</div>
<div class="pull-left width50">
<div class="height100">
<div>I need to show this div element height to 100%</div>
</div>
</div>
</div>
</div>
See this:
I have added display: flex for .full_container
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.full_container {
height: 350px;
border: 1px solid #ddd;
display: flex;
}
.pull-left {
float: left;
}
.width50 {
width: 50%;
}
.inline_height {
color: #fff;
padding: 10px;
background: #333;
}
.height100 {
padding: 10px;
height: 100%;
max-height: 100%;
background: #e8e8e8;
}
<div class="full_container">
<div class="pull-left width50">
<div class="inline_height">
Content height only
</div>
</div>
<div class="pull-left width50">
<div class="height100">
<div>I need to show this div element height to 100%</div>
</div>
</div>
</div>

Different width divs in the same row

I'm trying to put 3 divs(with different widths respectively : 10%,70% & 20%) in the same row but the middle one always go full width of the page.
Here is my code:
#left-bar {
width: 10%;
background-color: #FF0000;
}
#middle-bar {
width: 70%;
background-color: #6600FF;
}
#right-bar {
width: 20%;
background-color: #99FF99;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
By default div is a block level element that's why they aren't in the same row.
You have a few options to fix this:
option with CSS flexbox:
.row {
display: flex;
width: 100%
}
.row>div {
/*demo purposes */
height: 30px;
}
#left-bar {
flex: 0 10%;
background-color: #F00;
}
#middle-bar {
flex: 1;
background-color: #60F;
}
#right-bar {
flex: 0 20%;
background-color: #9F9;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
(old options)
option with display:inline-block
.row {
/*fix inline-block gap*/
font-size: 0;
}
.row>div {
display: inline-block;
/*demo purposes */
height: 30px;
}
#left-bar {
width: 10%;
background-color: #F00;
}
#middle-bar {
width: 70%;
background-color: #60F;
}
#right-bar {
width: 20%;
background-color: #9F9;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
option with display:table-[cell]
.row {
display: table;
width: 100%
}
.row>div {
display: table-cell;
/*demo purposes */
height: 30px;
}
#left-bar {
width: 10%;
background-color: #F00;
}
#middle-bar {
width: 70%;
background-color: #60F;
}
#right-bar {
width: 20%;
background-color: #9F9;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
The table-cell option actually doesn't work in some internet explorer versions. But the same result can be achieved with the property float:
#left-bar{
width:10%;
background-color: #FF0000;
}
#middle-bar{
width:70%;
background-color: #6600FF;
}
#right-bar{
width:20%;
background-color: #99FF99;
}
.row > div {float:left;}
<div class="row">
<div id="left-bar">a</div>
<div id="middle-bar">b</div>
<div id="right-bar">c</div>
</div>
#left-bar{
width:10%;
background-color: #FF0000;
float:left;
}
#middle-bar{
width:70%;
background-color: #6600FF;
float:left;
}
#right-bar{
width:20%;
background-color: #99FF99;
float:left;
}
If that doesn't work, please provide more html and css because the problem will be somewhere else. Also, verify that you have heights set for your divs.

Simple HTML/CSS - positioning div's

I've recently gotten into the world of HTML/CSS and I am struggling with something.
I want to position the div's like this:
But the I only manage to it like this:
As you see, I want div 5 to be below Div 4, and next to div 3. But I only
Of course, I can wrap div 4 and div 5 in a new div, but I'd rather learn a better way of doing this.
body {
background-color: yellow;
}
#banner {
background-color: green;
}
#topp-meny {
background-color: pink;
}
#side-meny {
background-color: violet;
float: left;
}
#innhold {
background-color: grey;
float: left;
}
#footer {
background-color: blue;
clear: both;
}
<div id="banner">Webutvikling</div>
<div id="topp-meny">Meny</div>
<div id="side-meny">
<p>sidemeny</p>
</div>
<div id="innhold">
<p>innhold</p>
</div>
<div id="footer">
<p>footer</p>
</div>
I don't think that there is a better way to do so without wrapping in a DIV your Div 4 and 5. But in place of using float, you can specify a width to each div and display them as display : inline-block; (a bit better).
* {
margin: 0;
padding: 0;
}
body {
background-color: yellow;
}
#banner {
background-color: green;
}
#topp-meny {
background-color: pink;
}
#side-meny {
background-color: violet;
display: inline-block;
vertical-align: top;
}
#innhold {
background-color: grey;
}
#footer {
background-color: blue;
}
#wrapping {
display: inline-block;
}
<div id="banner">Webutvikling</div>
<div id="topp-meny">Meny</div>
<div id="side-meny">
<p>sidemeny</p>
</div>
<div id="wrapping">
<div id="innhold">
<p>innhold</p>
</div>
<div id="footer">
<p>footer</p>
</div>
</div>
Without wrapping, you can add a height (in PX, not in %) to your Div 3 so that Div 5 remain of the right. I don't really like this option...
* {
margin: 0;
padding: 0;
}
body {
background-color: yellow;
}
#banner {
background-color: green;
}
#topp-meny {
background-color: pink;
}
#side-meny {
background-color: violet;
float: left;
height: 50px;
}
#innhold {
background-color: grey;
float: left;
width: 90%
}
#footer {
background-color: blue;
float: left;
width: 90%
}
<div id="banner">Webutvikling</div>
<div id="topp-meny">Meny</div>
<div id="side-meny">
<p>sidemeny</p>
</div>
<div id="innhold">
<p>innhold</p>
</div>
<div id="footer">
<p>footer</p>
</div>
The problem is that you need to specify a static height for your sub-menu...
Going by the diagram you supplied:
#side-meny {
float:left
}
Make a new div containing #innhold and #footer, let's call it #right-container so you have
<div id="right-container">
<div id="innhold">
<p>innhold</p>
</div>
<div id="footer">
<p>footer</p>
</div>
</div>
Then
#right-container {
float:right
}
See if that works.
Please use the following code which I have modified.
body {
background-color: yellow;
}
#banner {
background-color: green;
}
#topp-meny {
background-color: pink;
}
#side-meny {
background-color: violet;
display: inline-block;
vertical-align: top;
width: 25%;
}
#block {
display: inline-block;
vertical-align: top;
width: 74%;
}
#block p {
margin: 0;
}
#innhold {
background-color: grey;
}
#footer {
background-color: blue;
clear: both;
}
<div id="banner">Webutvikling</div>
<div id="topp-meny">Meny</div>
<div id="side-meny">
<p>sidemeny</p>
</div>
<div id="block">
<div id="innhold">
<p>innhold</p>
</div>
<div id="footer">
<p>footer</p>
</div>
</div>
in your css file you can set
#footer{
...
position:absolute;
left: (div3's width);
top: (div1+div2+div4 height)
}

Creating 8/12 - 4/12 grid whith different amount of columns in

I've been struggling to create a grid banner which contains 2 columns 8/12 and 4/12 where the 8/12 contain 1 div which fills everything and the 4/12 contains 2 on top of eachother. There should be 20 pix between the two columns andbetween the two divs in the 4/12. It should look something like below where the two columns height always is aligned?
Here you go
$(document).ready(function() {
var h;
h = $('#one').height();
alert(h);
$('#ttcont').height(h)
});
#one {
width: 66%;
background-color: black;
display: inline-block;
vertical-align: top;
}
#two {
height: 49.5%;
width: 100%;
background-color: red;
}
#three {
height: 49.5%;
margin-top: 1%;
width: 100%;
background-color: pink;
}
#ttcont {
display: inline-block;
width: 33%;
}
#cont {}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cont">
<div id="one">
jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>jkhdfc
<br>
</div>
<div id="ttcont">
<div id="two">
hjgdcf
</div>
<div id="three">
hjdv
</div>
</div>
</div>
If you want the 4-12s to automatically adapt in height you need to explicitly set the surrounding container's height in css. Since I assume this depends on content, you have to use a tiny bit of Javascript to measure its rendered height and then apply that as a css style to it.
$(document).ready(function() {
var boxcontainerHeight = $('.boxcontainer').height();
$('.boxcontainer').css('height', boxcontainerHeight + 'px');
});
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.boxcontainer {
background-color: #f0f0f0;
width: 500px;
}
.boxcontainer:after {
content: ".";
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
.big {
background-color: #666;
color: #fff;
float: left;
width: 66.6666666%;
height: 300px;
border: 20px solid rgba(255, 255, 255, 0.5);
}
.small {
color: #fff;
height: 50%;
border: 20px solid rgba(0, 0, 0, 1);
}
.small+.small {
border-top-width: 0;
}
.small .boxcontent {
background-color: #a00;
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<html>
<head>
<title>Boxes</title>
</head>
<body>
<div class="boxcontainer">
<div class="big">
<div class="boxcontent">8-12</div>
</div>
<div class="small">
<div class="boxcontent">4-12</div>
</div>
<div class="small">
<div class="boxcontent">4-12</div>
</div>
</div>
</body>
</html>
#d8, #d4 div {
border: 1px solid black;
float: left;
}
#d8, #d4 {
height: 200px;
}
#d8 {
width: 60%;
margin-right: 10px;
}
#d4 div {
width: 30%;
height: calc(50% - 11px);
margin-left: 10px;
margin-top: 10px;
}
#d4 div:first-child {
margin-top: 0px;
margin-bottom: 10px;
}
body {
width: 100vw;
height: 100vh;
}
<div id="d8"></div>
<div id="d4">
<div></div>
<div></div>
</div>
A little CSS solves it.

Centering Div while being able to expand div

I found this solution to centering my div vertically and horizontally. However if I fill in the content section past the length defined for the div it will run outside of it. I was hoping to make it expand depending on the content inside the div. How do I make it so this can happen?
JSFIDDLE
HTML:
<body>
<div id="wrapper">
<div id="headerwrapper">
<div id="header" class="center">header</div>
</div>
<div id="titlewrapper">
<div id="title" class="center">title</div>
</div>
<div id="contentwrapper">
<div id="content" class="center">content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br></div>
</div>
<div id="footerwrapper">
<div id="locationwrapper">
<div id="location" class="center">location</div>
</div>
<div id="copyrightwrapper">
<div id="copyright" class="center">copyright</div>
</div>
</div>
</div>
</body>
CSS:
html body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
.center {
position: relative;
top: 50%;
transform: translateY(-50%);
margin-right: auto;
margin-left: auto;
width: 100%;
height: 100%
max-width: 5em;
}
#wrapper {
background-color: pink;
height: 100%;
width: 100%;
}
#headerwrapper {
background-color: green;
width: 100%;
height: 8em;
}
#header {
color: white;
background-color: black;
}
#titlewrapper {
background-color: red;
width: 100%;
height: 8em;
}
#title {
color: white;
background-color: black;
}
#contentwrapper {
background-color: blue;
width: 100%;
height: 8em;
}
#content {
color: white;
background-color: black;
}
#locationwrapper {
background-color: yellow;
width: 100%;
height: 8em;
}
#location {
color: white;
background-color: black;
}
#footerwrapper {
background-color: brown;
width: 100%;
height: 100%;
}
#copyrightwrapper {
background-color: green;
width: 100%;
height: 8em;
}
#copyright {
color: white;
background-color: black;
}
If you want the "content" sections to dynamically adjust height, take off the fixed height.
Change:
#contentwrapper {
background-color: blue;
width: 100%;
height: 8em;
}
To:
#contentwrapper {
background-color: blue;
width: 100%;
}
Working fiddle to your requirement: http://jsfiddle.net/k5YUu/6/