I need the content box to reach to the footer even when the content box is empty. I want to achieve this using only CSS.
padding-bottom is not an option.
I don't want to use a background image, such as background-image: url center repeat-y;
How can I achieve this?
.wrap {
height: 100%;
}
.l-col {
padding-top: 0;
height: 100%;
}
.footer {
position: relative;
height: 60px;
clear: both;
float: left;
width: 100%;
z-index: 3;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="wrap">
<div class="container">
<div class="col-xs-12 l-col">
<div class="col-xs-12" style="padding:0px">
<table>Content</table>
</div>
</div>
</div>
</div>
Current Layout:
Desired Layout:
Using CSS's calc() function, you can use calculate the min-height of your content div.
body {
margin: 0
}
.header,
.footer {
width: 100%;
height: 60px;
background-color: grey;
}
.content {
width: 100%;
min-height: calc(100vh - 120px);
background-color: #FFF8DC;
}
<div class="wrap">
<div class="container">
<div class="header">
Header
</div>
<div class="content">
Content
</div>
<div class="footer">
Footer
</div>
</div>
</div>
If your preferred method is jQuery, the following code will work, even on page resize.
function setContentHeight() {
var headerHeight = $(".header").height();
var footerHeight = $(".footer").height();
var winHeight = $(window).height();
$(".content").css("min-height", winHeight-(headerHeight+footerHeight));
}
setContentHeight();
$(window).resize(setContentHeight);
Here you go just calculate your min height so if content gets more it will expand if you don't want that just use regular height.
body{margin:0;}
.head, .foot {
width: 100%;
background: gray;
height: 50px;
float: left;
display: inline-block;
}
.content {
width: 80%;
min-height: calc(100vh - 100px);
background: lightgray;
float: left;
display: inline-block;
}
<div class="head">Head</div>
<div class="content">hello</div>
<div class="foot">foot</div>
flex + html5, looks like a school case ...
html {
display:flex;
height:100%;
}
body {
flex:1;
display:flex;
flex-flow:column;
color:white;
}
header , footer{
text-align:center;
background:#4F81BD;
line-height:4em;
}
main {
flex:1;
display:flex;
justify-content:center;
padding-left:10%;/* cause aside is set to 10% width */
}
section {
border:30px #4F81BD solid;
padding:1em;
margin:2px;
box-shadow:0 0 0 2px , inset 0 0 0 2px ;
width:60%;/* whatever */
color: #385D8A
}
aside {
background: #4F81BD ;
box-shadow:0 0 0 2px #385D8A;
margin:auto 0;
width:10%;
min-height:30vh;/* demo purpose, use content instead */
display:flex;/* optionnal to center on XY axis */
align-items:center;
justify-content:center;
}
<header>
header (any height)
</header>
<main><!-- fill gap in between -->
<section>section, run snippet in full page mode and resize window</section>
<aside>aside</aside>
</main>
<footer>
footer (any height)
</footer>
pen to play with: http://codepen.io/gc-nomade/pen/ORyXZA
Related
I have a div with a fixed position containing an image that I have set to max-width:20% so it is scaled down. The height of the div is scaled to match the image but the width isn't, it looks like it's the same width of the initial size of the image.
I might be missing something fundamental but can't really understand this.
#logo {
max-width: 20%;
}
#logoholder {
position: fixed;
left: 10px;
top: 120px;
background: rgb(47 47 47 / 36%);
text-align: center;
}
#logo2 {
max-width: 77px;
}
#logoholder2 {
position: fixed;
width: 77px;
height: 77px;
left: 10px;
top: 30px;
background: rgb(47 47 47 / 36%);
text-align: center;
}
<div id="logoholder">
<img id="logo" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
<-- Expected result -->
<div id="logoholder2">
<img id="logo2" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
#logo{
max-width:100px;
}
#logoholder {
position: fixed;
left:0;
top:0;
background: rgb(47 47 47 / 36%);
}
<div id="logoholder">
<img id="logo" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
The max-width using a percentage is causing weird behaviour, changed it to px.
I set some margins and borders for clarity - and left the original images in place (the first one is the one in play here)
I would suggest using a flex display for simplicity then we can set the container to a size and the height of the image to what we want relative to that (see comments in the CSS)
I set the button at the "top" but it could be relative position also and work around that "fixed" position issue.
body {
margin: 0;
}
#logoholder {
position: relative;
left: 10px;
top: 1rem;
/* background: rgb(47 47 47 / 36%);*/
/* light violet background */
background-color: #8080FF20;
}
#logo {
max-width: 20%;
}
#logoholder2 {
position: relative;
left: 10px;
top: 30px;
*/ width: 77px;
height: 77px;
/* light cyan background */
background-color: #20E0E020;
}
#logo2 {
max-width: 77px;
}
/* set up the blocks to keep the "gray" one at the top */
.container-all {
display: flex;
align-items: cemter;
justify-content: cemter;
/*stack then for this demo */
flex-direction: column;
/* the "lime" border around all the content */
border: solid 1px #88ff88;
}
.container-all .content-container {
margin: 0.5rem;
/* get our logo (first container) at the top if we want to */
/* margin-top:0;*/
}
.logo-container {
/* keep logo/button at top when scrolling for this demo */
align-self: flex-start;
position: sticky;
top: 0;
/* set up this containers display */
display: flex;
justify-content: center;
align-items: center;
}
.logo-container .content-item {
/* controls the height of the image on the button */
/* these should be the same since the "default" is 16px font-size == 1rem */
font-size: 1rem;
/* font-size:16px;*/
}
.logo-image {
/* controlled by container font size as these have em */
/* so if 1rem = 16px this 4em would be 16 X 5=80px */
height: 5em;
}
.content-container {
text-align: center;
border: 1px solid blue;
object-fit: contain;
}
.content-container:first-of-type {
/* light gray background for this demo */
/* alpha transparency information into the hex format for colors 2E as this has 8 characters */
background-color: #8080802E;
border: outset #D0D0D02E 4px;
}
.content-item {
border: dashed #00000044 1px;
padding: 0.25rem;
margin: 0.25rem;
}
.content-container .content-item .big-me:last-of-type {
height: 20rem;
}
<div class="container-all">
<div class="logo-container content-container">
<button type="button" class="content-item">
<img class="logo-image" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</button>
</div>
<div class="content-container">
<div class="content-item">
Below here just to force scrolling on the sticky icon
</div>
</div>
<div id="logoholder" class="xcontent-container">
<div class="content-item">
<img id="logo" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
</div>
<div class="content-container">
<div class="content-item">
<-- Expected result -->
</div>
</div>
<div id="logoholder2" class="content-container">
<div class="content-item">
<img id="logo2" src="https://www.google.com/gmail/about/static-2.0/images/logo-gmail.png">
</div>
</div>
<div class="content-container">
<div class="content-item">
<div class="big-me">I am big so I can force the scroll.
</div>
</div>
</div>
</div>
This question already has answers here:
Fixed header, footer with scrollable content
(7 answers)
Closed 2 years ago.
I'm coding a website and i want to split a page in 3 different section:
one for the title+a button,
one for the content,
one for the text input.
.
The problem is that the divs don't fill the height and the width of the screen. The second div also need a scrollbar because of his content that can vary.
I'd like to resolve the problem with CSS, but everything is accepted
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Server Messaggistica</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div style="width:100vh; height: 100vh;">//container of the 3 divs
<div style="width:100%; height: 15%;">//div1
<h1>Bentornato utente</h1>
<button class=button>LOG OUT</button>
</div>
<hr>
<div style="width:100%; height: 70%; overflow-y: scroll; overflow-x: hidden;">//div2
//php content
</div>
<hr>
<div style="width:100%; height: 15%;">//div3
<textarea name="messaggio" rows="3" cols="100"></textarea>
</div>
</div>
</body>
</html>
You can do this with the vh unit in CSS, which allows you to specify the height of containers in relation to the height of the viewport.
body {
margin: 0;
}
.vh-15 {
min-height: 15vh;
}
.vh-70 {
min-height: 70vh;
}
/* for illustration */
.bg-red { background: red; }
.bg-green { background: green; }
.bg-blue { background: blue; }
div { color: white; }
<div class='vh-15 bg-red'> 1: 15% </div>
<div class='vh-70 bg-green'> 2: 70% </div>
<div class='vh-15 bg-blue'> 3: 15% </div>
I would solve this using flexbox. The flex children values are relative to each other. I've based mine out of 100. The numbers are arbitrary though. Instead of 70 and 15, you could use 700 and 150.
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.top,
.bottom {
flex: 15;
}
.middle {
flex: 70;
}
/******************
Presentational
******************/
.middle { background-color: green; }
.middle::after { content: '2: 70%'; }
.top { background-color: red; }
.top::after { content: '1: 15%'; }
.bottom { background-color: blue; }
.bottom::after { content: '3: 15%'; }
.container > div { position: relative; }
body { margin: 0; }
.container > div::after {
position: absolute;
top: 50%;
left: 2rem;
transform: translateY(-50%);
color: white;
display: block;
font-family: sans-serif;
}
<div class="container">
<div class="top"></div>
<div class="middle"></div>
<div class="bottom"></div>
</div>
Here is the effect I am trying to achieve:
Example
I know how to make the triangle, my issue is that is is being created INSIDE of the box. If I set "left" to 100%, the box will disappear behind the right side of the box instead of going outside of the box over the next one.
Here is the Pen I am working on to try and get this to work:
My Code
HTML:
<div class="square title">
<div class="content">
<div class="table">
<div class="table-cell ">
<ul>This demo shows you can center multiple types of content :
<li>Text</li>
<li>Images</li>
<li>Lists</li>
<li>... (you can also do it with forms)</li>
</ul>
</div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell ">
<p>Hello World!</p>
</div>
</div>
</div>
</div>
CSS:
body {
font-family: sans-serif;
color: #fff;
font-size: 20px;
text-align: center;
}
.square {
float:left;
position: relative;
width: 33%;
padding-bottom : 33%; /* = width for a 1:1 aspect ratio */
/* margin:1.66%; */
background-color:#1E1E1E;
overflow:hidden;
/* border: solid 1px red; */
margin: 5px;
}
.content {
position:absolute;
height:90%; /* = 100% - 2*5% padding */
width:90%; /* = 100% - 2*5% padding */
padding: 5%;
}
.table{
display:table;
width:100%;
height:100%;
}
.table-cell{
display:table-cell;
vertical-align:middle;
}
/* For list */
ul{
text-align:left;
margin:5% 0 0;
padding:0;
list-style-position:inside;
}
li{
margin: 0 0 0 5%;
padding:0;
}
.title::after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-left: 50px solid green;
left: 95%;
/* top: 45%; */
/* z-index: 999; */
}
I tried making a whole new div around the square and setting that to have the triangle, but it made the triangle go all the way to the right of the screen, even without setting anything for the left or right.
I also tried z-index but that didn't do anything either.
You can easily achieve this with only background:
.box {
display: inline-block;
width: 150px;
height: 150px;
background: grey;
}
.box:last-child {
background:
linear-gradient(to top right,grey 49.8%,transparent 50%) 0 calc(50% - 15px),
linear-gradient(to bottom right,grey 49.8%,transparent 50%) 0 calc(50% + 15px),
#000;
background-size:30px 30px;
background-repeat:no-repeat;
}
<div>
<div class="box">
</div>
<div class="box">
</div>
</div>
The following implementation i came up with for a sidemenu works fine
https://jsbin.com/getotijela/edit?html,css,output
HTML:
<link rel="stylesheet" type="text/css" href="main.css">
<div class="container">
<div class="menu">
a
</div>
<div class="content">
<span id="clickable">
basdasdasdasdas
</span>
</div>
<div>
<script>
document.getElementById("clickable").addEventListener('click',function(){
var el = document.getElementsByClassName("menu")[0]
el.className = "menuClosed"
})
</script>
CSS:
.test{
background-color:red;
}
.container{
display:flex;
flex-direction: row;
position:relative;
height:100%;
}
.menu{
width:200px;
/* left:20px; */
background-color:red;
}
.menuClosed{
width:0px;
background-color:red;
transition: 0.3s all;
}
.content{
background-color:yellow;
flex:1;
}
but what it does is collapse the sidemenu to a width of 0 ( as i've instructed it to). What i was aiming for was: having the sidemenu move to the left as many units as it's width, something that in the past i would achieve by modifying the leftcss property.
In other words, i dont want the menu to collapse to a width of 0, just have it move out of sight
How could i achieve something similar to that in flexbox if at all?
#PossessWithin Why would you use a translateX for that ?
You should use the flexbox-shrink and flexbox-basis property's they are made especially for these cases.
I made a fiddle check it out here JSFiddle
<aside class="sidebar is-visible">
<p class="sidebar-content">
Put all your content inside of here since this keeps the width of your sidebar <br>(so a div with the width you want the sidebar to be).
</p>
</aside>
<main class="content">
<button class="toggle-sidebar">Toggle sidebar</button>
<p>
scale this content
</p>
</main>
CSS
*{
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
}
body {
display: flex;
justify-content: flex-end;
}
.content {
display: flex;
min-height: 0;
flex-direction: column;
flex-grow: 1;
flex-shrink: 0;
flex-basis: 100%;
}
.sidebar {
flex-grow: 0;
flex-shrink: 0;
flex-basis: auto;
height: 100%;
}
.sidebar.is-visible ~ .content {
flex-basis: 0;
}
/* Animation */
.content {
transition: flex-basis .1s cubic-bezier(.465, .183, .153, .946);
will-change: flex-basis;
}
.sidebar.is-visible ~ .content {
transition: flex-basis .3s cubic-bezier(.465, .183, .153, .946);
}
.sidebar-content {
display: block;
width: 300px;
background-color: #eee;
height: 100%;
margin: 0;
padding: 20px;
border-right: 1px solid #ccc;
}
.content {
padding: 20px;
}
Please vote this up since it's the way it's supposed to be done.
Please try this:
HTML:
<link rel="stylesheet" type="text/css" href="main.css">
<div class="container">
<div class="menu">
a
</div>
<div class="content">
<span id="clickable">
basdasdasdasdas
</span>
</div>
<div>
CSS
.test{
background-color:red;
}
.container{
display:flex;
flex-direction: row;
position:relative;
height:100%;
}
.menu{
width:200px;
transition: 0.3s all ease-in-out;
background-color:red;
}
.menuClosed{
background-color:red;
transition: 0.3s all ease-in-out;
transform: translateX(-200px);
margin-right: -200px;
}
.content{
background-color:yellow;
flex:1;
}
I have changed the "menuClosed" class by moving it to the left with a transform: translateX(-200px). To make the screen move back to the right, I have added a negative margin right of the same size.
This may not be the best practice - I'm open minded to hear other solutions!
Also, as a plus, I have changed your Javascript code to toggle the class, making it work to open and close on click, instead of opening only.
You can see the new code here, on Codepen. I hope it helps you!
I would like two create two buttons that overlay a div using HTML like the following:
*Both the same DIV with two buttons overlapping each side. So one div with two buttons overlapping.
I would like the buttons to be transparent and overlay the div but I am not sure how.
I have created my Div:
<div class="container">
<div id="slides">
<img src="img/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
</div>
</div>
The div I would like to overlay is called "container" and the two buttons are:
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
Is there any way in CSS or HTML to do this?
You have to place your buttons absolutely on top of your image. To do so, first make .container take a position: relative; and then put your buttons as siblings of your .slides div and place them absolutely.
.container {
position: relative;
}
.slidesjs-navigation {
position: absolute;
top: 0;
display: block;
width: 50%;
height: 100%;
background: rgba(0,0,0,0); /* Added in case you want to transition this */
}
.slidesjs-navigation:hover {
background: rgba(0,0,0,0.25); /* Makes the hovered button visible */
}
.slidesjs-previous {
left: 0;
}
.slidesjs-next {
right: 0; /* left: 50%; works too */
}
.slides img {
display: block; /* Avoids the space usually seen under inline images */
width: 100%; /* Ensures the image takes up the whole width */
}
<div class="container">
<div id="slides" class="slides">
<img src="https://c1.staticflickr.com/5/4147/5087404401_d24513119a_b.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/"><!-- original `src`: "img/example-slide-1.jpg" -->
</div>
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
</div>
Here is a simple way to do it. Put both buttons inside a div with a height:100%, width:50% and float:left;. This way each button takes up the full height of the div but only half of its width. The float:left; will then put them side by side in the div, hopefully achieving what you want!
.box {
border:1px solid black;
height:200px;
width:400px;
background-color:#005680;
}
.button1 {
width:50%;
height:100%;
float:left;
background-color: rgba(0,0,0,0);
border:0px solid black;
}
.button2 {
width:50%;
height:100%;
float:left;
background-color: rgba(0,0,0,0);
border:0px solid black;
}
.button1:hover {
background-color: rgba(10,10,10,0.1);
}
.button2:hover {
background-color: rgba(10,10,10,0.1);
}
<div class="box">
<button class="button1"></button>
<button class="button2"></button>
</div>
This can be your code.
.d {
position:relative;
}
.b1 {
float:left;
height:100px;
width:75px;
}
.b2 {
position:absolute;
left:75px;
height:100px;
width:75px;
}
<div class="d">
<button class="b1"></button>
<button class="b2"></button>
</div>
So basically you would like to create something similar to a toggle button or on/off switch? You could try something like:
HTML:
<div id="toggle">
<a id="left-side" href="">Left</a>
<a id="right-side" href="">Right</a>
</div>
CSS:
<script type="text/css">
DIV#toggle {
width:100px;
height:50px;
margin:0px;
padding:0px;
}
DIV#toggle>A {
display:block;
width:50%;
height:100%;
padding:0px;
text-size:10pt;
text-align:center;
}
DIV#toggle>A#right-side {
margin:0px auto 0px 0px;
background-color:#ff0000;
}
DIV#toggle>A#left-side {
margin:0px 0px 0px auto;
background-color:#00ff00;
}
</script>
Since you mentioned that the buttons are in the div, you can simply position them using position: absolute. By adding position: relative to the container, you can position them within that container rather than within the document as a whole.
/* -------------------------------------------------- --
The part that you actually need
-- -------------------------------------------------- */
/* Allow elements to be positioned relative to the container */
.container {
position: relative;
}
/* Let the buttons both cover the (left) half of the div */
.container .slidesjs-navigation {
position: absolute;
top: 0;
left: 0;
width: 50%; /* Of .container, its positioning parent */
height: 100%; /* Of .container */
}
/* Make an exception for the second button to move it to the right half */
.container .slidesjs-next {
left: 50%;
}
/* -------------------------------------------------- --
The part that's just for the demonstration.
-- -------------------------------------------------- */
/* Make the content large to show that the buttons scale */
#slides {
padding: 50px;
}
/* Make the div red, as in the question */
.container {
background-color: red;
}
/* Have white, semi-transparent buttons with a border, so you see where they are */
.container .slidesjs-navigation {
background-color: white;
border: 1px dashed black;
box-sizing: border-box;
opacity: 0.5;
}
/* Make the buttons opaque on hover to show that they respond */
.container .slidesjs-navigation:hover {
opacity: 1;
}
<div class="container">
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
<div id="slides">
<img src="img/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
</div>
</div>
Hope this is what you were looking for. Happy to explain or help in a better solution if needed.
.container {
width: 100vw;
height: 50vh;
background-image: url('https://c1.staticflickr.com/5/4147/5087404401_d24513119a_n.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
margin: 0;
padding: 0;
}
.container a{
width: 49.5%;
height: 50vh;
margin: 0;
padding: 0;
display: inline-block;
}
.container a:hover{
width: 49.5%;
height: 50vh;
background: rgba(255,255,255,0.4);
margin: 0;
padding: 0;
display: inline-block;
}
<div class="container">
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
</div>