CSS 3 columns - First two fixed width, third remaining width - html

I have 3 columns. left, middle and right.
left and middle are fixed-width, right should fill the remaining space.
How can I accomplish this?
Current HTML
<div id="menu">
<div id="left">
</div>
<div id="middle">
</div>
<div id="right">
</div>
</div>
LESS
#menu {
width: 100%;
#left {
width: 20%;
float: left;
}
#middle {
width: 300px;
float: left;
}
#right {
overflow-x: hidden;
float: right;
}
}

#menu {
width: 100%;
#left {
width: 20%;
float: left;
}
#middle {
width: 300px;
float: left;
}
#right {
width: -webkit-calc(100% - 20% - 300px);
width: -moz-calc(100% - 20% - 300px);
width: -o-calc(100% - 20% - 300px);
width: calc(100% - 20% - 300px);
float: right;
}
}
You must know that calc is still an experimental technology, I suggest you to use javascript instead if you are looking for browser compatibility.

Here is a fiddle with it all working.
It's "small-screen-first" so - if you aren't into that... then you can just delete the #media rule.
It looks like all you really need, is a width auto - and to make sure it's not floated.
HTML
<aside class="container left"><h2>Left</h2></aside>
<section class="container main-content"><h2>Main content</h2></section>
<aside class="container right">
<h2>Right</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et beatae quam quibusdam dolor dolorum vero harum commodi vel quidem quasi sed dolores iusto is</p>
</aside>
CSS
* {
box-sizing: border-box;
}
.container {
width: 100%;
float: left;
}
#media (min-width: 800px) {
.left {
width: 20%;
}
.main-content {
width: 400px;
}
.right {
width: auto;
float: none;
}
}

I think
#right{
width:auto;
float:right;
overflow-x: hidden;
}
has to work.

#middle {
width: 300px;
float: left;
position: relative; /* Show above #right */
}
#right {
width: 80%;
margin-left: -300px; /* equal to width of #middle in px */
padding-left: 300px; /* equal to width of #middle in px */
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow-x: hidden;
float: right;
}

Related

How can I set height=100% without any content in css?

sorry for my English...
I want to make sidebar 100% height of the page. I set html:100% and then height: 100%. but as you see in screenshot the sidebar does not working. and the height is equal to the height of content inside that.
this is css code i wrote for that. I also use viewpoints for sidebar..............
html {
box-sizing: border-box;
height: 100%;
}
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
body {
font-family: Tahoma, sans-serif;
}
body p {
font-family: 'Trebuchet MS', sans-serif;
}
.main {
width: 80%;
height: 100%;
background-color: #243E36;
color: #F1F7ED;
float: left;
position: relative;
}
header {
text-align: center;
margin: 20px auto;
border-bottom: 2px solid #E0EEC6;
width: 30%;
padding-bottom: 15px;
}
header h1 {
color: #C2A83E;
}
header p {
margin-top: 10px;
text-transform: uppercase;
word-spacing: 10px;
letter-spacing: 5px;
}
section {
color: #212121;
padding: 0 20px;
}
article {
width: 50%;
margin-bottom: 30px;
float: left;
}
article h2 {
padding: 15px;
}
article p {
text-align: justify;
padding: 0 15px;
}
footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: #7CA982;
text-align: center;
}
aside {
width: 20%;
min-height: 100%;
max-height: 100%;
background-color: #E0EEC6;
float: left;
}
.group:before,
.group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
zoom: 1;
}
<body>
<div class="container group">
<div class="main">
<!-- Header -->
<header>
<h1>My Personal NoteBook</h1>
<p>Welcome to my page</p>
</header>
<!-- Notes -->
<section class="group">
<article>
<h2>Title 1</h2>
<p>Posted on 2020/07/23</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorum, sequi iusto! Facere, quos
tempore veritatis sit ratione iste perferendis quod possimus voluptatem, quam, non similique
labore quas adipisci corporis libero!</p>
</article>
</section>
<!-- Footer -->
<footer>
<p>©2020 My Nootbook</p>
</footer>
</div>
<!-- Sidebar -->
<aside style="height:100vh;">
<h1>SideBar</h1>
</aside>
</div>
</body>
One way you can do this is by using inline CSS in your sidebar div element
`
<div class="sidenav" style="height:100vh;position: fixed;">
About
Services
Clients
Contact
</div>"
`
I hope this example will give you a better idea.
You issues is you have used 2 floats elements, and float elements won't respect height:100%.
Solution #1: Float 1 div, and another using margin-left
html,body {
height: 100%;
}
.c-container {
height: 100%;
}
.c-content {
float: left;
width: 80%;
}
.c-sidebar {
margin-left: 80%;
height: 100%;
background: red;
}
<div class="c-container">
<div class="c-content ">
content
</div>
<div class="c-sidebar">
sidebar
</div>
</div>
Flex solution:
html,body {
height: 100vh;
}
.c-container {
display: flex;
height: 100%;
}
.c-content {
flex: 1 1 auto;
}
.c-sidebar {
width: 200px;
background: red;
}
<div class="c-container">
<div class="c-content ">
content
</div>
<div class="c-sidebar">
sidebar
</div>
</div>

