I have a page which displays an HTML canvas element inside a container. Since the image displayed in the canvas can be far bigger than the space I have, I forced the size of the container and used its overflow property to scroll the contente of the canvas. While both the container and the scrollbar are displayed correctly, the canvas simply ignores it.
My HTML:
<div class="sidebar">
Some content
</div>
<div class="the_wrapper">
<div class="canvas_wrapper">
<canvas id="imageCanvas"></canvas>
</div>
<div class="another_element">
Some other content
</div>
</div>
And this is the CSS:
.sidebar{
height: 100vh;
width: 20vw;
float: left;
}
.the_wrapper{
height: 100vh;
width: 80vw;
float: right;
}
.canvas_wrapper{
height: 60vh;
overflow: scroll;
}
.another_element{
height: 40vh;
}
This is what I want
But all I get is this
.the_wrapper do not need a float set to right.
.the_wrapper{
height: 100vh;
width: 80vw;
float: right; // Don't do that
}
Just do this
.the_wrapper {
position: absolute;
right: 0;
height: 100vh;
width: 80vw;
}
I also reset some properties to get the result of your first example.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
overflow: hidden;
}
Here the snippet result :
* {
box-sizing: border-box;
padding: 0;
margin: 0;
overflow: hidden;
}
.sidebar {
height: 100vh;
width: 20vw;
float: left;
border: 3px solid #000;
}
.the_wrapper {
position: absolute;
right: 0;
height: 100vh;
width: 80vw;
}
.canvas_wrapper {
height: 60vh;
border: 3px solid green;
}
.another_element {
height: 40vh;
border: 3px solid red;
}
<div class="sidebar">Some content</div>
<div class="the_wrapper">
<div class="canvas_wrapper">Canvas
<canvas id="imageCanvas"></canvas>
</div>
<div class="another_element">Some other content</div>
</div>
You can also try it in https://jsfiddle.net/lofeed/6n983g7x/4/
The wrapper is set to float to the right, meaning that all available space will be included within it.
Related
I have a div .modal that has a fixed position with padding: 90px;. There is a div .child inside it with height: 1500px;.
The problem is that the padding right and bottom gone on modal, I have tried to set box-sizing: border-box; but it cannot solve the problem.
If you inspect it, there are negative value applied on position, I don't know why.
.modal {
background-color: gray;
height: 100vh;
padding: 90px;
position: fixed;
width: 100vw;
}
.child {
background-color: orange;
height: 1500px;
width: 100%;
}
<div class="modal">
<div class="child"></div>
</div>
Padding should be present no matter the value of the height of the content.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.modal {
background-color: gray;
height: 100%;
padding: 90px;
position: fixed;
width: 100vw;
overflow: auto;
}
.child {
background-color: orange;
height: 1500px;
width: 100%;
}
<div class="modal">
<div class="child"></div>
</div>
Try this
this will work for you, so basically the padding top and bottom didn't show because the child div was taking the whole height of the page but if you set the height to be for example 800px then it will work.
.modal {
background-color: gray;
height: 100vh;
position: fixed;
width: 100vw;
display:flex;
justify-content: center;
align-items:center;
}
.child {
background-color: orange;
height: 800px;
width: 100%;
margin: 90px;
}
<div class="modal">
<div class="child"></div>
</div>
I know that fixed positioning does not work relative to the parent, only to the browser window and the solution is absolute, but I also have a problem with that.
In the div in which I need a scroll inside, I have to put the icon always visible in the bottom right corner.
My fiddle: https://jsfiddle.net/nck7o0jL/
Below is my code.
.big {
height: 600px;
width: 600px;
border: 2px solid black;
}
.small {
height: 300px;
width: 300px;
border: 2px solid red;
overflow: auto;
position: relative;
resize: both;
}
img {
width: 30px;
height: 30px;
position: absolute;
right: 15px;
bottom: 15px;
}
<div class="small"><img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-close-circled-128.png">
<div class="big">
</div>
</div>
As you can see, by stretching the div.small the icon is held, but during the scroll it is not.
Will someone give a helping hand?
You can approximate this using flexbox and position:sticky
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.big {
height: 600px;
width: 600px;
flex-shrink: 0;
}
.small {
height: 300px;
width: 300px;
border: 2px solid red;
overflow: auto;
resize: both;
display: flex;
}
img {
width: 30px;
height: 30px;
margin: auto 0 15px auto;
position: sticky;
order: 1;
right: 15px;
top: calc(100% - 45px);
}
<div class="small"><img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-close-circled-128.png">
<div class="big">
</div>
</div>
I am looking to create this kind of card layout how to get that blue on both side of the card.
The only thing i would like to know is how to get that blue on left and right side of the card.
.card {
height: 300px;
width: 400px;
background: #f1f1f1;
}
<div class="card">
<h2>Title</h2>
</div>
You need to wrap The card with container with two childern.
1- Then add overlay div with absolute positioning (this will be the blue side)
2- The card (white div)
N.P: I've added flex to body just to center the card, no need for it.
Example:
body {
background-color: gray;
display: flex;
}
.card-container {
position: relative;
height: 300px;
width: 400px;
margin: auto;
}
.overlay {
position: absolute;
top: 5%;
left: 0;
width: 100%;
height: 90%;
background: linear-gradient(#4180B9, #42BDBB);
border-radius: 5px;
}
.card {
z-index: 2;
position: relative;
width: 90%;
height: 100%;
margin: auto;
background-color: #fff;
border-radius: 5px;
}
<div class="card-container">
<div class="overlay"></div>
<div class="card">
</div>
I have a layout wherein the container has a fixed height and width of 640px x 480px. Inside this container are 3 divs, top, mid and bot. I want this 3 divs to fit inside the container provided that they will not overflow the container. The top and bot div doesn't have fixed height while the mid should fit the space between and push top and bot.
What I've already tried was like this:
HTML
<div class="main">
<div class="top">
</div>
<div class="mid">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Chestnut-breasted_Malkoha2.jpg/593px-Chestnut-breasted_Malkoha2.jpg" />
</div>
<div class="bot">
</div>
</div>
CSS
.main {
padding: 10px;
width: 640px;
height: 480px;
display: inline-block;
background: #000;
position: relative;
}
.top {
width: 100%;
height: 50px;
display: block;
background: #eee;
}
.mid {
width: 100%;
height: 100%;
display: block;
background: #333;
}
img {
max-width: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.bot {
width: 100%;
height: 50px;
display: block;
background: #ccc;
}
FIDDLE HERE
Now my problem is the mid push the bot outside the container. How can i make them fit inside the container without using overflow: hidden? Thanks in advance.
NOTE : the image should fit inside the mid container.
UPDATE top and bot div can contain paragraphs so it's not fixed height.
Check this sample:
http://jsfiddle.net/J6QTg/8/
.main {
padding: 50px 0px;
width: 640px;
height: 480px;
display: block;
background: #000;
position: relative;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.top {
width: 100%;
height: 50px;
display: block;
background: #eee;
position: absolute;
top : 0;
left : 0;
}
.mid {
width: 100%;
height: 100%;
display: block;
background: #333;
}
img {
max-width: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.bot {
width: 100%;
height: 50px;
display: block;
background: #ccc;
position: absolute;
bottom : 0;
left : 0;
}
Update:
It is also possible to use tables, to have more flexible boxes.
http://jsfiddle.net/jslayer/U3EaZ/
HTML:
<div class="box">
<div class="h"> Hello<br/>Cruel<br/>World </div>
<div class="m">
<img src="http://goo.gl/a1smCR" alt="" />
</div>
<div class="b"> Omg </div>
</div>
CSS:
.box {
display: table;
width: 640px;
height: 480px;
background: red;
}
.h, .m, .b {
display: table-row;
}
.h {
background: yellow;
height: 0;
}
.m {
background: green;
}
.m img {
max-width: 100%;
height: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.b {
background: blue;
height: 0;
}
I would use JavaScript/JQuery: FIDDLE
I've used JQuery for simplicity, but it can probably be done with just JavaScript...
var totalheight = eval($('.main').height() - $('.top').outerHeight(true) - $('.bot').outerHeight(true))
$('.mid').outerHeight(totalheight);
Try to set the height of mid based on the container.
.mid {
width: 100%;
height: 383px;
display: block;
background: #333;
}
FIDDLE
If the container has a fixed height and width, then you can set the height to 79.25% like this:
.mid {
max-width: 100%;
height: 79.25%;
display: block;
background: #333;
}
demo
Could you please give a html code for the following?
I need to display div and iframe horizontally fitting the whole page. But I need div to be fixed size (100px) and iframe fitting the remaining space.
Thanks
Fiddle
CSS
div{ border: 1px solid #f00; width: 100px; position: absolute; left: 0; top: 0;}
iframe{ width: 100%; margin: 0 0 0 100px;}
HTML
<div>hi</div>
<iframe src="http://www.google.com/"></iframe>
EDIT:
To avoid horizontal scrollbar define width in % to both the elements - Updated Fiddle
http://jsfiddle.net/gZNKk/1/
<html><head>
<style>
body, html {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#left {
float: left;
width: 100px;
background: blue;
height: 100%;
}
#right {
width: auto; /* This is the default */
float: none;
margin-left: 100px;
background: red;
height: 100%;
}
#right-iframe {
background: yellow;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="left"></div>
<div id="right">
<iframe id="right-iframe"></iframe>
</div>
</body></html>
EDIT: Fixed the extra spacing on the right causing the scrollbar to appear.
CSS:
#content-wrapper {
width: 100%;
overflow:hidden;
}
#content-left {
width: 49.5%;
min-height: 100%;
float: left;
border-right: solid 1px #A9D0D6;
}
#content-right {
width: 49.5%;
min-height: 100%;
float: right;
}
HTML:
<div id='content-wrapper'>
<div id='content-left'></div>
<div id='content-right'><iframe src="http://www.google.com"></div>
</div>
Width you can adjust, whatever you required.
Try this,
http://jsfiddle.net/anglimass/UUmsP/15/