How to change flex column width while keeping item centered - html

I have a flexbox in my HTML, and I have two columns. What I have trouble doing is changing the right column's width. If I set the width to, say, width: 50%, the .container is no longer centered on the page, and the Google Maps size is also changed. I am trying to shrink the .container size but keep the whole flexbox centered on the page and the size of the maps the same. Any help would be greatly appreciated.
#google-maps
{
background: #FFFFFF;
}
.hours-and-location
{
}
#hours-and-location-container
{
display: flex;
flex-direction: row;
justify-content: center;
margin: 3em;
width: 50%;
}
.column
{
display: flex;
flex-direction: column;
margin: 1em;
}
.locations
{
width: 100%;
}
.page-title-header
{
text-align: center;
}
<h1 class="page-title-header">
Hours and Locations
</h1>
<div id="hours-and-location-container">
<iframe class="column" id="google-maps"
src="https://www.google.com/maps/d/u/0/embed?mid=1_iD-tpjnLUFwGIWoEcsx05qBgbx112w&ehbc=2E312F"
width="600" height="500">
</iframe>
<div class="hours-and-location">
<div class="locations column">
<h2>
Locations
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
</p>
<p>
Augue mauris augue neque gravida in. Est sit amet facilisis magna. In vitae turpis massa sed
elementum tempus egestas sed.
</p>
<p>
Lectus quam id leo in vitae turpis massa sed.
</p>
<p>
Imperdiet proin fermentum leo vel orci porta non pulvinar. A iaculis at erat pellentesque adipiscing
commodo elit at imperdiet. Semper eget duis at tellus at urna condimentum. Purus in massa tempor
nec feugiat nisl.
</p>
</div>
<div class="hours">
</div>
</div>
</div>

I think you're looking for this
#google-maps
{
background: #FFFFFF;
}
.hours-and-location
{
width:40vh
}
#hours-and-location-container
{
display: flex;
flex-direction: row;
justify-content: center;
align-items:center;
margin: 3em;
}
.column
{
margin: 1em;
}
.page-title-header
{
text-align: center;
}
<h1 class="page-title-header">
Hours and Locations
</h1>
<div id="hours-and-location-container">
<iframe class="column" id="google-maps"
src="https://www.google.com/maps/d/u/0/embed?mid=1_iD-tpjnLUFwGIWoEcsx05qBgbx112w&ehbc=2E312F"
width="600" height="500">
</iframe>
<div class="hours-and-location">
<div class="locations column">
<h2>
Locations
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
</p>
<p>
Augue mauris augue neque gravida in. Est sit amet facilisis magna. In vitae turpis massa sed
elementum tempus egestas sed.
</p>
<p>
Lectus quam id leo in vitae turpis massa sed.
</p>
<p>
Imperdiet proin fermentum leo vel orci porta non pulvinar. A iaculis at erat pellentesque adipiscing
commodo elit at imperdiet. Semper eget duis at tellus at urna condimentum. Purus in massa tempor
nec feugiat nisl.
</p>
</div>
<div class="hours">
</div>
</div>
</div>

you can assign a max- width on your flex div then wrap them in a another div that control to center them like below.
#google-maps
{
background: #FFFFFF;
}
.hours-and-location
{
}
#hours-and-location-container
{
display: flex;
flex-direction: row;
justify-content: center;
margin: 3em;
max-width: 700px;
gap: 10px;
}
.wrapper {
display:flex;
justify-content: center;
}
.column
{
display: flex;
flex-direction: column;
margin: 1em;
}
.locations
{
width: 100%;
}
.page-title-header
{
text-align: center;
}
<h1 class="page-title-header">
Hours and Locations
</h1>
<div class="wrapper">
<div id="hours-and-location-container">
<iframe class="column" id="google-maps"
src="https://www.google.com/maps/d/u/0/embed?mid=1_iD-tpjnLUFwGIWoEcsx05qBgbx112w&ehbc=2E312F"
width="600" height="500">
</iframe>
<div class="hours-and-location">
<div class="locations column">
<h2>
Locations
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
</p>
<p>
Augue mauris augue neque gravida in. Est sit amet facilisis magna. In vitae turpis massa sed
elementum tempus egestas sed.
</p>
<p>
Lectus quam id leo in vitae turpis massa sed.
</p>
<p>
Imperdiet proin fermentum leo vel orci porta non pulvinar. A iaculis at erat pellentesque adipiscing
commodo elit at imperdiet. Semper eget duis at tellus at urna condimentum. Purus in massa tempor
nec feugiat nisl.
</p>
</div>
<div class="hours">
</div>
</div>
</div>
</div>

