I'm trying to make small grid of images. On desktops I want 3 images per column and on mobiles 2 images per column. I have no problem doing that. Problems start when I shrink the size of the page to the mobile size. The images are in the proper order but they do not shrink, they keep their original size and the one on the right goes out of the grid (you can't see half of it). I tried max-width:100%, width:100% etc. Did not work.
.sponsors1 {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
#media(max-width:768px) {
.sponsors1 {
grid-template-columns: 1fr 1fr;
justify-self: center;
grid-gap: 8px;
margin-top: 10px;
margin-bottom: 20px;
align-items: center;
overflow:
}
.img1 {
justify-self: center;
}
.img2 {
justify-self: center;
}
.img3 {
justify-self: center;
}
}
<div class="sponsors1">
<img src="images/#.png" alt="">
<img src="images/#.jpg" alt="">
<img src="images/#.png" alt="">
</div>
You should set your image containers' justify-self properties to stretch and then set the image's (NOT their containers') widths to 100%.
.sponsors1{
display:grid;
grid-template-columns: 1fr 1fr 1fr;
}
#media(max-width:768px){
.sponsors1{
grid-template-columns: 1fr 1fr;
justify-self:center;
grid-gap: 8px;
margin-top: 10px;
margin-bottom: 20px;
align-items:center;
overflow:
}
.img1{
justify-self: stretch;
}
.img2{
justify-self: stretch;
}
.img3{
justify-self: stretch;
}
}
img {
width: 100%
}
<div class="sponsors1">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg" alt="">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg" alt="">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg" alt="">
</div>
Related
I made an inline svg with 3d.js and I want to use it in a grid layout.
Its using minmax(0,xfr) to make sure nothing gets bigger then the grid-item itself.
That works resonable but not with inline svg.
It seems to ignore the size at first, so I had to set the width and height.
But even that is ignored, when the screen becomes wide enough :(
Also it is not positioned in the middle but at the top so also the justify-self: center;
align-self: center; options of the grid-item is totaly ignored.
I am trying for hours now with all kind of settings (like preserve aspect ratio etc) but they all seems to not work. Also transform does not seem to work in all screen resolutions.
It seems I do something completely wrong, the size is determent by the svg element while the grid should set the size and the svg should adapt.
How can I make this svg behave like a normal scalable picture/div ?
You can see the code in codepen :
<div class="container">
<div class="Picture"></div>
<div class="Time">
<div class="StopWatch">
</div>
<div class="MinutesText"></div>
</div>
<div class="Level">
<div class="LevelPicture" style=" width:100%; height:100%">
<svg viewBox="0 0 100 100" id="circleLevel">
</svg>
</div>
<div class="LevelText"></div>
</div>
<div class="Arrow">
</div>
</div>
.container { display: grid;
grid-template-columns: minmax(0, 0.2fr) minmax(0, 1.5fr) minmax(0, 2.6fr) minmax(0, 0.6fr) minmax(0, 0.1fr);
grid-template-rows: minmax(0, 0.2fr) minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 0.2fr);
gap: 0px 0px;
grid-auto-flow: row;
grid-template-areas:
". . . . ."
". Picture Time . ."
". Picture Level Arrow ."
". . . . .";
}
.Picture {
justify-self: center;
align-self: center;
grid-area: Picture;
}
.Time { display: grid;
grid-template-columns: minmax(0,0.4fr) minmax(0,1.6fr);
grid-template-rows: minmax(0,1fr);
gap: 0px 0px;
grid-auto-flow: row;
grid-template-areas:
"StopWatch MinutesText";
grid-area: Time;
}
.StopWatch {
justify-self: center;
align-self: center;
grid-area: StopWatch;
}
.MinutesText {
justify-self: start;
align-self: center;
grid-area: MinutesText;
}
.Level { display: grid;
grid-template-columns: minmax(0,0.4fr) minmax(0,1.6fr);
grid-template-rows: minmax(0,1fr);
gap: 0px 0px;
grid-auto-flow: row;
grid-template-areas:
"LevelPicture LevelText";
grid-area: Level;
}
.LevelPicture {
justify-self: center;
align-self: center;
grid-area: LevelPicture;
}
.LevelText {
justify-self: start;
align-self: center;
grid-area: LevelText;
}
.Arrow {
justify-self: center;
align-self: center;
grid-area: Arrow;
}
html, body , .container {
height: 100%;
margin: 0;
}
https://codepen.io/mistert007/pen/mdjRwqr?editors=1111
I have a multiple column CSS Grid defined with repeat(6, 1fr) but with only one or two columns defined. It seems justifying center or space-between does not work in this case, probably because the grid already knows it has 6 equal width columns so there is nothing to justify?
.grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-template-rows: 3em;
grid-gap: 1rem;
/*justify-items: center; horizontally centers column content */
/*align-items: center; vertically centers column content */
}
.grid > div {
background-color: yellow;
}
.grid > div:first-child {
background-color: orange;
}
<div class="grid">
<div>content1</div>
<div>content2</div>
</div>
If you will have only one row you can do the following otherwise use flexbox:
.grid {
display: grid;
grid-auto-columns: calc((100% - 5rem)/6);
grid-auto-flow: column;
grid-template-rows: 3em;
grid-gap: 1rem;
justify-content: center;
border: 1px solid;
}
.grid>div {
background-color: yellow;
}
.grid>div:first-child {
background-color: orange;
}
<div class="grid">
<div>content1</div>
<div>content2</div>
</div>
<div class="grid">
<div>content1</div>
<div>content2</div>
<div>content3</div>
</div>
<div class="grid" style="justify-content: space-between;">
<div>content1</div>
<div>content2</div>
</div>
<div class="grid" style="justify-content: space-between;">
<div>content1</div>
<div>content2</div>
<div>content3</div>
</div>
I would like to make my header sticky when scrolling using CSS grid.
I have tried the solution proposed here: Sticky header on css grid
Meaning:
position: sticky;
top:0;
However it does not work...
.wrapper {
display: grid;
grid-template-areas: "header" "middle" "footer";
grid-template-rows: auto 1fr auto;
height: 100vh;
}
/* Header */
header {
order: 1;
grid-area: header;
display: grid;
grid-gap: 100px;
grid-template-areas: "logo nav";
grid-template-columns: auto 1fr;
grid-auto-flow: column;
position: sticky;
top: 0;
}
nav {
display: grid;
grid-area: nav;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
/* Middle */
.middle {
order: 2;
grid-area: middle;
display: grid;
grid-template-columns: 50px 1fr 50px;
}
.middle>* {
grid-column: 2 / -2;
}
/* Footer */
footer {
order: 3;
grid-area: footer;
display: grid;
grid-template-columns: 1fr auto 1fr;
}
.footer-links {
display: grid;
grid-column: 2 /-2;
grid-template-columns: 1fr;
grid-auto-flow: column;
align-items: center;
}
<body>
<div class="wrapper">
<!-- Header -->
<header>
<img src="img/logo_jaeaess_glitch.png" alt="Logo of the VJ Jääß (Jess de Jesus)" style="width:42px;height:42px">
<nav>
Welcome
About
Art Work
Events
</nav>
</header>
<!-- Middle -->
<section class="middle">
</section>
<footer>
<div class="footer-links">
Instagram
<p>© 2019 Jääß</p>
</div>
</footer>
</div>
</body>
Everything displays as I want it to, except that the header scroll down instead of staying fix...
(For those who wonder, I put the order just to move it within a media query at a later stage of development)
Thank you for your answers!
To make the header fixed when scrolling, you could make it position: fixed. This requires you to set a fixed height for your header. This will make the header element flow on top of the content and ignore scrolling relative to the window.
.wrapper {
/* the header will not take any vertical place so shift wrapper down a bit*/
margin-top: 3rem;
display: grid;
/*I removed the header area as we don't need it anymore and would not work with fixed position anways*/
grid-template-areas: "middle" "footer";
grid-template-rows: 1fr auto;
/*I set the wrapper height to `200vw` so its easier to see the header not scrolling. Also take maring top into account*/
height: calc(200vh - 3rem);
}
/* Header */
header {
display: grid;
grid-gap: 100px;
grid-template-areas: "logo nav";
grid-template-columns: auto 1fr;
grid-auto-flow: column;
position: fixed;
top: 0;
height: 3rem;
width: 100%;
}
nav {
display: grid;
grid-area: nav;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
/* Middle */
.middle {
order: 2;
grid-area: middle;
display: grid;
grid-template-columns: 50px 1fr 50px;
}
.middle>* {
grid-column: 2 / -2;
}
/* Footer */
footer {
order: 3;
grid-area: footer;
display: grid;
grid-template-columns: 1fr auto 1fr;
}
.footer-links {
display: grid;
grid-column: 2 /-2;
grid-template-columns: 1fr;
grid-auto-flow: column;
align-items: center;
}
<div class="wrapper">
<!-- Header -->
<header>
<img src="img/logo_jaeaess_glitch.png" alt="Logo of the VJ Jääß (Jess de Jesus)" style="width:42px;height:42px" />
<nav>
<a href="./index.html" title="Welcome" class="welcome active">Welcome</a
>
About
Art Work
Events
</nav>
</header>
<!-- Middle -->
<section class="middle"></section>
<footer>
<div class="footer-links">
<a href="https://www.instagram.com/jaeaess/" target="_blank">Instagram</a
>
<p>© 2019 Jääß</p>
</div>
</footer>
</div>
Ps.: You are kinda overusing the css grid at this moment. It is designed for 2 dimensional layouts. Your layout would be much(!) easier if you were using flexbox. Also making grid work in IE 11 is a pain.
hi all i have a three row bootstrap 4 column as shown below but for some reason its not responding to the resizing even though i changed the min-width in media queries and also have added container fluid in the html. Can somoene please tell me what im doing wrong and how i can make it responsive ? Thanks for the help !!
<div classname="container-fluid">
<div classname="row">
<div className="col-xs-4">
<div className="card">
<div className="card-body">
<img className="card-img-top" src={trail.imgSmall} />
<h2 className="card-title">{trail.name}</h2>
<div className="star-rating__ico fa fa-star-o fa-lg">{trail.stars}</div>
<br></br> <br></br>
<h4 className="card-subtitle">{trail.summary}</h4>
<p classname="card-text"> {trail.length} km </p>
<button> View </button>
</div>
</div>
</div>
</div>
</div>
css
#media only screen and (min-width : 480px) {
.col-xs-4{
{ width: 20%; }
}
}
#media (min-width: 408px) {
.card {
margin-left: 0;
margin-right: 0;
width: 50%;
position: relative;
left:0px;
}
}
.card-info {
padding: 1rem;
display: -ms-grid;
display: grid;
-ms-grid-rows: 1fr 2.5rem;
grid-template-rows: 1fr 2.5rem;
-ms-grid-columns: 3fr 1fr;
grid-template-columns: 3fr 1fr;
}
.card-title {
font-size: 2rem;
grid-row: 1 / 2;
grid-column: 1 / 2;
}
.card-icon {
grid-row: 1 / 2;
grid-column: 2 / 3;
justify-self: right;
width: 30px;
height: 30px;
background-color: LightBlue;
border-radius: 100%;
display: -ms-grid;
display: grid;
-ms-grid-column-align: center;
justify-items: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.car
If you are using bootstrap 4, do mention. Also I don't think bootstrap 4 has col-xs-* class instead it uses col-* classes for that, and you need to add cols for specific device widths instead of modifying media queries first to see if that can solve your problem
There are lots of similar questions, I have reviewed all of them, but none solved my problem.
Premises:
I have a flexbox layout with flex column and the bottom flex-item filling the remainder of the page height. The flex-item gets stretched to the remainder of the page by flex 1.
Goal:
I need my grid (with its children) inside this flex-item to expand to the height of the flex-item.
Problem:
The html wrapper only has a min-height 100vh set. This makes the grid stretch to the flex-item, but not its children!
The only solution I can find is to also set height 100vh on the html wrapper, but I do not want to do this. Is there any way to solve my problem without setting height?
See the codepen here:
https://codepen.io/mesqueeb/pen/aGeKjm
See the animated GIF here to show you what I mean:
You can try this.
remove the flex-direction: column; in the .remaining and it will expand the height.
main{
min-height: calc(100vh - 51px);
display: flex;
flex-direction: column;
}
div{
border: solid goldenrod thick;
padding: 2px;
margin: 2px;
}
.full-page{
display: flex;
flex-direction: column;
height: 100%;
flex: 1;
}
.top-row{
height: 100px;
}
.remaining{
flex: 1;
display: flex;
}
.grid{
border: solid teal thick;
flex: 1;
display: grid;
grid-template-rows: 1fr 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr;
}
.key{
border: thin green solid
}
.small{
font-size: .8em
}
<main>
<div class="full-page">
<div class="top-row">
grid below will take full height only if body height is set...
</div>
<div class="remaining">
<div class="grid">
<div class="key">1</div>
<div class="key">2</div>
<div class="key">3</div>
<div class="key">4</div>
<div class="key">5</div>
<div class="key">6</div>
<div class="key">7</div>
<div class="key">8</div>
<div class="key">9</div>
<div class="key">C</div>
<div class="key">0</div>
<div class="key">➕</div>
</div>
</div>
</div>
</main>
Not sure if it solves your problem in the best way, but this works:
.remaining {
flex: 1;
/* display: flex; */
flex-direction: column;
position: relative;
}
.grid {
border: solid #008080 thick;
/* flex: 1; */
display: grid;
grid-template-rows: 1fr 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}