Same height for boxes in both columns

I'm trying to create a same-height column which was 2 boxes to the left and 1 box to the right. Something on this line where 01 & 02 combined together has the same height as 03:
Demo: https://jsfiddle.net/bptdqx67/2/
HTML
<div class="row">
<div class="col-7">
<div class="h-100">
<div class="thankyou__box blue">
<div class="thankyou__number">
<h4>01</h4>
</div>
<div class="thankyou__content">
<p>This is the first box. This is the first box. This is the first box. This is the first box. This is the first box. This is the first box. This is the first box. </p>
</div>
</div>
<div class="thankyou__box green">
<div class="thankyou__number">
<h4>02</h4>
</div>
<div class="thankyou__content">
<p>This is the second box. This is the second box. This is the second box. This is the second box. This is the second box. This is the second box. This is the second box. </p>
</div>
</div>
</div>
</div>
<div class="col-5">
<div class="thankyou__box green thankyou__height">
<div class="thankyou__number">
<h4>03</h4>
</div>
<div class="thankyou__content">
<p>This is the third box. This is the third box. This is the third box. This is the third box. This is the third box.</p>
</div>
</div>
</div>
</div>
CSS:
* {
box-sizing: border-box;
}
.row::after {
content: "";
clear: both;
display: table;
}
.col {
/*flex: 0 0 20%;
*/
width: 20%;
float: left;
padding: 1px;
}
[class*="col-"] {
float: left;
padding-left: 5px;
padding-right: 5px;
}
.col-1 {
width: 8.33%;
}
.col-2 {
width: 16.66%;
}
.col-3 {
width: 25%;
}
.col-4 {
width: 33.33%;
}
.col-5 {
width: 41.66%;
}
.col-6 {
width: 50%;
}
.col-7 {
width: 58.33%;
}
.col-8 {
width: 66.66%;
}
.col-9 {
width: 75%;
}
.col-10 {
width: 83.33%;
}
.col-11 {
width: 91.66%;
}
.col-12 {
width: 100%;
}
.h-100 {
height: 100%;
}
.thankyou__box {
padding: 15px;
border-radius: 4px;
margin-bottom: 10px;
background-size: 50px;
background-repeat: no-repeat;
background-position: 98% 95%;
}
.thankyou__box.blue {
border: 2px solid #c9f5ff;
}
.thankyou__box.green {
border: 2px solid #c6dc9c;
}
.thankyou__number {
width: 33px;
display: inline-block;
vertical-align: top;
float: left;
}
.thankyou__content {
width: calc(90% - 40px);
display: inline-block;
}
.thankyou__content p {
margin: 0;
}
.thankyou__height {
height: 100%;
background-size: 100px;
background-position: 95% 100%;
}
.thankyou__height .thankyou__content {
width: calc(100% - 33px);
}
Adding display:flex to .row would solve this problem.
Using Grid will greatly simplify your layout rules. Here is a straightforward approach with no dependencies. Once we declare the parent as a grid container, we can create rules for how the children behave.
.right {
grid-column: 2; /* begin at column two */
grid-row: 1 / 3; /* span from the first grid line to the third */
}
With this in place the right column's height will always be the sum of the children in the first column.
.grid {
display: grid;
grid-template-columns: 50% 50%;
grid-template-rows: auto auto;
grid-gap: 2px;
}
.right {
grid-column: 2;
grid-row: 1 / 3;
background-color: red;
}
.grid * {
padding: 1em;
}
.grid *:not(.right) {
background-color: #ccc;
}
<div class="grid">
<div class="top">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis nemo doloremque tempora porro quos natus odio est tenetur facilis commodi voluptatum reprehenderit, in, consequatur pariatur. Voluptatum quam, modi sit. Eos. lorem</div>
<div class="btm">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum ut maiores perspiciatis temporibus quae magni enim quas rerum deserunt expedita voluptas deleniti, labore dolore possimus quis officiis ducimus vel repellat.</div>
<div class="right"></div>
</div>
jsFiddle
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 500px;
width: 100%;
}
.container__inner {
display: flex;
}
.container__col:nth-child(1) {
width: 60%;
margin-right: 30px;
}
.container__col:nth-child(1) .container__item {
height: 100px;
}
.container__col:nth-child(2) {
width: 40%;
}
.container__col:nth-child(2) .container__item {
height: 100%;
}
.container__item {
display: block;
border-radius: 4px;
border: 2px solid green;
margin-bottom: 30px;
width: 100%;
}
.container__item:last-of-type {
margin-bottom: 0;
}
<div class="container">
<div class="container__inner">
<div class="container__col">
<div class="container__item"></div>
<div class="container__item"></div>
</div>
<div class="container__col">
<div class="container__item"></div>
</div>
</div>
</div>

