HTML make left and right div with left-one position:fixed - html

I want to create page with navigation menu on left side which will be fixed there.
In the center of the screen should be main content of page.
I made this:
HTML:
<div>
<Sidepanel></Sidepanel>
<div class="content">
<div class="item">
<img src="#/assets/1.jpg">
</div>
<div class="item">
<img src="#/assets/2.jpg">
</div>
<div class="item">
<img src="#/assets/3.jpg">
</div>
<div class="item">
<img src="#/assets/4.jpg">
</div>
</div>
</div>
HTML for sidepanel:
<div class="Sidepanel">
<div>
Home
</div>
<div>
1234
</div>
<div>
Settings
</div>
</div>
CSS:
.Sidepanel {
background-color: #5555FF;
float: left;
padding: 1em;
/*width: 200px;*/
height: 100%;
overflow: auto;
position: fixed;
}
.Sidepanel div {
margin: 5% 0 5% 0;
}
a {
color: black;
font-size: calc(1em + 1vw);
}
body {
margin: 0
}
.content {
-webkit-columns: 2 200px;
-moz-columns: 2 200px;
columns: 2 200px;
}
.content img {
width: 90%;
object-fit: cover;
}
And on the resulting page right div goes under left. It works well if I remove position:fixed, but then I loose fixed menu on scroll.

You can try with grid. Pls. look at snippet below:
.Sidepanel {
background-color: #5555FF;
padding: 1em;
height: 100%;
overflow: auto;
position: fixed;
grid-column: 1;
}
.Sidepanel div {
margin: 5% 0 5% 0;
}
a {
color: black;
font-size: calc(1em + 1vw);
}
body {
margin: 0
}
.container {
display: grid;
grid-template-columns: minmax(0,200px) 1fr;
}
.content {
-webkit-columns: 2 200px;
-moz-columns: 2 200px;
columns: 2 200px;
grid-column: 2;
justify-self: start;
}
.content img {
width: 90%;
object-fit: cover;
}
#media (max-width: 500px) {
.container {
grid-template-columns:30% 1fr;
}
}
<div class="container">
<Sidepanel>
<div class="Sidepanel">
<div>
Home
</div>
<div>
1234
</div>
<div>
Settings
</div>
</div>
</Sidepanel>
<div class="content">
<div class="item">
<img src="https://picsum.photos/200">
</div>
<div class="item">
<img src="https://picsum.photos/200">
</div>
<div class="item">
<img src="https://picsum.photos/200">
</div>
<div class="item">
<img src="https://picsum.photos/200">
</div>
</div>
</div>

Related

Text below images in css grid is making them change size based on length of text

