HTML divs not properly displaying as a grid - html

I need to put these divs into a grid so that they display on the screen in a grid as opposed to a block. I have them displayed in a block and centered on the screen for smaller screen widths and after a certain screen width I would like them to display as a grid, but I keep getting the buttons and text displaying to the right of the images as opposed to displaying under the images. Here is my HTML and CSS code...
<section>
<div class="container-2">
<div class="wrapper-2">
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://atlas-content-cdn.pixelsquid.com/stock-images/shirt-men-181dmv4-600.jpg" alt="Image cannot be displayed">
<h2>Men's slim fit blue plaid shirt</h2>
<p>$50.00</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://watchdreamer.com/sites/default/files/styles/soldat_md/public/2021-05/WBP201A.BA0632_.png?h=7afb1587&itok=EH_sMV2B" alt="Image cannot be displayed">
<h2>Men's silver and black time piece</h2>
<p>$499.99</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom" data-aos="fade-right" data-aos-duration="800"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://www.pngall.com/wp-content/uploads/5/Brown-Men-Shoes-PNG-Image.png" alt="Image cannot be displayed">
<h2>Men's Uncle Tom dress shoes</h2>
<p>$44.99</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom" data-aos="fade-right" data-aos-duration="800"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://i5.walmartimages.com/asr/b19cdda5-932f-4862-a7b3-b7440bfb759e_1.87f4ae5495ec75a86d5f6e4572e807d3.jpeg?odnHeight=612&odnWidth=612&odnBg=FFFFFF" alt="Image cannot be displayed">
<h2>Men's slim black slim fit dress pants</h2>
<p>$70.00</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom" data-aos="fade-right" data-aos-duration="800"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://www.suitsexpert.com/wp-content/uploads/2019/01/silk-tie.png" alt="Image cannot be displayed">
<h2>Men's formal red tie</h2>
<p>$19.99</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
</div>
</div>
</section>
<style>
.container-2 {
width: 90%;
display: block;
margin: 0 auto 0 auto;
}
.boxes {
display: grid;
justify-content: space-evenly;
grid-template-columns: 220px 220px 220px;
}
</style>

You need to change .boxes class. When grid-template-columns property is used, it will create columns that put your text and button to the side of your image.
.boxes {
display: grid;
width: 50%;
margin: 0 auto;
}
Also, you can add width and height to your image so that it does not go out of the grid width.

You don't put display:grid; at the boxes you want to be a part of the grid. But you put it in the container. This would be an example
.container-2 {
display:grid;
gap:1rem;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-template-rows: 200px;
}
then you can remove the .wrapper-2 element

Related

Why is my outline top not showing in CSS?

Im styling multiple boxes, it's only the first box whose top outline is not working. Here's my code. I'm using bootstrap in React. Border works. I have attached the relevent css.
EDIT: I hacked it by setting my outline-offset to negative the amount of pixels. so -3. Worked fine for me, and am wondering how it happened and how to avoid it.
.savedMeme--card {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: 100%;
padding: 10px;
}
.savedMeme--card:hover {
background-color: #e3e3e3c4;
outline: 3px solid var(--blue);
}
<div className="offcanvas offcanvas-end" tabIndex="-1" id="sidebar" aria-labelledby="sidebar--header">
<div className="offcanvas-header">
<h2 className="offcanvas-title" id="sidebar--header">Your saved memes</h2>
<button className="btn-close" data-bs-dismiss="offcanvas" type="button" aria-label="Close"></button>
</div>
<div className="offcanvas-body p-0">
<div className="savedMeme--card">
<!-- this is an imported component -->
<div className="savedMeme--header">
<span className="bi bi-bookmark-x-fill"></span>
<img src={props.url} style={{ width: "80px", height: "80px" }} alt="meme" />
</div>
<div className="savedMeme-body">
<p>
{props.topText}...
</p>
<p className="savedMeme--view-meme">view meme</p>
</div>
</div>
</div>
</div>
</div>
</div>
I have fixed your closing div tag issue and changed className to class and just defined css variable
:root {
--blue: blue;
}
Everything seems to works fine on hover.
:root {
--blue: blue;
}
.savedMeme--card {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: 100%;
padding: 10px;
}
.savedMeme--card:hover {
background-color: #e3e3e3c4;
outline: 3px solid var(--blue);
}
<div class="offcanvas offcanvas-end" tabIndex="-1" id="sidebar" aria-labelledby="sidebar--header">
<div class="offcanvas-header">
<h2 class="offcanvas-title" id="sidebar--header">Your saved memes</h2>
<button class="btn-close" data-bs-dismiss="offcanvas" type="button" aria-label="Close"></button>
</div>
<div class="offcanvas-body p-0">
<div class="savedMeme--card">
<!-- this is an imported component -->
<div class="savedMeme--header">
<span class="bi bi-bookmark-x-fill"></span>
<img src={props.url} style={{ width: "80px" , height: "80px" }} alt="meme" />
</div>
<div class="savedMeme-body">
<p>
{props.topText}...
</p>
<p class="savedMeme--view-meme">view meme</p>
</div>
</div>
</div>
</div>

I am having trouble aligning grid container with the width of the website