HTML and CSS help having 3 elements responsive like this

I want 3 elements in line. First two being aligned to the left and the third one being align to right.When the window is smaller i want the second going under the first while the third remains in the right, when the window gets even smaller all three under each other.
Here is an example:
https://www.backyardburgers.com/
I want to make the red thing under the header with those three elements an h2 a p and an anchor wich is the button.
I would like if you could show me what css to use if the html is the following:
<section class="location">
<div class="content">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, copiosae perpetua voluptaria in pro, laboramus scriptorem instructior in usu, duo expetenda delicatissimi in. </p>
<a class="button" href="#">Sale sonet</a>
</div></section>
Example code with 3 divs
CSS ::::
div {
height: 200px;
width: 200px;
border: 1px solid white;
display: inline-block;
}
#media only screen and (max-width: 500px) {
div {
width: 100%;
}
}
#media screen and (max-width: 900px) and (min-width: 500px) {
div {
display: block;
}
.first, .second {
width: calc(100% - 200px);
}
.third{
position: fixed;
top: 8px;
right: 5px;
width: 200px;
}
}
#media screen and (min-width: 900px) {
div{
display: inline-block;
}
.first {
float: left;
}
.second {
width: calc(100% - 410px);
}
.third {
float: right;
}
}
Here is a simple turnaround :
.location {
background: #d00807;
color: #fff;
padding: 20px;
position: relative;
}
.location h2 {
display: inline-block;
margin: 0px;
vertical-align: middle;
}
.location p {
display: inline-block;
margin: 0px;
margin-left: 10px;
vertical-align: middle;
}
.location a.button {
background: transparent;
border: 1px solid #fff;
text-decoration: none;
color: #fff;
padding: 10px;
position: absolute;
right: 20px;
top: 50%;
margin-top: -20px;
}
#media (max-width:768px) {
.location h2 {
display: block;
margin-bottom: 10px;
}
.location p {
width: 50%;
margin-left: 0px;
}
}
<section class="location">
<div class="content">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, copiosae perpetua voluptaria in pro, laboramus scriptorem instructior in usu, duo expetenda delicatissimi in. </p>
<a class="button" href="#">Sale sonet</a>
</div>
</section>

DIVs don't line up