I'm a bit new to front end and doing my best to figure things out. I have been building a relatively simple landing page and all looking great except when I try to use a css grid. The text (people's names) is changing the size of the images so that none of them are the same size (see the attached image). It seems that the images directly above and below each other grow together if the text is changed for one. While the images next to each other left and right change inversely. Removing all text makes them the same size.
Here is a fiddle for a runnable copy.
I would really like to set the grid to take up a percentage of the container it's in if it's possible. For the life of me I can't find what I am missing. Is there some way that I can set all images to stay the same size as one another?
I will try to include the relevant pieces of CSS.
.team {
padding: 66px 0 80px 0;
background-image: url("assets/pattern-team.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center center;
width: 100%;
}
.team .container {
display: flex;
}
.team-heading {
width: 30%;
margin-right: 80px;
}
.team-heading p {
margin-top: 17px;
}
.team-members {
width: 70%;
display: grid;
grid-template-areas: "name1." "name2 name3";
gap: 30px;
row-gap: 30px;
}
.name1 {
grid-area: name1;
}
.name2 {
grid-area: name2;
}
.name3 {
grid-area: name3;
}
enter code here .team-member {
cursor: pointer;
}
.team-member .team-img {
box-shadow: 10px 10px #7CE04E;
border: 2px solid black;
}
.team-member h4 {
margin: 15px 0 5px 0;
}
.team img {
display: block;
}
<!-- Our team -->
<section class="team">
<div class="container">
<div class="team-heading">
<h2>Our team</h2>
<p>Meet the cats behind the magic.</p>
</div>
<div class="team-members">
<!-- Griff -->
<div class="team-member griff">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg" />
</div>
<h4>Griff</h4>
<p>description</p>
</div>
<!-- Brenden -->
<div class="team-member brenden">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg" />
</div>
<h4>Brenden</h4>
<p>description</p>
</div>
<!-- Thu -->
<div class="team-member thu">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg" />
</div>
<h4>Thu</h4>
<p>description</p>
</div>
</div>
</div>
</section>
Thanks in advance for any pointers or even a suggestion of where to start searching!
Simply add column templates:
grid-template-columns: 1fr 1fr;
h4 {
font-size: 33px;
line-height: 43px;
}
.team {
padding: 66px 0 80px 0;
background-image: url("assets/pattern-team.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center center;
width: 100%;
}
.team .container {
display: flex;
}
.team-heading {
width: 30%;
margin-right: 80px;
}
.team-heading p {
margin-top: 17px;
}
.team-members {
width: 70%;
display: grid;
/*Set 2 eqaul columns*/
grid-template-columns: 1fr 1fr;
grid-template-areas: "griff ." "brenden thu";
gap: 30px;
row-gap: 30px;
}
.griff {
grid-area: griff;
}
.brenden {
grid-area: brenden;
}
.thu {
grid-area: thu;
}
.team-member .team-img {
box-shadow: 10px 10px #7CE04E;
border: 2px solid black;
}
.team-member h4 {
margin: 15px 0 5px 0;
}
.team img {
display: block;
}
<!-- Our team -->
<section class="team">
<div class="container">
<div class="team-heading">
<h2>Our team</h2>
<p>Meet the cats behind the magic.</p>
</div>
<div class="team-members">
<!-- Griff -->
<div class="team-member griff">
<div>
<img
class="team-img"
src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg"
/>
</div>
<h4>Griff</h4>
<p>description</p>
</div>
<!-- Brenden -->
<div class="team-member brenden">
<div>
<img
class="team-img"
src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg"
/>
</div>
<h4>Brenden</h4>
<p>description</p>
</div>
<!-- Thu -->
<div class="team-member thu">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg"/>
</div>
<h4>Thu</h4>
<p>description</p>
</div>
</div>
</div>
</section>

How do I maintain constant image height? Stuck in flexbox?

I am trying to create flexbox with different image heights and width. I want the break points as
max-width: 640px; ------->Only one column
max-width: 860px; -------->Two columns only
greater than: 860px;-------->Three column only
What I am messing with? Why it is becoming ugly while shrinking window?I am losing 3 column of image even before window size reach 860px breakpoint. What else can I do?
After window size reaches to 860px it is working fine, but until than it is becoming ugly.
I want my image height not be changed. Let it be as it is !
.container {
width: 100%;
height: 1000px;
display: flex;
flex-direction: column;
background: green;
flex-wrap: wrap;
align-items: center;
align-content: center;
justify-content: flex-start;
}
.box {
width: 30%;
border: 2px solid red;
margin: 8px;
}
img {
width: 100%;
height: auto;
}
#media screen and (max-width: 860px) {
.container {
background-color: red;
height: 1100px;
}
.box {
width: 46%;
}
}
#media screen and (max-width: 640px){
.container {
background-color: yellowgreen;
height: auto;
flex-direction: row;
}
.box {
width: 100%;
}
}
<div class="container">
<div class="box">
<img src="https://www.daily-sun.com/assets/news_images/2017/01/12/DAILYSUN_ZYAN.jpg" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/79/e2/8d/79e28db17abc2eb6c3085c9c72bff5e4.jpg" alt="">
</div>
<div class="box">
<img src="https://www.pinkvilla.com/files/styles/gallery-section/public/zayn_malik_tattoos_1.jpg?itok=Q5bXGlfm" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/b5/0c/30/b50c30ddaaffc98ff2cb077cc7f57823.jpg" alt="">
</div>
<div class="box">
<img src="https://images.news18.com/ibnlive/uploads/2021/01/1610783227_zayn-malik.jpg" alt="">
</div>
<div class="box">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gigi-hadid-and-zayn-malik-attend-the-manus-x-machina-news-photo-527409630-1554477973.jpg?crop=1.00xw:0.762xh;0,0.0194xh&resize=480:*" alt="">
</div>
</div>
In this cas, I would use CSS column-count and CSS grid.
Just an example with your code:
.container {
column-count: 3;
column-gap: 10px;
background: green;
padding: 10px;
}
#media (max-width: 640px) {
.container {
column-count: 1;
}
}
#media (min-width: 641px) and (max-width: 840px) {
.container {
column-count: 2;
}
}
img {
max-width: 100%;
display: block;
}
.box {
margin: 0;
display: grid;
grid-template-rows: 1fr auto;
margin-bottom: 10px;
break-inside: avoid;
border: 2px solid red;
}
<div class="container">
<div class="box">
<img src="https://www.daily-sun.com/assets/news_images/2017/01/12/DAILYSUN_ZYAN.jpg" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/79/e2/8d/79e28db17abc2eb6c3085c9c72bff5e4.jpg" alt="">
</div>
<div class="box">
<img src="https://www.pinkvilla.com/files/styles/gallery-section/public/zayn_malik_tattoos_1.jpg?itok=Q5bXGlfm" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/b5/0c/30/b50c30ddaaffc98ff2cb077cc7f57823.jpg" alt="">
</div>
<div class="box">
<img src="https://images.news18.com/ibnlive/uploads/2021/01/1610783227_zayn-malik.jpg" alt="">
</div>
<div class="box">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gigi-hadid-and-zayn-malik-attend-the-manus-x-machina-news-photo-527409630-1554477973.jpg?crop=1.00xw:0.762xh;0,0.0194xh&resize=480:*" alt="">
</div>
</div>
However for this layout using grid is the best way, but I tried to find a way by flex. For "flex-direction: column;" height is important so you should set a height that can't contain more than 2 images. I did it with "height: 70vw;"
.container {
width: 100%;
height: 70vw;
display: flex;
flex-direction: column;
background: green;
flex-wrap: wrap;
align-items: center;
align-content: center;
justify-content: flex-start;
}
.box {
width: 30%;
border: 2px solid red;
margin: 8px;
}
img {
width: 100%;
height: auto;
}
#media screen and (max-width: 860px) {
.container {
background-color: red;
height: 1120px;
}
.box {
width: 46%;
}
}
#media screen and (max-width: 640px){
.container {
background-color: yellowgreen;
height: auto;
flex-direction: row;
}
.box {
width: 100%;
}
}
<div class="container">
<div class="box">
<img src="https://www.daily-sun.com/assets/news_images/2017/01/12/DAILYSUN_ZYAN.jpg" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/79/e2/8d/79e28db17abc2eb6c3085c9c72bff5e4.jpg" alt="">
</div>
<div class="box">
<img src="https://www.pinkvilla.com/files/styles/gallery-section/public/zayn_malik_tattoos_1.jpg?itok=Q5bXGlfm" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/b5/0c/30/b50c30ddaaffc98ff2cb077cc7f57823.jpg" alt="">
</div>
<div class="box">
<img src="https://images.news18.com/ibnlive/uploads/2021/01/1610783227_zayn-malik.jpg" alt="">
</div>
<div class="box">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gigi-hadid-and-zayn-malik-attend-the-manus-x-machina-news-photo-527409630-1554477973.jpg?crop=1.00xw:0.762xh;0,0.0194xh&resize=480:*" alt="">
</div>
</div>

