This is a simple used automobile sales platform for a dealer who doesn't want a lot of interactivity, just a listing of the vehicles and prices in a visual manner similar to a print magazine (click on Run Code Snippet and View Full page to see it as it looks currently):
body {
font-family: Helvetica, sans-serif;
}
header, footer {
background-color: #7690AC;
color: #FFFFFF;
padding: 20px;
padding-bottom: 20px;
}
.content {
padding: 10px;
margin-bottom: 10px;
margin-left: 20px;
}
.grid {
margin-bottom: 20px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-gap: 20px;
align-items: center;
}
.grid > article {
border: 1px solid #333;
box-shadow: 2px 2px 6px 0px rgba(0,0,0,0.3);
min-height: 25em;
top: -10px;
}
.grid > article img {
max-width: 100%;
margin-bottom: 12px;
}
.text {
font-size: 1em;
transform: scaleX(1.2) scaleY(1);
margin-left: 25px;
width: 270px;
}
.text {
padding: 0 10px 20px;
}
.text > button {
background: gray;
border: 0;
color: white;
padding: 10px;
width: 100%;
}
h3.price {
text-align: center;
}
.cards {
grid-template-columns: repeat(2, 1fr);
border-collapse: collapse;
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-gap: 1rem;
}
.card {
background-color: dodgerblue;
color: white;
padding: 1rem;
height: 4rem;
}
p.address, p.phoneno {
font-size: 18px;
font-weight: 900;
line-height: 12px;
}
☎:before {
font-size: 14px;
}
<header>
<h1>YOURMOTORHOMES</h1>
<h2>Axtley Road, Penderton XX1 1XA</h2>
<h2>01634 00000</h2>
</header>
<div class="content">
<p>Welcome to YourMotorhomes!</p>
</div>
<main class="grid">
<article>
<img src="https://i.imgur.com/PApYyjj.jpg" alt="Elddis Autoquest">
<div class="text">
<p><b>2020 70 ELDDIS AUTOQUEST 194 2.2 HDi 140 LOW PROFILE MOTORHOME PEUGEOT BOXER CHASSIS</b>
4 berth, end washroom, white, 100 litre fresh water, 70 litre waste water, 3 ring hob, OG cooker, 155 litre fridge, 600 miles, almost as new, <b class="price">£44895</b></p>
</div>
</article>
<article>
<img src="https://i.imgur.com/h7Cujxy.jpg" alt="Dethleffs Esprit"><em>Image for illustration purposes only</em>
<div class="text">
<p><b>2014 64 DETHLEFFS i6810 ESPRIT 2.3 MULTIJET 130 A-CLASS FIAT DUCATO MOTORHOME</b>
4 berth, 4 belted seats A-class motorhome finished in Diamodn White, fixed single bed layout, 3 ring cooker, fully loaded spec, 28,000 miles <b class="price">£62115</b></p>
</div>
</article>
<article>
<img src="https://i.imgur.com/TfuaqVa.jpg" alt="Burstner Aviano">
<div class="text">
<p><b>2009 59 BURSTNER AVIANO i725 3.0 MULTIJET 180 FIAT TD</b>
4 berth, gold, island bed layout, 3 ring hob, 150 litre fridge, 7.45m length, 2.30m width <b class="price">£44995</b></p>
</div>
</article>
<article>
<img src="https://i.imgur.com/oUWFVub.jpg" alt="Burstner Nexxo">
<div class="text">
<p><b>2009 58 BURSTNER NEXXO FAMILY A645 2.2 TDCi</b>
6 berth, 6 belted seats, end bedroom, blue, Layout - Over Cab Double, Centre Dinette Double, Rear Bunk beds, 2 Owners from New, Good Service History, Cab Air Conditioning, Gaslow Refillable LPG System, Truma Blown Air Combination Boiler, HPI Clear, Roof Rails, Large Garage - if not using bottom bunk, Awning,MOT 17/12/2021, 11 Service Stamps in the book, Last Damp check 01/21, GVW 3500kg, Length 6.56m, Width 2.30m, Height 3.0m, only 20,747 miles, registered 30/01/2009, MoT due in Oct' 21. DUE THIS WEEK. A GREAT EXAMPLE OF THIS BURSTNER MOTORHOME, MUST BE SEEN NOW, YOU WILL NOT FIND BETTER
<b class="price">£35000</b></p>
</div>
</article>
</main>
<footer>
content
</footer>
Functionally, it works, but I want to try and achieve three things; the within grid being all the same size, and also the images being the same size within the article (I've got it at max-width:100%) so it's not creating uneven sizes (if you view the design at full screen) and preventing text overflow by auto-resizing the font if there's a lot of text without needing a scrollbar or overflow: hidden; in the CSS.
I would be grateful if anyone can help, as this template's working, not quite production-ready, but it's getting there slowly.
Try this -
1. Remove transform property form .text class and
2. Remove align-items from .grid class.
.text {
font-size: 1em;
/* transform: scaleX(1.2) scaleY(1); */ // Comment it.
margin-left: 25px;
width: 270px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-gap: 20px;
/* align-items: center; */ //Comment it.
}
The given code arranges the articles in a grid which adjusts to the viewport width OK but these things are required:
The height of each article should be the same
The height of each image should be the same
The text should have font-size adjusted so that it always fits within the article size
Taking each requirement in turn:
Set the height of article to something. It depends on what you think would be sensible bearing in mind the maximum amount of text a van may require - to ensure its text will still be readable. The snippet below sets it at 30em (based on the code in the question having a minimum height of 25em)
Although we want the height of each img to be the same, say a % of the article height, we need to ensure that the whole of the img is always viewable, without distortion or cropping. This snippet changes the HTML so that the img element becomes a div with fixed dimensions and the image is used as a background, centered both horizontally and vertically and with size contain. (see below for alternative).
Altering the font size I think requires Javascript. This snippet looks at the height of the text div and if it's too tall alters the font size until it fits. You may want to put a different limit on it so that it is always readable, even if that means occasionally the user having to scroll.
const articles = document.querySelectorAll('.grid > article');
articles.forEach(article => {
const articleH = article.offsetHeight;
let h = article.querySelector('.text').offsetHeight;
var fontSize = 0.9;
while (h > articleH/2) {//NOTE assumes the img is 50% alter if it is something else
article.querySelector('.text').style.fontSize = fontSize + 'em';
h = article.querySelector('.text').offsetHeight;
if (fontSize <= 0.2) break;
fontSize = fontSize - 0.05;
}
});
body {
font-family: Helvetica, sans-serif;
width: 100vw;
}
header, footer {
background-color: #7690AC;
color: #FFFFFF;
padding: 20px;
padding-bottom: 20px;
}
.content {
padding: 10px;
margin-bottom: 10px;
margin-left: 20px;
}
.grid {
margin-bottom: 20px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-gap: 20px;
align-items: center;
}
.grid > article {
border: 1px solid #333;
box-shadow: 2px 2px 6px 0px rgba(0,0,0,0.3);
/* min-height: 25em; */
height: 30em; /* ADDED */
top: -10px;
}
.grid > article .img {
width: 100%;
height: 50%;
background-size: contain;
background-position: center center;
background-repeat: no-repeat no-repeat;
margin-bottom: 12px;
}
.text {
font-size: 1em;
/*transform: scaleX(1.2) scaleY(1);*/
margin-left: 25px;
width: 270px;
}
.text {
padding: 0 10px 20px;
}
.text > button {
background: gray;
border: 0;
color: white;
padding: 10px;
width: 100%;
}
h3.price {
text-align: center;
}
.cards {
grid-template-columns: repeat(2, 1fr);
border-collapse: collapse;
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-gap: 1rem;
}
.card {
background-color: dodgerblue;
color: white;
padding: 1rem;
height: 4rem;
}
p.address, p.phoneno {
font-size: 18px;
font-weight: 900;
line-height: 12px;
}
☎:before {
font-size: 14px;
}
<header>
<h1>YOURMOTORHOMES</h1>
<h2>Axtley Road, Penderton XX1 1XA</h2>
<h2>01634 00000</h2>
</header>
<div class="content">
<p>Welcome to YourMotorhomes!</p>
</div>
<main class="grid">
<article>
<div class="img" style="background-image: url(https://i.imgur.com/PApYyjj.jpg)" alt="Elddis Autoquest"></div>
<div class="text">
<p><b>2020 70 ELDDIS AUTOQUEST 194 2.2 HDi 140 LOW PROFILE MOTORHOME PEUGEOT BOXER CHASSIS</b>
4 berth, end washroom, white, 100 litre fresh water, 70 litre waste water, 3 ring hob, OG cooker, 155 litre fridge, 600 miles, almost as new, <b class="price">£44895</b></p>
</div>
</article>
<article>
<div class="img" style="background-image: url( https://i.imgur.com/h7Cujxy.jpg" alt="Dethleffs Esprit)"></div><em>Image for illustration purposes only</em>
<div class="text">
<p><b>2014 64 DETHLEFFS i6810 ESPRIT 2.3 MULTIJET 130 A-CLASS FIAT DUCATO MOTORHOME</b>
4 berth, 4 belted seats A-class motorhome finished in Diamodn White, fixed single bed layout, 3 ring cooker, fully loaded spec, 28,000 miles <b class="price">£62115</b></p>
</div>
</article>
<article>
<div class="img" style="background-image: url(https://i.imgur.com/TfuaqVa.jpg)" alt="Burstner Aviano"></div>
<div class="text">
<p><b>2009 59 BURSTNER AVIANO i725 3.0 MULTIJET 180 FIAT TD</b>
4 berth, gold, island bed layout, 3 ring hob, 150 litre fridge, 7.45m length, 2.30m width <b class="price">£44995</b></p>
</div>
</article>
<article>
<div class="img" style="background-image: url(https://i.imgur.com/oUWFVub.jpg);" alt="Burstner Nexxo"></div>
<div class="text">
<p><b>2009 58 BURSTNER NEXXO FAMILY A645 2.2 TDCi</b>
6 berth, 6 belted seats, end bedroom, blue, Layout - Over Cab Double, Centre Dinette Double, Rear Bunk beds, 2 Owners from New, Good Service History, Cab Air Conditioning, Gaslow Refillable LPG System, Truma Blown Air Combination Boiler, HPI Clear, Roof Rails, Large Garage - if not using bottom bunk, Awning,MOT 17/12/2021, 11 Service Stamps in the book, Last Damp check 01/21, GVW 3500kg, Length 6.56m, Width 2.30m, Height 3.0m, only 20,747 miles, registered 30/01/2009, MoT due in Oct' 21. DUE THIS WEEK. A GREAT EXAMPLE OF THIS BURSTNER MOTORHOME, MUST BE SEEN NOW, YOU WILL NOT FIND BETTER
<b class="price">£35000</b></p>
</div>
</article>
</main>
<footer>
content
</footer>
An alternative to contain on the background size could be cover - if you were absolutely sure that the motor was central in each image and the aspect ratio such that it would fit OK. This runs a risk that not all the van will show though, but it gives a more consistent solid look to the top part of the article.
Hello guys I rendering an article.component.html inside my article-list-component.html in a list when I do it in plain HTML it renders just fine (see picture 1):
Title - author - Date
Here is my article-list.component.html
<ul>
<li *ngFor="let article of data_array">
<a [href]="article.url" class="undecorateda" target="_blank">
<app-article [data]='article'></app-article>
</a>
</li>
</ul>
but when I try to use angular-material list the component renders all to the left like this (see picture 2):
Title-author-Date
Here is my article-list.component html:
<mat-list>
<mat-list-item *ngFor="let article of data_array">
<a [href]="test">
<app-article [data]='article' (click)="printURL(article.url)"></app-article>
</a>
</mat-list-item>
</mat-list>
when I use the plain HTML in the article-list.component.html it renders as I want it to do, but if I use the material code inside article-list.component.html it doesn't render properly
this is the article.component.html
<div class='article-container'>
<div class='title-container'>
{{data.title}}
<div class='author-container'>
-{{data.author}}-
</div>
</div>
<div class='date-container'>
{{formatDay(data.created_at)}}
</div>
<div class="actions-container" id="deletebtn">
<button mat-icon-button color="warn" (click)="deleteArticle(data._id)">
<mat-icon>delete_forever</mat-icon>
</button>
</div>
</div>
this is the article.component.css file:
.article-container {
display: grid;
grid-auto-flow: column;
grid-template-columns: 10fr 2fr 1fr;
height: 50px;
background-color: #fff;
border-bottom: 1px solid #ccc;
align-items: center;
padding: 0 15px;
}
.article-container>* {
grid-row: 1/2;
}
.article-container #deletebtn {
display: none;
}
.article-container:hover {
background-color: #fafafa;
}
.article-container:hover #deletebtn {
display: block;
}
.title-container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
color: #333;
font-size: 13pt;
}
.author-container {
color: #999;
font-size: 10pt;
margin-top: 3px;
}
.date-container {
color: #333;
font-size: 13pt;
}
.title-container div {
padding: 0 15px;
}
Basically what I want is to use material-angular list inside the article-list.component.html and that it render good like in picture 1
==========================================
If you add a width of 100% to the article component itself it should ensure the component takes the whole width and the list will the whole width as well.
:host {
width: 100%;
}
Take a look at this example here to see the list taking 100% of the width.
I have the grid area template with correct formating, but for some reason, when I add an element and assign it's grid-area, it goes into the next available space in the column. eg: supposed to be middle column bottom row, but instead showed up on the middle column a space away from the privious element. (example shown in code) Also, the spacing is not working eg: 3fr is the same size as a 1fr. (This is in code pen)
fixed this problem in comments
New problem: the numbers are surrounding everything, why?
body {
background-color: rgb(90, 250, 190);
text-align: center;
font-family: 'Alegreya', serif;
min-width: 320px;
}
.container {
min-height: 500px;
width: 98%;
margin: 10px;
display: grid;
background: rgb(255, 255, 255);
grid-template-columns: 30px 3fr 2fr;
grid-template-rows: 0.5fr 1fr 1fr 1fr 3fr 3fr 1fr 3fr 2fr;
grid-template-areas: "description description description" "1 name nameinput"
"2 email emailinput"
"3 age ageinput"
"4 redblueoryellow redblueoryellowinput"
"5 mixedwith mixedwithinput"
"6 lighterordarkerdropdown lighterordarkerdropdowninput"
"7 radiobuttons radiobuttonsinput"
"8 questionsorcomments questionsorcommentsinput"
}
.description {
grid-area: description;
font-size: 30px;
}
.\31 {
grid-area: \31;
}
.\32 {
grid-area: \32;
}
.\33 {
grid-area: \33;
}
.\34 {
grid-area: \34;
}
.\35 {
grid-area: \35;
}
.\36 {
grid-area: \36;
}
.\37 {
grid-area: \37;
}
.\38 {
grid-area: \38;
}
.name {
grid-area: name;
}
.email {
grid-area: email;
}
.questionsorcomments {
grid-area: questionsorcomments;
}
<div class="container">
<p id="description" class="description">
What is your favorite color?
</p>
<p class="1">1.</p>
<p class="2">2.</p>
<p class="3">3.</p>
<p class="4">4.</p>
<p class="5">5.</p>
<p class="6">6.</p>
<p class="7">7.</p>
<p class="8">8.</p>
<p class="name">What is your name?</p>
<p class="email">What is your email?</p>
<p class="questionsorcomments"> Any questions or comments?</p>
</div>
The numbers are supposed to be running down the side. If you want a link to the full codepen then here it is: https://codepen.io/Homburg_Molly/pen/arbzeN
I am using Next.js and SCSS and trying to locate 5 & 3 rows of images at the center of the page with responsive grid system.
I just need to slightly adjust images location to the right side but contents do not move at all.
here is the code :
Next.js
// So basically ui.container wraps up li.item which are images.
<ul className="container">
{stores.map(store => (
<li onClick={this.open} key={store.id} className="item">
<img
src={store.thumb}
onClick={() => this.storeDetail(store.id)}
/>
</li>
))}
</ul>
SCSS
section {
background: pink;
}
.store-list-title {
text-align: center;
padding-top: 2rem;
font-size: 3rem;
}
.container {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(5, 200px);
}
Add justify-content:center for aligining center
.container {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(5, 50px);
justify-content: center;
}
So the solution I found on youtube is using mixin function in SCSS.
It needs calculation so I am still looking at it to understand how it works.
I would be appreciated if someone explains how it works
item element and mixin
#mixin grid($cols, $mgn) {
float: left;
margin-right: $mgn;
margin-bottom: $mgn;
width: ((100% - (($cols - 1) * $mgn)) / $cols);
&:nth-child(#{$cols}n) {
margin-right: 0;
}
}
.item {
#include grid(5, 2%);
img {
width: 100%;
}
}
li tags
{stores.map(store => (
<li onClick={this.open} key={store.id} className="item">
<img
src={store.thumb}
onClick={() => this.storeDetail(store.id)}
alt={`${store.name} image`}
/>
</li>
))}
I am using a Grid layout, and I am trying to place an image next to a text inside of the same griditem. The image is like an icon and supposed to be right next to the text (as it's placed in the code below). The text next to it is also supposed to have a different color and font than the rest of the text. I previously tried this with a span. However, when I use any of those tags inside the griditem it kinda breaks the grid. Instead of being a normal wall of text, it's suddenly all next to each other. I've been trying to figure this out for a couple hours now, can anyone help?
.container {
display: grid;
grid-template: repeat(4, auto) 300px 150px / repeat(6, 1fr);
grid-gap: 3px;
grid-template-areas: ". . h h . ." ". . img img . ." "a a a a a a" ". t t t t ." ". p1 p2 p3 p4 ." ". sm sm hp hp .";
}
.text {
display: flex;
grid-area: t;
font-size: 1vw;
font-family: Verdana;
border: 1px solid #3f3f3f;
border-radius: 25px;
padding: 2%;
}
<div class="container">
<div class="text">Hi!<br><br> Just a quick note to say thank you for making an account with SuperBath.co.uk!
<br><br> Having a SuperBath.co.uk account will give you the following perks:<br>
<br>
<img src="..scratches/Drop.jpg">Saved personal details<br> Personal data is instantly available as you log in with your email address and password. <br><br>
</div>
</div>
The main problem here is that because you use display: flex on text, the img becomes a flex row item and the text before and after the image, will become anonymous flex items, hence they line up side-by-side.
There is mainly two ways to solve that, where one solution is to wrap the whole text/image chunk in a span, and then, to enable a different color on the text next to the img, also wrap it with a span.
Stack snippet
.container {
display: grid;
grid-template: repeat(4, auto) 300px 150px / repeat(6, 1fr);
grid-gap: 3px;
grid-template-areas: ". . h h . ." ". . img img . ." "a a a a a a" ". t t t t ." ". p1 p2 p3 p4 ." ". sm sm hp hp .";
}
.text {
display: flex;
grid-area: t;
font-size: 1vw;
font-family: Verdana;
border: 1px solid #3f3f3f;
border-radius: 25px;
padding: 2%;
}
.text span span {
color: blue /* added */
}
<div class="container">
<div class="text"><span>Hi!
<br>
<br> Just a quick note to say thank you for making an account with SuperBath.co.uk!
<br>
<br> Having a SuperBath.co.uk account will give you the following perks:
<br>
<br>
<img src="http://placehold.it/15/00f"><span>Saved personal details</span>
<br> Personal data is instantly available as you log in with your email address and password.
<br>
<br></span>
</div>
</div>
Or as suggested in a comment, simply remove display: flex from the text, and only wrap the text that should have different color with a span.
Stack snippet
.container {
display: grid;
grid-template: repeat(4, auto) 300px 150px / repeat(6, 1fr);
grid-gap: 3px;
grid-template-areas: ". . h h . ." ". . img img . ." "a a a a a a" ". t t t t ." ". p1 p2 p3 p4 ." ". sm sm hp hp .";
}
.text {
grid-area: t;
font-size: 1vw;
font-family: Verdana;
border: 1px solid #3f3f3f;
border-radius: 25px;
padding: 2%;
}
.text span {
color: blue /* added */
}
<div class="container">
<div class="text">Hi!
<br>
<br> Just a quick note to say thank you for making an account with SuperBath.co.uk!
<br>
<br> Having a SuperBath.co.uk account will give you the following perks:
<br>
<br>
<img src="http://placehold.it/15/00f"><span>Saved personal details</span>
<br> Personal data is instantly available as you log in with your email address and password.
<br>
<br>
</div>
</div>