Well, I have given margin: 0 auto; for making it to centre in any width from left to right it always takes the element to centre from the left and right. I hope this might will help or you are looking for something else?
#google-maps
{
background: #FFFFFF;
}
.hours-and-location
{
}
#hours-and-location-container
{
display: flex;
flex-direction: row;
justify-content: center;
margin: 3em;
width: 50%;
margin: 0 auto;
}
.column
{
display: flex;
flex-direction: column;
margin: 1em;
}
.locations
{
width: 100%;
}
.page-title-header
{
text-align: center;
}
<h1 class="page-title-header">
Hours and Locations
</h1>
<div id="hours-and-location-container">
<iframe class="column" id="google-maps"
src="https://www.google.com/maps/d/u/0/embed?mid=1_iD-tpjnLUFwGIWoEcsx05qBgbx112w&ehbc=2E312F"
width="600" height="500">
</iframe>
<div class="hours-and-location">
<div class="locations column">
<h2>
Locations
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
</p>
<p>
Augue mauris augue neque gravida in. Est sit amet facilisis magna. In vitae turpis massa sed
elementum tempus egestas sed.
</p>
<p>
Lectus quam id leo in vitae turpis massa sed.
</p>
<p>
Imperdiet proin fermentum leo vel orci porta non pulvinar. A iaculis at erat pellentesque adipiscing
commodo elit at imperdiet. Semper eget duis at tellus at urna condimentum. Purus in massa tempor
nec feugiat nisl.
</p>
</div>
<div class="hours">
</div>
</div>
</div>

Related

Styling side by side elements

I have figured out how to set two HTML elements side by side. I want to have a text paragraph on the left and an image on the right.
Currently, my code is:
<!DOCTYPE html>
<html>
<style>
</style>
<body>
<div style="width: 50%; height: 100px; float: left;" >
<h2> What We Do</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Morbi tincidunt ornare massa eget egestas. Vel eros donec ac odio tempor. Est velit egestas dui id ornare arcu odio ut sem. Urna porttitor rhoncus dolor purus non enim praesent elementum facilisis.</p>
</div>
<div style="margin-left:50%; "><img style=" max-width: 100%; height: auto;" src="https://images.designtrends.com/wp-content/uploads/2016/04/06094112/Beautiful-Mountain-HD-Backgrounds.jpg" >
</div>
</div>
</body>
</html>
This is results in an two column layout, but I want to know how to format.
I want to add padding to the text, but when I do so, the image is messed up completely. How can I padding padding to my text so that there is space around it? I tried to add padding:20px; to the <div> that has the text which doesn't work.
<div style="width: 50%; height: 100px; float: left; padding:20px;">
<h2> What We Do</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Morbi tincidunt ornare massa eget egestas. Vel eros donec ac odio tempor. Est velit egestas dui id ornare arcu odio ut sem. Urna porttitor rhoncus dolor purus non enim praesent elementum facilisis.</p>
</div>
Use Grid with a media query for smaller screens:
article {
display: grid;
}
div {
padding: 0.5em;
}
img {
width: 100%;
}
#media (min-width: 400px) {
article {
grid-template-columns: 50% 50%;
}
}
<article>
<div>
<h2> What We Do</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Morbi tincidunt ornare massa eget egestas. Vel eros donec ac odio tempor. Est velit egestas dui id ornare arcu odio ut sem.
Urna porttitor rhoncus dolor purus non enim praesent elementum facilisis.</p>
</div>
<img src="https://images.designtrends.com/wp-content/uploads/2016/04/06094112/Beautiful-Mountain-HD-Backgrounds.jpg">
</article>
use box-sizing:border-box, after applying padding, so the padding will be calculated within the width
For more info Reference
<div style="width: 50%; height: 100px; float: left; padding:20px;box-sizing:border-box" >
<h2> What We Do</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Morbi tincidunt ornare massa eget egestas. Vel eros donec ac odio tempor. Est velit egestas dui id ornare arcu odio ut sem. Urna porttitor rhoncus dolor purus non enim praesent elementum facilisis.</p>
</div>
<div style="margin-left:50%; "><img style=" max-width: 100%; height: auto;" src="https://images.designtrends.com/wp-content/uploads/2016/04/06094112/Beautiful-Mountain-HD-Backgrounds.jpg" >
</div>
</div>
The best way to do this is to wrap both <div> inside a flex-box. And adding border-box as value for box-sizing property. You can read more about box-sizing here: Box Sizing and about Flex Box here. Both are pretty useful to placing items side by side.
Here is a sample code.
<!DOCTYPE html>
<html>
<style>
* {
box-sizing: border-box;
}
</style>
<body>
<div style="display: flex; flex-direction: row; width: 100%;">
<div style="width: 50%; height: 100px; padding:20px;">
<h2> What We Do</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore
magna aliqua. Morbi tincidunt ornare massa eget egestas. Vel eros donec ac odio tempor. Est velit
egestas
dui id ornare arcu odio ut sem. Urna porttitor rhoncus dolor purus non enim praesent elementum
facilisis.
</p>
</div>
<div style="width: 50%; padding: 20px;">
<img style=" max-width: 100%; height: auto;"
src="https://images.designtrends.com/wp-content/uploads/2016/04/06094112/Beautiful-Mountain-HD-Backgrounds.jpg" />
</div>
</div>
</body>
</html>
The box-sizing will prevent your image from changing position when adding padding to the div. And flex-box is much better way to position things instead of float as it offers more functionality and can also position things vertically.
Here is another great article related to Flex Box - Must Read.
You can use this example for side by side
.flex-container {
display: flex;
}
.flex-child {
flex: 1;
border: 2px solid yellow;
}
.flex-child:first-child {
margin-right: 20px;
}
<div class="flex-container">
<div class="flex-child magenta">
Flex Column 1
</div>
<div class="flex-child green">
Flex Column 2
</div>
</div>
Using flex makes it really simple to control the layout.
.container {
display: flex;
height: max-content;
gap: 1rem;
}
.flex-item {
flex: 1;
width: 50%;
}
.info {
height: 100px;
padding: 20px;
}
.image {
display: inline-block;
height: 150px;
width: 250px;
padding: 20px;
}
<div class="container">
<div class="flex-item info">
<h2> What We Do</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Morbi tincidunt ornare massa eget egestas. Vel eros donec ac odio tempor. Est velit egestas dui id ornare arcu odio ut sem.
Urna porttitor rhoncus dolor purus non enim praesent elementum facilisis.</p>
</div>
<div class="flex-item">
<div><img class="image" src="https://images.designtrends.com/wp-content/uploads/2016/04/06094112/Beautiful-Mountain-HD-Backgrounds.jpg">
</div>
</div>
</div>