I am not sure why my CSS image grid is not aligning with the length of the webpage, even though I have made the length and width the same as the 1200px.
Note: When I open the inspect tool in google. It states that the width is 1184, however, when I change it to 1200px it doesn't fix the problem
My goal is to have this CSS grid to be 1200px * 500px. I really appreciate any help you can provide.
img {
width: 400px;
height: 250px;
}
.container-2 {
margin-top: 2em;
background-color: rgb(50, 100, 0);
display: grid;
grid-template-rows: 250px 250px;
grid-template-columns: repeat(3, 400px);
}
.photo_caption {
position: absolute;
}
<div class="container-2">
<div class="pic-1">
<img src="images/sailboat.jpg" alt="sailing" />
</div>
<div class="pic-2">
<img src="images/water.jpg" alt="oceanside" />
</div>
<div class="pic-3">
<img src="images/pool.jpg" alt="swimming pool" />
</div>
<div class="pic-4">
<img src="images/tree.jpg" alt="oceanview" />
</div>
<div class="pic-5">
<img src="images/side-wall.jpg" alt="campground" />
</div>
<div class="pic-6">
<p class="photo_caption">
We're dog-friendly... If your dog is friendly, too!</p>
<img src="images/dog.jpg" alt="dog friendly" />
</div>
</div>

Put a text beneath an image

I am currently working on a website and what i want to do is I want four pictures in a square and I want a text underneath them.
I already managed to put the four images but once i try to put a text it goes everywhere but not underneath the images
HTML:
<section class="section-2">
<div class="item">
<img src="#">
<p>text</p>
</div>
<div class="item">
<img src="#">
<p>text</p>
</div>
<div class="item">
<img src="#">
<p>text</p>
</div>
<div class="item">
<img src="#">
<p>text</p>
</div>
</section>
CSS:
.section-2 {
margin: 200px 30px 30px 30px;
width:100%;
float:right;
min-height:1000px;
height:100%;
}
img {
float:left;
margin: 0px 100px 200px 150px;
width: 30%;
height: 30%;
The easiest and shortes way would be to simply align the cards in a grid. For that use display: grid;. To have 2 cards aligned horizontally you need to add: grid-template-columns: repeat(2, 1fr); you can change the number 2 with the numebr of cards you want to have aligned next to each other. To seperate the cards from each other, you can use grid-gap: with a value of the gap you want to have.
.section-2 {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 15px;
}
.section-2 div img {
width: 100%;
}
<section class="section-2">
<div>
<img src="https://www.tacoshy.de/Images/Yoshi/IMAG0735.jpg">
<p>I'm a Syrian Hamster</p>
</div>
<div>
<img src="https://www.tacoshy.de/Images/Yoshi/IMAG0736.jpg">
<p>I like to eat watermelons</p>
</div>
<div>
<img src="https://www.tacoshy.de/Images/Areno/IMAG0865.jpg">
<p>I love to burrow tunnels and caves</p>
</div>
<div>
<img src="https://www.tacoshy.de/Images/Areno/IMAG0863.jpg">
<p>And I really enjoy sleeping in my self digged caves</p>
</div>
</section>

How do I control the size of images using CSS grid?

I'm trying to set 9 images in a 3x3 grid, all of them with the same height and width. I'm able to set the grid but a couple of the images are smaller than the rest. Below I'm only showing how I formatted one of the photos. The HTML is the same for the other 8 photos.
.items {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.item > img {
object-fit: cover;
width: 100%;
max-height: 100%;
}
<div class="container">
<div class="items">
<div class="item">
<div class="item-image">
<img src="/dist/img_resources/vector1.jpg" alt="">
</div>
<div class="item-text">
<p class="item-description">Lorem, ipsum.</p>
<p class="item-price">$X.XX</p>
</div>
</div>
</div>
</div>

css styling with bulma cards

I do have the following HTML output:
so, as you can see the footer isn't matching...
my css component looks like this:
.card-equal-height {
display: flex;
flex-direction: column;
height: 100%;
}
.card-equal-height
.card-footer {
margin-top: auto;
height: 100%;
}
.card-equal-height.card-footer this part is not working somehow. I want the footer to be matching the order cards, no matter how long the description is.
html:
<div [ngClass]="{'card-highlight': product.listItemHovered}" class="card card-equal-height"
(mouseenter)="hoverListItem(product)"
(mouseleave)="hoverListItem(product)"
(click)="test(product)">
<div class="card-image">
<figure class="image is-square">
<img [src]="product.imageURL" alt="{{product.title}}">
</figure>
</div>
<div class="card-content">
<p class="title has-text-centered"> {{product.title}}</p>
<p class="subtitle">{{product.price | currency: "USD"}}</p>
</div>
<div class="card-footer">
<p class="card-footer-item">
<button (click)="removeFromCart(product); showRemoved()"
class="button is-danger is-outlined is-pulled-left is-small"> Remove
</button>
</p>
<p class="card-footer-item">
<button (click)="addToCart(product);showAdded()"
class="button is-outlined is-primary is-pulled-right is-small"> Add to Cart
</button>
</p>
</div>
</div>
I think you can achieve changing the height of "card-content" (forget change the .card-footer) using flex-grow
.card-equal-height
.card-content {
flex-grow:1;
}
For more about flex, check this link in css-tricks