Responsive Design - Div disappears when resizing window

Just trying to make two div elements (.left and .right) display vertically when width value is less than 800px. However, the div .left disappeared when I tried to do so. I removed some content from the code to keep it short.
Does anyone have an idea as to why this is happening and how to fix it?
This is my code:
* {
box-sizing: border-box;
}
body {
color: white;
}
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: #282C34;
}
.right {
right: 0;
background-color: #616161;
}
.centered {
position: absolute;
width: 100;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.container {
position: relative;
border-style: solid;
border-color: #92a8d1;
background-color: #92a8d1;
}
#media screen and (max-width:800px) {
.left,
.right {
width: 100%;
/* The width is 100%, when the viewport is 800px or smaller */
}
}
<div class="split left">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>asd</h2>
</div>
</div>
</center>
</div>
</div>
<div class="split right">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>fgh</h2>
</div>
</div>
</center>
</div>
</div>
Thanks for your help!
* {
box-sizing: border-box;
}
body {
color: white;
margin: 0;
}
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: #282C34;
}
.right {
right: 0;
background-color: #616161;
}
.centered {
position: absolute;
width: 100;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.container {
position: relative;
border-style: solid;
border-color: #92a8d1;
background-color: #92a8d1;
}
#media screen and (max-width:800px) {
.left,
.right {
width: 100%;
height: 50%;
/* The width is 100%, when the viewport is 800px or smaller */
}
.split {
position: relative;
}
body {
height: 100vh;
}
}
<div class="split left">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>asd</h2>
</div>
</div>
</center>
</div>
</div>
<div class="split right">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>fgh</h2>
</div>
</div>
</center>
</div>
</div>
Nest the two divs inside a wrapper div and work with media queries and the flex property. Like..
HTML:
<div class="wrapper">
<div class="left">
...
</div>
<div class="right">
...
</div>
</div>
CSS/SCSS
#media(max-width: 800px) {
.wrapper {
display: flex;
flex-direction: column;
...
}
}
Or Try:
<ul class="flex-container column">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
</ul>
.flex-container {
padding: 0;
margin: 0;
list-style: none;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
}
.column {
-webkit-flex-direction: column;
flex-direction: column;
float: left;
}
.column li {
background: deepskyblue;
}

Aligning images horizontally with respect to another image