Why does the width of my web page extend beyond my viewport?

I have this web page. All the content of the web page is within the size of my desktop's view port. However, the width of the page still goes beyond the view port. I even tried putting margin and padding at 0 but nothing worked. It also looks especially awkward in mobile view. How do I fix that?
Below is the code:
:root {
--main-color:#ff9955ff;
--secondary-color:yellow;
--dark-color:#444;
--light-color:#fafafa;
}
body {
font-family: Montserrat, sans-serif;
background: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin: 0px;
padding: 0px;
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
font-size: 18px;
}
::selection {
background: var(--main-color);
color: var(--light-color);
}
a {
text-decoration: none;
color: var(--dark-color);
}
input {
box-sizing: border-box;
}
.box {
background: red;
height: 100px;
width: 100px;
}
.center-text {
text-align: center;
}
.columns-two, .columns-three, .columns-four, .columns-six {
display: flex;
flex-direction: row;
align-items: center;
align-content: center;
justify-content: center;
gap: 30px;
}
.columns-two div {
width: clamp(480px, 480px, 100%);
}
.columns-three div {
width: clamp(200px, calc((1000px - (30px * 2)) / 3), 100%);
}
.columns-four div {
width: calc((1000px - (30px * 3)) / 4);
}
.columns-six div {
width: calc((1000px - (30px * 5)) / 6);
}
.horizontal {
display: flex;
align-items: center;
align-content: center;
justify-content: center;
gap: 20px;
}
.max-height {
min-height: 100vh;
}
.half-height {
min-height: calc(100vh / 2);
}
.max-width {
width: clamp(200px, 90vw, 1000px);
}
.vertical {
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
justify-content: center;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
/* header */
.header {
height: 70px;
justify-content: space-between;
}
.title {
height: 100%;
}
.title img {
height: 100%;
width: clamp(0px,250px,60%);
}
.nav-toggle-checkbox, .nav-toggle-spans {
position: fixed;
top: 2.5%;
right: -100vw;
height: clamp(10px,80px,20vw);
width: clamp(10px,80px,20vw);
}
.nav-toggle-checkbox {
opacity: 0;
}
.nav-toggle-spans span {
height: 20%;
background: var(--main-color);
margin: 10% 0;
display:flex;
flex-direction: row;
z-index: 2;
transition: 400ms;
}
.navbar {
display: flex;
gap: 2.5px;
transition: 300ms;
}
.navbar a {
margin: 5px;
}
/* footer */
footer {
background: var(--main-color);
width: 100vw;
padding: 20px 0;
text-align: center;
}
.socials {
gap: 10px;
}
footer img {
height: 50px;
width: 50px;
}
#media screen and (max-width:700px) {
.nav-toggle-checkbox, .nav-toggle-spans {
right: 5%;
transition: 400ms;
}
.nav-toggle-spans {
z-index: 2;
}
.nav-toggle-checkbox {
z-index: 3;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans span {
background: var(--light-color);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-one {
position: relative;
top: 30%; /* Changed from 100% */
transform: rotate(45deg);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-two {
opacity: 0;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-three {
position: relative;
top: -30%;
transform: rotate(-45deg);
transition: 400ms;
}
.navbar, .nav-toggle-checkbox:not(:checked) ~ .navbar {
position:fixed;
top: 0;
right: -100vh;
height: 100%;
display: flex;
flex-direction: column;
justify-content:flex-start;
background: var(--main-color);
opacity: 90%;
border-left: 4px solid var(--secondary-color);
padding: 150px 5% 0 50px;
z-index: 1;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar {
right: 0;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar a {
color: var(--light-color);
text-align: right;
font-size: 1.25em;
}
}
<body tabindex="-1">
<div id="svelte">
<body>
<div class="max-width">
<header class="header horizontal">
<div class="title"><img loading="lazy" src="./logo-title.svg" alt="Title"></div> <input type="checkbox" class="nav-toggle-checkbox">
<div class="nav-toggle-spans"><span class="nav-span-one"></span> <span class="nav-span-two"></span> <span class="nav-span-three"></span></div>
<nav class="navbar">Home Elements Services Contact</nav>
</header>
<!--<Header>-->
<head>
<title>Home - CSS Templates</title>
</head>
<section class="vertical">
<h2>2 Columns</h2>
<div class="wrap columns-two">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
</div>
</section>
<!--<ColumnsTwo>-->
<section class="vertical max-height">
<h2>3 Columns</h2>
<div class="wrap columns-three">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
</div>
</section>
<!--<ColumnsThree>-->
<section class="vertical">
<hr>
<h2>4 Columns</h2>
<div class="wrap columns-four">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsFour>-->
<section class="vertical">
<hr>
<h2>6 Columns</h2>
<div class="wrap columns-six">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsSix>-->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Amet luctus venenatis lectus
magna fringilla urna porttitor rhoncus dolor. Nisi quis eleifend quam
adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet consectetur
adipiscing. Eu consequat ac felis donec et odio pellentesque diam. Volutpat
commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Sem et
tortor consequat id porta nibh venenatis cras. Sed faucibus turpis in eu mi
bibendum neque egestas congue. Etiam non quam lacus suspendisse faucibus
interdum posuere lorem. Malesuada fames ac turpis egestas maecenas pharetra.
Lorem ipsum dolor sit amet consectetur. Ut enim blandit volutpat maecenas
volutpat blandit aliquam etiam erat. Id aliquet risus feugiat in ante metus.</p>
<footer>
<p class="socials"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook"></p>
<p>This website was designed by Name</p>
</footer>
</body>
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true" class="s-jHz34e3aRDB7"></div>
</div>
</body>
Go to the top of the CSS and put "* {width: 100%}". If that doesn't work, you might have to manually change the width until it fits the size of your viewport.
Please mark this as an answer if this helped you.
Change the footer CSS width unit from vw to %:
footer {
background: var(--main-color);
width: 100%;
padding: 20px 0;
text-align: center;
}
:root {
--main-color: #ff9955ff;
--secondary-color: yellow;
--dark-color: #444;
--light-color: #fafafa;
}
body {
font-family: Montserrat, sans-serif;
background: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin: 0px;
padding: 0px;
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
font-size: 18px;
}
#svelte {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: center;
justify-content: center;
align-items: center;
}
::selection {
background: var(--main-color);
color: var(--light-color);
}
a {
text-decoration: none;
color: var(--dark-color);
}
input {
box-sizing: border-box;
}
.box {
background: red;
height: 100px;
width: 100px;
}
.center-text {
text-align: center;
}
.columns-two,
.columns-three,
.columns-four,
.columns-six {
display: flex;
flex-direction: row;
align-items: center;
align-content: center;
justify-content: center;
gap: 30px;
}
.columns-two div {
width: clamp(480px, 480px, 100%);
}
.columns-three div {
width: clamp(200px, calc((1000px - (30px * 2)) / 3), 100%);
}
.columns-four div {
width: calc((1000px - (30px * 3)) / 4);
}
.columns-six div {
width: calc((1000px - (30px * 5)) / 6);
}
.horizontal {
display: flex;
align-items: center;
align-content: center;
justify-content: center;
gap: 20px;
}
.max-height {
min-height: 100vh;
}
.half-height {
min-height: calc(100vh / 2);
}
.max-width {
width: clamp(200px, 90vw, 1000px);
}
.vertical {
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
justify-content: center;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
/* header */
.header {
height: 70px;
justify-content: space-between;
}
.title {
height: 100%;
}
.title img {
height: 100%;
width: clamp(0px, 250px, 60%);
}
.nav-toggle-checkbox,
.nav-toggle-spans {
position: fixed;
top: 2.5%;
right: -100vw;
height: clamp(10px, 80px, 20vw);
width: clamp(10px, 80px, 20vw);
}
.nav-toggle-checkbox {
opacity: 0;
}
.nav-toggle-spans span {
height: 20%;
background: var(--main-color);
margin: 10% 0;
display: flex;
flex-direction: row;
z-index: 2;
transition: 400ms;
}
.navbar {
display: flex;
gap: 2.5px;
transition: 300ms;
}
.navbar a {
margin: 5px;
}
/* footer */
footer {
background: var(--main-color);
width: 100vw;
padding: 20px 0;
text-align: center;
}
.socials {
gap: 10px;
}
footer img {
height: 50px;
width: 50px;
}
#media screen and (max-width: 700px) {
.nav-toggle-checkbox,
.nav-toggle-spans {
right: 5%;
transition: 400ms;
}
.nav-toggle-spans {
z-index: 2;
}
.nav-toggle-checkbox {
z-index: 3;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans span {
background: var(--light-color);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-one {
position: relative;
top: 30%; /* Changed from 100% */
transform: rotate(45deg);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-two {
opacity: 0;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-three {
position: relative;
top: -30%;
transform: rotate(-45deg);
transition: 400ms;
}
.navbar,
.nav-toggle-checkbox:not(:checked) ~ .navbar {
position: fixed;
top: 0;
right: -100vh;
height: 100%;
display: flex;
flex-direction: column;
justify-content: flex-start;
background: var(--main-color);
opacity: 90%;
border-left: 4px solid var(--secondary-color);
padding: 150px 5% 0 50px;
z-index: 1;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar {
right: 0;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar a {
color: var(--light-color);
text-align: right;
font-size: 1.25em;
}
}
<body tabindex="-1">
<div id="svelte">
<body>
<div class="max-width">
<header class="header horizontal">
<div class="title"><img loading="lazy" src="./logo-title.svg" alt="Title"></div> <input type="checkbox" class="nav-toggle-checkbox">
<div class="nav-toggle-spans"><span class="nav-span-one"></span> <span class="nav-span-two"></span> <span class="nav-span-three"></span></div>
<nav class="navbar">Home Elements Services Contact</nav>
</header>
<!--<Header>-->
<head>
<title>Home - CSS Templates</title>
</head>
<section class="vertical">
<h2>2 Columns</h2>
<div class="wrap columns-two">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
</div>
</section>
<!--<ColumnsTwo>-->
<section class="vertical max-height">
<h2>3 Columns</h2>
<div class="wrap columns-three">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
</div>
</section>
<!--<ColumnsThree>-->
<section class="vertical">
<hr>
<h2>4 Columns</h2>
<div class="wrap columns-four">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsFour>-->
<section class="vertical">
<hr>
<h2>6 Columns</h2>
<div class="wrap columns-six">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsSix>-->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Amet luctus venenatis lectus
magna fringilla urna porttitor rhoncus dolor. Nisi quis eleifend quam
adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet consectetur
adipiscing. Eu consequat ac felis donec et odio pellentesque diam. Volutpat
commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Sem et
tortor consequat id porta nibh venenatis cras. Sed faucibus turpis in eu mi
bibendum neque egestas congue. Etiam non quam lacus suspendisse faucibus
interdum posuere lorem. Malesuada fames ac turpis egestas maecenas pharetra.
Lorem ipsum dolor sit amet consectetur. Ut enim blandit volutpat maecenas
volutpat blandit aliquam etiam erat. Id aliquet risus feugiat in ante metus.</p>
</body>
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true" class="s-jHz34e3aRDB7"></div>
</div>
<footer>
<p class="socials"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
</p>
<p>This website was designed by Name</p>
</footer>
</body>

I want to move in my navigation bar in a non gimmicky way

I'm quite very new to HMTL and CSS, having just coded in C# before.
I got this fiddle here
https://jsfiddle.net/4asrj9x6/24/
<html>
<header>
<body>
<nav>
<ul class="navigation">
<li>Home</li>
<li>Contact</li>
<li>About</li>
</ul>
</nav>
</header>
<main class="grid">
<aside></aside>
<section>
<h1>Header</h1>
<img src="https://via.placeholder.com/620x350.jpg">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Est ultricies integer quis auctor elit sed vulputate mi. Aenean pharetra magna ac
placerat vestibulum. Velit euismod in pellentesque massa. Bibendum neque egestas congue quisque egestas
diam in arcu. Curabitur gravida arcu ac tortor dignissim convallis aenean et tortor. Sit amet mauris
commodo quis imperdiet massa. Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper.
</p>
</section>
<section>
<h1>Header</h1>
<img src="http://placehold.it/620x350.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Est ultricies integer quis auctor elit sed vulputate mi. Aenean pharetra magna ac
placerat vestibulum. Velit euismod in pellentesque massa. Bibendum neque egestas congue quisque egestas
diam in arcu. Curabitur gravida arcu ac tortor dignissim convallis aenean et tortor. Sit amet mauris
commodo quis imperdiet massa. Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper.
</p>
</section>
<section>
<h1>Header</h1>
<img src="http://placehold.it/620x350.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Est ultricies integer quis auctor elit sed vulputate mi. Aenean pharetra magna ac
placerat vestibulum. Velit euismod in pellentesque massa. Bibendum neque egestas congue quisque egestas
diam in arcu. Curabitur gravida arcu ac tortor dignissim convallis aenean et tortor. Sit amet mauris
commodo quis imperdiet massa. Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper.
</p>
</section>
<aside></aside>
</main>
</body>
</html>
* {
box-sizing: border-box;
}
header {
margin-top: none;
width: 100%;
height: 80px;
filter: drop-shadow(0px 8px 8px hsla(0, 0%, 0%, 0.24));
background-color: whitesmoke;
}
header nav {
display: flex;
justify-content: flex-end;
height: 100%;
}
.navigation {
list-style-type: none;
display: inline;
}
li a{
display: block;
text-align: center;
text-decoration: none;
}
.navigation li {
display: inline-flex;
height: 100%;
padding: 10px;
font-size: 24px;
}
main {
display: grid;
grid-template-columns: 20% 20% 20% 20% auto;
grid-gap: 20px;
}
aside {
margin: none;
}
section h1 {
text-align: center;
font-size: 24;
font-weight: bold;
}
section img {
width: 100%;
}
section img:hover {
opacity: 50%;
transition: 0.1s;
}
section p {
font-size: 18px;
}
What I want to accomplish is to move in my nav bar links from the right edge. So that the end of 'About' is sort of aligned with the end of the third image.
What I've tried is to add a lot of padding to the navigation class. However this feels super gimmicky and it doesn't scale well at all. Since as soon as you move the window even a tiny bit it goes all wrong.
There should be a better way to do this but I feel kind of stuck.
You have to give your nav-bar a width to work with, since you have justify-content set to flex-end it will always be on the end depending on the width you have set.
Give your nav-bar a reasonable width and line in up with the third image.
Final code:
header nav {
display: flex;
justify-content: flex-end;
height: 100%;
width: --your-desirable-width;
margin-right: auto;
}
This is responsable and it'll always be ..% of the screen.
so this should be what you are looking for, I have used css position: sticky; and have added only 2 lines of code in the styling of the header
<html>
<body>
<style>
* {
box-sizing: border-box;
}
header {
margin-top: none;
width: 100%;
height: 80px;
filter: drop-shadow(0px 8px 8px hsla(0, 0%, 0%, 0.24));
background-color: whitesmoke;
position: sticky;
top: 0;
}
header nav {
display: flex;
justify-content: flex-end;
height: 100%;
}
.navigation {
list-style-type: none;
display: inline;
}
li a{
display: block;
text-align: center;
text-decoration: none;
}
.navigation li {
display: inline-flex;
height: 100%;
padding: 10px;
font-size: 24px;
}
main {
display: grid;
grid-template-columns: 20% 20% 20% 20% auto;
grid-gap: 20px;
}
aside {
margin: none;
}
section h1 {
text-align: center;
font-size: 24;
font-weight: bold;
}
section img {
width: 100%;
}
section img:hover {
opacity: 50%;
transition: 0.1s;
}
section p {
font-size: 18px;
}
</style>
<header>
<nav>
<ul class="navigation">
<li>Home</li>
<li>Contact</li>
<li>About</li>
</ul>
</nav>
</header>
<main class="grid">
<aside></aside>
<section>
<h1>Header</h1>
<img src="https://via.placeholder.com/620x350.jpg">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Est ultricies integer quis auctor elit sed vulputate mi. Aenean pharetra magna ac
placerat vestibulum. Velit euismod in pellentesque massa. Bibendum neque egestas congue quisque egestas
diam in arcu. Curabitur gravida arcu ac tortor dignissim convallis aenean et tortor. Sit amet mauris
commodo quis imperdiet massa. Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper.
</p>
</section>
<section>
<h1>Header</h1>
<img src="http://placehold.it/620x350.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Est ultricies integer quis auctor elit sed vulputate mi. Aenean pharetra magna ac
placerat vestibulum. Velit euismod in pellentesque massa. Bibendum neque egestas congue quisque egestas
diam in arcu. Curabitur gravida arcu ac tortor dignissim convallis aenean et tortor. Sit amet mauris
commodo quis imperdiet massa. Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper.
</p>
</section>
<section>
<h1>Header</h1>
<img src="http://placehold.it/620x350.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Est ultricies integer quis auctor elit sed vulputate mi. Aenean pharetra magna ac
placerat vestibulum. Velit euismod in pellentesque massa. Bibendum neque egestas congue quisque egestas
diam in arcu. Curabitur gravida arcu ac tortor dignissim convallis aenean et tortor. Sit amet mauris
commodo quis imperdiet massa. Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper.
</p>
</section>
<aside></aside>
</main>
</body>
</html>

Why does position:fixed on the right and left containers break this layout?

I want the containers to stick while you scroll down the page, but when I add "position:fixed" it breaks the layout for some reason, making everything go over to the left. i added the code with position:fixed added to the containers, and here's an example of what it's supposed to look like without:
enter image description here
body {
font-family: arial;
background: #222;
}
img {
width: 100%;
display: block;
}
#wrapper {
width: 1000px;
margin: 100px 0 100px 0;
}
#container_left {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
float: left;
position: fixed;
}
.post {
border: 1px solid red;
background: #fff;
font-size: 20px;
padding: 10px;
width: 500px;
height: auto;
text-align: center;
float: left;
margin: 0 80px 0 80px;
}
#container_right {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
float: left;
position: fixed;
}
.text_container {
border: 1px solid red;
margin: 10px 10px 10px 10px;
}
.text {
vertical-align: bottom;
}
.text p {
margin: 0;
}
<body>
<div align="center">
<div id="wrapper">
<div id="container_left">
<div class="text_container">
<div class="text">
{block:Description}
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Description}</div>
{/block:Description}
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container left -->
<div class="post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
</div> <!-- post -->
<div id="container_right">
<div class="text_container">
<div class="text">
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Extra Box}</div>
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container right -->
</div> <!-- wrapper -->
</div> <!-- center -->
</body>
I have found some issues and have fixed that. Some points that I have noticed are.
Specify right/left with bottom/top values for fixed positioned elements to make them fixed at a position.
Use margin: 0 auto inorder to align the center portion.
Never make use of float along with margin: 0 auto. Using float will prevent margin: 0 auto from its desired behaviour.
Hope this is helpful.
body {
font-family: arial;
background: #222;
}
img {
width: 100%;
display: block;
}
#wrapper {
/* width: 1000px;
margin: 100px 0 100px 0; */
width: 100%; /* Use your desired width*/
}
#container_left {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
position: fixed;
left: 0;
top: 0;
}
.post {
border: 1px solid red;
background: #fff;
font-size: 20px;
padding: 10px;
width: 500px;
height: auto;
text-align: center;
/* float: left; :Using float will break the margin:0 auto to break*/
margin: 0 auto;
}
#container_right {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
/* float: left; :Using float will break the margin:0 auto to break*/
position: fixed;
right: 0;
top: 0;
}
.text_container {
border: 1px solid red;
margin: 10px 10px 10px 10px;
}
.text {
vertical-align: bottom;
}
.text p {
margin: 0;
}
<body>
<div align="center">
<div id="wrapper">
<div id="container_left">
<div class="text_container">
<div class="text">
{block:Description}
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Description}</div>
{/block:Description}
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container left -->
<div class="post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
</div> <!-- post -->
<div id="container_right">
<div class="text_container">
<div class="text">
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Extra Box}</div>
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container right -->
</div> <!-- wrapper -->
</div> <!-- center -->
</body>
Want to get rid of this positioning overheads? Go for flex. its just awesome. Here is a sample implementation for your question.
body {
font-family: arial;
background: #222;
overflow: hidden;
}
img {
width: 100%;
display: block;
}
#wrapper {
width: 100%;
display: flex;
}
#container_left {
border: 1px solid red;
background: #fff;
font-size: 14;
/* width: 150px; */
/* height: auto; */
text-align: center;
}
.post {
border: 1px solid red;
background: #fff;
font-size: 20px;
padding: 10px;
/* width: 500px; */
height: auto;
text-align: center;
margin: 0 auto;
max-height: 100vh;
overflow: auto;
box-sizing: border-box;
}
#container_right {
border: 1px solid red;
background: #fff;
font-size: 14;
/* width: 150px; */
/* height: auto; */
text-align: center;
}
.text_container {
border: 1px solid red;
margin: 10px 10px 10px 10px;
}
.text {
vertical-align: bottom;
}
.text p {
margin: 0;
}
<body>
<div align="center">
<div id="wrapper">
<div>
<div id="container_left">
<div class="text_container">
<div class="text">
{block:Description}
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Description}</div>
{/block:Description}
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container left -->
</div>
<div class="post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
</div> <!-- post -->
<div>
<div id="container_right">
<div class="text_container">
<div class="text">
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Extra Box}</div>
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container right -->
</div>
</div> <!-- wrapper -->
</div> <!-- center -->
</body>
With position fixed you need to set a left/right property instead of a float.
Try changing the right container to the code below and then adjust your other css accordingly:
#container_right {
border:1px solid red;
background:#fff;
font-size:14;
width:150px;
height:auto;
text-align:center;
position:fixed;
right: 10px;
}