I have created a jsfiddle for you to see what I'm doing.
https://jsfiddle.net/pksml/3mp1Lnw8/5/
#page-wrapper {
margin-left: 205px;
background-color: green;
}
The menu wrapper (orange) and the page wrapper (green) should both be at the top of the content wrapper (blue). But the green block looks to have a top margin (which it doesn't).
My question is this: why don't the orange and green blocks both line up at the top of the blue block?
Is some of my CSS code wrong? Thanks for your input!
It is the default margin of p tag which is pushing the green div down.
HTML {
background: #cccccc;
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
#bounding-wrapper {
min-width: 320px;
width: 100%;
padding: 10px;
}
#content-wrapper {
width: 100%;
margin: 0px;
padding: 0px;
overflow: auto;
height: auto !important;
background-color: blue;
}
#menu-wrapper {
width: 200px;
background-color: orange;
float: left;
}
#page-wrapper {
margin-left: 205px;
background-color: green;
}
p{
margin: 0 0 20px;
}
<div id="bounding-wrapper">
<div id="content-wrapper">
<div id="menu-wrapper">
this is in the menu wrapper
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fuga dolores voluptatibus itaque dolor quod.</p>
</div>
<!-- menu wrapper -->
<div id="page-wrapper">
<p>this is in the page wrapper</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum repellendus eum delectus deserunt molestiae cum,
</div>
<!-- page wrapper -->
</div>
<!-- content wrapper -->
</div>
<!-- bounding wrapper -->
You need to float both menu-wrapper and page-wrapper.
Looks like from your addition of the right margin you are trying to position the left menu? If so you could do something like this: https://jsfiddle.net/jgoley/98abyyp2/
jsfiddle
#page-wrapper {
float:left;
background-color: green;
}
use float:left instead of marigin left
I think the code below should work for you!
All I added was display: inline-block; to #menu-wrapper and #page-wrapper.
All I removed was the float: left; from #menu-wrapper and margin-left: 205; from #page-wrapper.
HTML {
background: #cccccc;
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
#bounding-wrapper {
min-width: 320px;
width: 100%;
padding: 10px;
}
#content-wrapper {
width: 100%;
margin: 0px;
padding: 0px;
overflow: auto;
height: auto !important;
background-color: blue;
}
#menu-wrapper {
width: 200px;
background-color: orange;
display: inline-block;
}
#page-wrapper {
background-color: green;
display: inline-block;
}
<div id="bounding-wrapper">
<div id="content-wrapper">
<div id="menu-wrapper">
this is in the menu wrapper
</div>
<!-- menu wrapper -->
<div id="page-wrapper">
<p>this is in the page wrapper</p>
</div>
<!-- page wrapper -->
</div>
<!-- content wrapper -->
</div>
<!-- bounding wrapper -->
Hope that helped!
you have two solutions,
you can set the display property of the #page-wrapper to be
display:inline-block
if you don't want to change its display property for any reason so
you can add float:left to the #page-wrapper as well
then no need for margin-left:205px in #page-wrapper
http://codepen.io/craigiswayne/pen/mPxJqv
** Makes use of flex box **
CSS:
.block{
width:100px;
height:100px;
background-color:#8BC34A;
}
.block.fill{
background-color:#F44336;
-webkit-flex: 1;
flex: 1;
}
.container {
display: -webkit-flex;
display: flex;
width:100%;
}

How to get inner div at the top of outer div

I have this situation:
I want the table on the right side to be at the same height as the form on the left side.
Here is my CSS:
.left {
height: auto;
width: 550px;
}
.right {
height: auto;
width: 550px;
padding-left: 40px;
}
.innerRight {
height: auto;
}
.middle {
height: auto;
position:absolute;
left:50%;
top:17%;
bottom:15%;
border-left:1px solid grey;
}
.left, .right {
display: inline-block;
}
How can I do this?
I used floating, but then the height doesn't adjust automatically, so I can't used it.
You could give them both position:absolute; then position them with top, left, right, ect..
Without your actual HTML code, here is an example that might help you by using the table-row, table-cell css property.
.wrap {
overflow: hidden;
width: 250px;
display: table;
border-collapse: collapse;
}
.row {
display: table-row;
}
.left {
width: 50%;
display: table-cell;
background-color: yellow;
}
.middle {
border-left: solid 1px red;
width: 1px;
display: table-cell;
}
.right {
width: 50%;
background-color: orange;
display: table-cell;
}
<div class="wrap">
<div class="row">
<div class="left">Lorem</div>
<div class="middle"></div>
<div class="right">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br/>
<br/>
<br/>
<br/>
<br/>
</div>
</div>
</div>