I am trying to align some pictures perfectly according to their height while maintaining their ability to scale. I have made a column layout using floats in CSS. There are three columns and have equal width so they scale equally but I can't seem to make the images have optimal height so they all fit in their containers with equal height. The images in my middle column are flowing out.
.section__banner-row {
max-width: 100%;
margin: 0 auto;
}
.section__banner-row:not(:last-child) {
margin-bottom: 1rem;
}
.section__banner-row::after {
content: "";
display: table;
clear: both;
}
.section__banner-row [class^="col-"] {
float: left;
}
.section__banner-row [class^="col-"]:not(:last-child) {
margin-right: 1rem;
}
.section__banner-row .col-1-of-2 {
width: calc((99.9% - 1rem) / 2);
}
.section__banner-row .col-1-of-3 {
width: calc((99.9% - 2 * 1rem) / 3);
}
.section__inside-banner {
margin-top: 1rem;
}
.container-shadow-box {
position: relative;
overflow: hidden;
}
.container-shadow-box img {
width: 100%;
display: block;
transition: all 0.5s;
}
.container-shadow-box:hover img {
transform: scale(1.11);
}
<div class="section__banner-row">
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/FhQFN40/blog-masonry-01.jpg" alt="Masonry 1">
</div>
</div>
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/0JHHwbm/blog-masonry-02.jpg" alt="Masonry 2">
</div>
<div class="section__inside-banner">
<div class="col-1-of-2">
<div class="container-shadow-box">
<img src="https://i.ibb.co/NycZ9KN/blog-masonry-03.jpg" alt="Masonry 3">
</div>
</div>
<div class="col-1-of-2">
<div class="container-shadow-box">
<img src="https://i.ibb.co/qRNZm1q/blog-masonry-04.jpg" alt="Masonry 4">
</div>
</div>
</div>
</div>
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/PmcznpR/blog-masonry-05.jpg" alt="Masonry 5">
</div>
</div>
</div>
Flexbox example:
body * {
box-sizing: border-box;
}
.grid-box {
padding-bottom: 28%; /* adjust this for container aspect ratio */
height: 0;
position: relative;
background: pink;
}
.section__banner-row {
display: flex;
}
.section__banner-row.outer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 5px;
}
.section__banner-row .col {
flex: 1 1 auto;
display: flex;
flex-direction: column;
justify-content: stretch;
align-items: stretch;
}
.section__banner-row .col > div {
flex-basis: 50%;
flex-grow: 1;
}
.container-shadow-box {
margin: 10px;
height: 100%;
background: #ddd;
}
.container-shadow-box>div {
background-size: cover;
height: 100%;
}
<div class="grid-box">
<div class="section__banner-row outer">
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/FhQFN40/blog-masonry-01.jpg);"></div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/0JHHwbm/blog-masonry-02.jpg);"></div>
</div>
<div class="section__banner-row">
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/NycZ9KN/blog-masonry-03.jpg);"></div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/qRNZm1q/blog-masonry-04.jpg);"></div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/PmcznpR/blog-masonry-05.jpg);"></div>
</div>
</div>
</div>
</div>
Fiddle demo
Does my browser support flexbox?

Using %-based width divs inside a container with px-based margin

Bit of a beginner's question here - I'm sure it's been asked many times over but not knowing how to phrase the question means I've found it hard to find answers.
I'm trying to create 3 "cards" in a div which are responsive. I would like the margin between the cards to stay at 20px.
This is what I've come up with so far - the contents of the card container should add up to 965, so I'm not sure what's causing it to break and spill out, unless I'm doing something else wrong.
.container {
max-width: 1280px;
}
.card-container {
max-width: 965px;
padding: 0 20px;
display: block;
float: left;
}
.card {
width: 33%;
min-width: 295px;
}
.one {
width: 100%;
height: 200px;
background-color: #333;
display: block;
float: left;
}
.card + .card {
margin: 0px 0px 0px 20px;
}
<div class="container">
<div class="card-container">
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
</div>
<!-- <div class="map-card"></div> -->
</div>
Thanks for any help, or redirecting to a similar topic.
You can use flex like this https://jsfiddle.net/3gg8ngm2/2/:
.container {
max-width: 1280px;
}
.card-container {
max-width: 965px;
padding: 0 20px;
display: flex;
}
.card {
width: 33%;
/* min-width: 295px; */
}
.one {
width: 100%;
height: 200px;
background-color: #333;
display: block;
float: left;
}
.card + .card {
margin: 0px 0px 0px 20px;
}
<div class="container">
<div class="card-container">
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
</div>
<!-- <div class="map-card"></div> -->
</div>
Or you can also use display-inline-block to your .card class.
There is a solution based on display: flex
.container {
width: 600px;
}
.card-container {
display: flex;
background: yellow;
}
.card {
width: calc(33% - 20px);
margin-right: 20px;
}
.card:first-child {margin-left:20px}
.one {
height: 200px;
background-color: #333;
}
<div class="container">
<div class="card-container">
<div class="card">
<div class="one">1</div>
</div>
<div class="card">
<div class="one">2</div>
</div>
<div class="card">
<div class="one">3</div>
</div>
</div>
</div>
Add this
.card {
width: 30%;
float:left;
min-width: 295px;
}
and will resolve your issue.