Flexbox one long and short columns

I'm trying to implement a layout like this:
On a narrower screen it look like this:
here is my code so far:
.cont {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 500px;
}
.cell{
border: 2px solid black;
}
.cell-1 {
flex-basis: 100%;
width: 70%;
margin-right: 25px;
}
.cell-2,
.cell-3 {
width: 30%;
}
#media (max-width: 1000px) {
.cont{
flex-wrap: nowrap;
}
.cell {
width: 100%;
}
.cell-1, .cell-2, cell-3 {
width: 100%;
}
.cell-1 {
order: 2;
}
.cell-2 {
order: 1;
}
.cell-3 {
order: 3;
}
<div class="cont">
<div class="cell cell-1">
<h2>One</h2>
</div>
<div class="cell cell-2">
<h2>Two</h2>
</div>
<div class="cell cell-3">
<h2>Three</h2>
</div>
</div>
The problem is that I need to set height to the .cont in order for columns to wrap in a widescreen mode, and I can't do that due to the variable content size. For example if I had only 2 small paragraphs in cell-1 and a height of 500px that would lead to footer being too far below from .cont. Or if I had to many content in cell-1 and a height: 500px, it would lead to content inside .cont go under footer.
What would you suggest to solve this problem?
codepen
You can "easily" achieve it with grid:
.cont {
display: grid;
grid-template: 'content side-1' 'content side-2';
grid-template-columns: 7fr 3fr;
grid-column-gap: 1em;
}
.cell-1 {
grid-area: content;
}
.cell-2 {
grid-area: side-1;
}
.cell-3 {
grid-area: side-2;
}
#media(max-width: 768px) {
.cont {
grid-template: 'side-1' 'content' 'side-2'
}
}
<div class="cont">
<div class="cell cell-1">
<h2>One</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sem viverra aliquet eget sit amet. Viverra nibh cras pulvinar mattis nunc. Ut pharetra sit amet aliquam id diam maecenas. Nunc eget lorem dolor sed viverra. Congue quisque egestas diam in arcu cursus euismod quis. Non quam lacus suspendisse faucibus interdum posuere lorem. Iaculis urna id volutpat lacus laoreet non curabitur gravida. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit. Quis eleifend quam adipiscing vitae proin sagittis nisl. In pellentesque massa placerat duis ultricies lacus. Curabitur vitae nunc sed velit dignissim sodales.
<p>Congue quisque egestas diam in arcu cursus euismod quis. Non quam lacus suspendisse faucibus interdum posuere lorem. Iaculis urna id volutpat lacus laoreet non curabitur gravida. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit. Quis eleifend quam adipiscing vitae proin sagittis nisl. In pellentesque massa placerat duis ultricies lacus. Curabitur vitae nunc sed velit dignissim sodales.
</div>
<div class="cell cell-2">
<h2>Two</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sem viverra aliquet eget sit amet. Viverra nibh cras pulvinar mattis nunc.
</div>
<div class="cell cell-3">
<h2>Three</h2>
<p>Non quam lacus suspendisse faucibus interdum posuere lorem. Iaculis urna id volutpat lacus laoreet non curabitur gravida. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit.
</div>
</div>