I am trying to put similar groups of elements in a grid:
#grid {
position: absolute;
left: 135px;
top: 158px;
width: 1080px;
height: 1035px;
display: grid;
grid-template-rows: 99px 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr;
grid-row-gap: 60px;
grid-column-gap: 60px;
grid-template-areas: "headings headings headings"
"content-a content-b content-c"
"content-d content-e content-f";
}
#welcome-heading {
padding-bottom: 10px;
}
#introduction-heading {
padding-bottom: 10px;
}
#headings-section {
grid-area: headings;
}
#content-a {
grid-area: content-a;
}
#content-b {
grid-area: content-b;
}
#content-c {
grid-area: content-c;
}
#content-d {
grid-area: content-d;
}
#content-e {
grid-area: content-e;
}
#content-f {
grid-area: content-f;
}
#content {
text-align: center;
}
#content img {
margin-bottom: 33px;
width: 320px;
height: 240px;
}
#content h4 {
margin-bottom: 20px;
}
.content-title-anchor {
font-size: 18px;
line-height: 18px;
color: #333333;
}
.button {
font-size: 16px;
line-height: 27px;
color: #FFFFFF;
background-color: #FF5A43;
padding: 10px 25px;
border-radius: 4px;
}
<div id="grid">
<section id="headings-section">
<h1 id="welcome-heading">Welcome to Icon Utopia!</h1>
<h3 id="introduction-heading">Everything about iconography and building your career as a designer.</h3>
<p>👇Wondering where to start?👇</p>
</section>
<section id="content">
<div id="content-a">
<img src="index/landing-page.jpg" alt="Guide to: Building your dribbble following.">
<a class="content-title-anchor" href="build-your-dribbble-audience.html">Build Your Dribbble Audience</a>
<h4>A Comprehensive Guide to Building your Dribbble following.</h4>
<a class="button" href="build-your-dribbble-audience.html">Get a FREE Chapter!</a>
</div>
<div id="content-b">
<img src="index/icon-design-guide2-1.jpg" alt="LEARN ICON DESIGN">
<a class="content-title-anchor" href="free-icon-design-guide.html">Free Icon Design Guide</a>
<h4>Everything you need to know about icon design to get started.</h4>
<a class="button" href="free-icon-design-guide.html">Learn Icon Design</a>
</div>
<div id="content-c">
<img src="index/pixel-perfect-icons.jpg" alt="CRAFTING PIXEL PERFECT ICONS">
<a class="content-title-anchor" href="crafting-pixel-perfect-icons-the-right-way.html">Pixel Perfect Course</a>
<h4>Crafting Pixel Perfect Icons The Right Way - learn to create sharp-looking icons!</h4>
<a class="button" href="crafting-pixel-perfect-icons-the-right-way.html">Check out the Course</a>
</div>
<div id="content-d">
<img src="index/space-noise-brushes.jpg" alt="SPACE NOISE: PROCREATE BRUSH SET">
<a class="content-title-anchor" href="https://gumroad.com/l/ojcK">Space Noise Brushes</a>
<h4>Procreate brushes that give your drawings fantastic textures</h4>
<a class="button" href="https://gumroad.com/l/ojcK">Get Noise Brushes</a>
</div>
<div id="content-e">
<img src="index/free-icons.jpg" alt="FREE ICONS">
<a class="content-title-anchor" href="https://iconutopia.com/free-icons/">Free Icons</a>
<h4>Best FREE vector icons and icon sets for personal and commercial use</h4>
<a class="button" href="https://iconutopia.com/free-icons/">Get Free Icons</a>
</div>
<div id="content-f">
<img src="index/icon-utopia-blog-2.jpg" alt="MY BLOG: ICON UTOPIA">
<a class="content-title-anchor" href="blog.html">Icon Utopia Blog</a>
<h4>Blog about making a steady income and building a career as an icon designer.</h4>
<a class="button" href="blog.html">Check out the Blog</a>
</div>
</section>
</div>
But this is the result that I get:
As you can see, the layout is correct for the first row. But the bottom 2 rows should each have 3 columns. Instead, I get 6 rows with one column. I've read this and I think it might have something to do with me nesting the element of each area within a div, but I'm not sure. I can't figure out what I'm supposed to do to get each of the div placed in one 'area' in a grid whose bottom 2 rows have 3 columns each.
Since your content-* elements are not direct children, they are not affected by the #grid parent. You can make your #content element a grid parent.
I changed the grid-template-areas for your #grid element and update the CSS to include styles for the #content element (which you may need to update for your needs)
#grid {
position: absolute;
left: 135px;
top: 158px;
width: 1080px;
height: 1035px;
display: grid;
grid-template-rows: 99px 1fr;
grid-template-columns: 1fr;
grid-row-gap: 60px;
grid-template-areas: "headings" "content"
}
#content {
display: grid;
width: 100%;
display: grid;
grid-template-rows: repeat(2, 1fr);
grid-template-columns: repeat(3, 1fr);
grid-row-gap: 60px;
grid-column-gap: 60px;
grid-template-areas: "content-a content-b content-c" "content-d content-e content-f";
grid-area: content;
}
#welcome-heading {
padding-bottom: 10px;
}
#introduction-heading {
padding-bottom: 10px;
}
#headings-section {
grid-area: headings;
}
#content-a {
grid-area: content-a;
}
#content-b {
grid-area: content-b;
}
#content-c {
grid-area: content-c;
}
#content-d {
grid-area: content-d;
}
#content-e {
grid-area: content-e;
}
#content-f {
grid-area: content-f;
}
#content {
text-align: center;
}
#content img {
margin-bottom: 33px;
width: 320px;
height: 240px;
}
#content h4 {
margin-bottom: 20px;
}
.content-title-anchor {
font-size: 18px;
line-height: 18px;
color: #333333;
}
.button {
font-size: 16px;
line-height: 27px;
color: #FFFFFF;
background-color: #FF5A43;
padding: 10px 25px;
border-radius: 4px;
}
<div id="grid">
<section id="headings-section">
<h1 id="welcome-heading">Welcome to Icon Utopia!</h1>
<h3 id="introduction-heading">Everything about iconography and building your career as a designer.</h3>
<p>👇Wondering where to start?👇</p>
</section>
<section id="content">
<div id="content-a">
<img src="index/landing-page.jpg" alt="Guide to: Building your dribbble following.">
<a class="content-title-anchor" href="build-your-dribbble-audience.html">Build Your Dribbble Audience</a>
<h4>A Comprehensive Guide to Building your Dribbble following.</h4>
<a class="button" href="build-your-dribbble-audience.html">Get a FREE Chapter!</a>
</div>
<div id="content-b">
<img src="index/icon-design-guide2-1.jpg" alt="LEARN ICON DESIGN">
<a class="content-title-anchor" href="free-icon-design-guide.html">Free Icon Design Guide</a>
<h4>Everything you need to know about icon design to get started.</h4>
<a class="button" href="free-icon-design-guide.html">Learn Icon Design</a>
</div>
<div id="content-c">
<img src="index/pixel-perfect-icons.jpg" alt="CRAFTING PIXEL PERFECT ICONS">
<a class="content-title-anchor" href="crafting-pixel-perfect-icons-the-right-way.html">Pixel Perfect Course</a>
<h4>Crafting Pixel Perfect Icons The Right Way - learn to create sharp-looking icons!</h4>
<a class="button" href="crafting-pixel-perfect-icons-the-right-way.html">Check out the Course</a>
</div>
<div id="content-d">
<img src="index/space-noise-brushes.jpg" alt="SPACE NOISE: PROCREATE BRUSH SET">
<a class="content-title-anchor" href="https://gumroad.com/l/ojcK">Space Noise Brushes</a>
<h4>Procreate brushes that give your drawings fantastic textures</h4>
<a class="button" href="https://gumroad.com/l/ojcK">Get Noise Brushes</a>
</div>
<div id="content-e">
<img src="index/free-icons.jpg" alt="FREE ICONS">
<a class="content-title-anchor" href="https://iconutopia.com/free-icons/">Free Icons</a>
<h4>Best FREE vector icons and icon sets for personal and commercial use</h4>
<a class="button" href="https://iconutopia.com/free-icons/">Get Free Icons</a>
</div>
<div id="content-f">
<img src="index/icon-utopia-blog-2.jpg" alt="MY BLOG: ICON UTOPIA">
<a class="content-title-anchor" href="blog.html">Icon Utopia Blog</a>
<h4>Blog about making a steady income and building a career as an icon designer.</h4>
<a class="button" href="blog.html">Check out the Blog</a>
</div>
</section>
</div>
You can technically remove the grid display from #grid since you don't necessarily need it, since your #headings-section is full-width anyway.
#grid {
position: absolute;
left: 135px;
top: 158px;
width: 1080px;
height: 1035px;
}
#content {
display: grid;
width: 100%;
display: grid;
grid-template-rows: repeat(2, 1fr);
grid-template-columns: repeat(3, 1fr);
grid-row-gap: 60px;
grid-column-gap: 60px;
grid-template-areas: "content-a content-b content-c" "content-d content-e content-f";
}
#welcome-heading {
padding-bottom: 10px;
}
#introduction-heading {
padding-bottom: 10px;
}
#headings-section {
grid-area: headings;
}
#content-a {
grid-area: content-a;
}
#content-b {
grid-area: content-b;
}
#content-c {
grid-area: content-c;
}
#content-d {
grid-area: content-d;
}
#content-e {
grid-area: content-e;
}
#content-f {
grid-area: content-f;
}
#content {
text-align: center;
}
#content img {
margin-bottom: 33px;
width: 320px;
height: 240px;
}
#content h4 {
margin-bottom: 20px;
}
.content-title-anchor {
font-size: 18px;
line-height: 18px;
color: #333333;
}
.button {
font-size: 16px;
line-height: 27px;
color: #FFFFFF;
background-color: #FF5A43;
padding: 10px 25px;
border-radius: 4px;
}
<div id="grid">
<section id="headings-section">
<h1 id="welcome-heading">Welcome to Icon Utopia!</h1>
<h3 id="introduction-heading">Everything about iconography and building your career as a designer.</h3>
<p>👇Wondering where to start?👇</p>
</section>
<section id="content">
<div id="content-a">
<img src="index/landing-page.jpg" alt="Guide to: Building your dribbble following.">
<a class="content-title-anchor" href="build-your-dribbble-audience.html">Build Your Dribbble Audience</a>
<h4>A Comprehensive Guide to Building your Dribbble following.</h4>
<a class="button" href="build-your-dribbble-audience.html">Get a FREE Chapter!</a>
</div>
<div id="content-b">
<img src="index/icon-design-guide2-1.jpg" alt="LEARN ICON DESIGN">
<a class="content-title-anchor" href="free-icon-design-guide.html">Free Icon Design Guide</a>
<h4>Everything you need to know about icon design to get started.</h4>
<a class="button" href="free-icon-design-guide.html">Learn Icon Design</a>
</div>
<div id="content-c">
<img src="index/pixel-perfect-icons.jpg" alt="CRAFTING PIXEL PERFECT ICONS">
<a class="content-title-anchor" href="crafting-pixel-perfect-icons-the-right-way.html">Pixel Perfect Course</a>
<h4>Crafting Pixel Perfect Icons The Right Way - learn to create sharp-looking icons!</h4>
<a class="button" href="crafting-pixel-perfect-icons-the-right-way.html">Check out the Course</a>
</div>
<div id="content-d">
<img src="index/space-noise-brushes.jpg" alt="SPACE NOISE: PROCREATE BRUSH SET">
<a class="content-title-anchor" href="https://gumroad.com/l/ojcK">Space Noise Brushes</a>
<h4>Procreate brushes that give your drawings fantastic textures</h4>
<a class="button" href="https://gumroad.com/l/ojcK">Get Noise Brushes</a>
</div>
<div id="content-e">
<img src="index/free-icons.jpg" alt="FREE ICONS">
<a class="content-title-anchor" href="https://iconutopia.com/free-icons/">Free Icons</a>
<h4>Best FREE vector icons and icon sets for personal and commercial use</h4>
<a class="button" href="https://iconutopia.com/free-icons/">Get Free Icons</a>
</div>
<div id="content-f">
<img src="index/icon-utopia-blog-2.jpg" alt="MY BLOG: ICON UTOPIA">
<a class="content-title-anchor" href="blog.html">Icon Utopia Blog</a>
<h4>Blog about making a steady income and building a career as an icon designer.</h4>
<a class="button" href="blog.html">Check out the Blog</a>
</div>
</section>
</div>
Related
I am trying to create a simple grid block with minimal css but it causes cls problem, The tags that are causing cumulative layout shift: h3, img, div, p, almost all of the block.
I tried to add more css to that tags but couldn't find a way to solve it.
First div is larger than other two divs and last two divs has same size
My codes are as follows:
.grid-section {
display: grid;
grid-template-columns: repeat(3, 48% 25% 25%);
grid-gap: 1%;
margin-bottom: 40px;
}
.grid-section img {
width: 100%;
margin-bottom: 20px;
}
.grid-section h3 {
margin-bottom: 5px;
}
.grid-section a {
display: inline-block;
padding-top: 10px;
color: #0067b8;
text-transform: uppercase;
font-weight: bold;
}
.grid-section a:hover i {
margin-left: 10px;
}
#media(max-width: 768px) {
.grid-section {
grid-template-columns: repeat(2, 1fr);
}
.grid-section :first-child {
grid-column: 1 / -1;
}
}
#media(max-width: 500px) {
.grid-section {
grid-template-columns: 1fr;
}
}
<section class="grid-section">
<div>
<img src="bvvvvvvvvvv/1.webp" class="img-fluid" alt="" width="100%" height="100%" />
<h3>Save $150 + free controller</h3>
<p>
Buy an Xbox One X console and double your fun with a free select
extra controller. Starting at $349.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
<div>
<img src="bvvvvvvvvvv/1.webp" class="img-fluid" alt="" width="100%" height="100%" />
<h3>Save $150 + free controller</h3>
<p>
Buy an Xbox One X console and double your fun with a free select
extra controller. Starting at $349.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
<div>
<img src="bvvvvvvvvvv/2.webp" class="img-fluid" alt="" width="100%" height="100%" />
<h3>The new Microsoft Edge</h3>
<p>
Expect more. World class performance, with more privacy, more
productivity, and more value.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
</section>
Any help will be appreciated. Thanks
ok with your demo, I better see what you are looking for.
simplest solution would be to use background image for the div which contain the image and the text. This solution already needs more structure in your html, but if you want to go with "img" tag, html structure will be at least 2 times more complex.
look at the snippet and try it in mobile view.
.grid-section {
display: grid;
grid-template-columns: repeat(3, 48% 25% 25%);
grid-gap: 1%;
margin-bottom: 40px;
}
.grid-section>div {
position: relative;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
min-height: 400px;
}
.grid-section .content {
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 1em;
margin: 1em;
background-color: rgba(255, 255, 255, 0.5);
}
.grid-section h3 {}
.grid-section a {
display: inline-block;
padding-top: 10px;
color: #0067b8;
text-transform: uppercase;
font-weight: bold;
}
.grid-section a:hover i {
margin-left: 10px;
}
#media (max-width: 768px) {
.grid-section {
grid-template-columns: repeat(2, 1fr);
}
.grid-section :first-child {
grid-column: 1 / -1;
}
}
#media (max-width: 500px) {
.grid-section {
grid-template-columns: 1fr;
}
}
<section class="grid-section">
<div style="background-image: url('https://picsum.photos/id/20/800/600')">
<div class="content">
<h3>Save $150 + free controller</h3>
<p>
Buy an Xbox One X console and double your fun with a free select extra controller. Starting at $349.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
</div>
<div style="background-image: url('https://picsum.photos/id/32/800/600')">
<div class="content">
<h3>Save $150 + free controller</h3>
<p>
Buy an Xbox One X console and double your fun with a free select extra controller. Starting at $349.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
</div>
<div style="background-image: url('https://picsum.photos/id/43/800/600')">
<div class="content">
<h3>The new Microsoft Edge</h3>
<p>
Expect more. World class performance, with more privacy, more productivity, and more value.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
</div>
</section>
I have these 2 divs (footer-txt and footer-img), on the mobile it works perfectly because I want the text on top and the 2 images on the bottom, like side by side.
But when the screen gets wider, I want the 2 images side by side and also the text div. Like a row with the 2 images and the text.
Is there a way that I can do this?
#footer {
background-color: #98AFFF;
}
.footer-txt {
font-size: 14px;
color: #464646;
text-align: left;
}
.footer-img {
display: flex;
gap: 25px;
}
<footer class="text-center text-lg-start" id="footer">
<div class="p-4" id="footer-content">
<div class="pb-2 footer-txt">
PROTESTE
</div>
<div class="pt-4 pb-2 justify-content-center footer-img">
<a href="#">
<img src="images/pag1/Mask group (1).png" alt="Google">
</a>
<a href="#">
<img src="images/pag1/Mask group.png" alt="Google">
</a>
</div>
</div>
</footer>
Well, if i understand correctly you can put this css in id #footer-content:
#footer-content {
display: flex;
flex-direction: row;
}
That way you change the direction of your div to as if it were a row.
If you only need this for when you're not mobile, you can add the following line:
#media screen and (min-width: 960px) {
#footer-content {
display: flex;
flex-direction: row;
}
}
The desired solution can be achieved using either Flex-Box or Grid & Responsive CSS using Media Queries
Flex Box
Grid Layout
Media Query
#footer {
background-color: #98AFFF;
}
#footer-content {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 25px;
}
.footer-txt {
font-size: 14px;
color: #464646;
text-align: left;
}
.footer-img {
display: flex;
gap: 25px;
}
/* Styling for Smaller Screens */
#media screen and (max-width: 500px) {
#footer-content {
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
}
<footer class="text-center text-lg-start" id="footer">
<div class="p-4" id="footer-content">
<div class="pb-2 footer-txt">
PROTESTE
</div>
<div class="pt-4 pb-2 justify-content-center footer-img">
<a href="#">
<img src="images/pag1/Mask group (1).png" alt="Google">
</a>
<a href="#">
<img src="images/pag1/Mask group.png" alt="Google">
</a>
</div>
</div>
</footer>
You have to make the text and both of the images a flex item. You achive this by defining the flex property on the footer-content. All of its direct children are then flex-items.
Very good explanation of flex can be found here:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
If my solution is not what are you looking for you are maybe also looking for breakpoints and media queries for a responsive design.
#footer {
background-color: #98AFFF;
}
.footer-txt {
font-size: 14px;
color: #464646;
text-align: left;
}
#footer-content {
display: flex;
flex-wrap: wrap;
}
<footer id="footer">
<div id="footer-content">
<div class="footer-txt">
PROTESTE
</div>
<div class="footer-img">
<a href="#">
<img src="images/pag1/Mask group (1).png" alt="Google">
</a>
</div>
<div class="footer-img">
<a href="#">
<img src="images/pag1/Mask group.png" alt="Google">
</a>
</div>
</div>
</footer>
I am trying to resize first column in grid searched on google but couldnt find the solution.
I can do it with css but want to learn how to resize repeated columns in grid.
I want first card to be width: 50%; and other two cards width:25%; and width:25%;
Here is my codes
.slider-cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
margin-bottom: 40px;
}
.slider-cards img {
width: 100%;
margin-bottom: 20px;
}
.slider-cards h3 {
margin-bottom: 5px;
}
.slider-cards a {
display: inline-block;
padding-top: 10px;
color: #0067b8;
text-transform: uppercase;
font-weight: bold;
}
.slider-cards a:hover i {
margin-left: 10px;
}
<div class="slider-cards">
<div class="first">
<img src="https://i.ibb.co/LZPVKq9/card1.png" alt="">
<h3>The Conversation has reported</h3>
<p>
COVID-19 has had a deeply unequal impact on UK society, affecting some communities substantially more than others.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
<div class="second">
<img src="https://i.ibb.co/LZPVKq9/card1.png" alt="">
<h3>The Conversation has reported</h3>
<p>
COVID-19 has had a deeply unequal impact on UK society, affecting some communities substantially more than others.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
<div class="third">
<img src="https://i.ibb.co/LZPVKq9/card1.png" alt="">
<h3>The Conversation has reported</h3>
<p>
COVID-19 has had a deeply unequal impact on UK society, affecting some communities substantially more than others.
</p>
Learn More <i class="fas fa-chevron-right"></i>
</div>
</div>
:
I am trying to build a section of a website which consists of 3 containers aligned horizontally and a footer.
The containers has a class of class="box" and the footer is simply denoted as <footer>. The container is also nested in a section with id="boxes".
When a property of float: left; is applied to the class="box", the entire section of id="boxes" seems to vanish. The contents of class="box" nested within the section id="box" is still visible but the <footer> represents the whole region instead on section id="box".
Please see figure below
Seek advise if this is an expected behavior and how can I achieve the style that I am looking for :
3 Containers, horizontally aligned
Footer at the bottom
Thanks!
ps: see below for attached snippet to see the issue that is being faced. notice that the <footer> cannibalises the <section id="boxes"> region.
#boxes .box {
text-align: center;
float: left;
margin-top: 20px;
width: 30%;
padding: 10px;
}
#boxes .box img {
width: 90px;
}
footer {
float: center;
text-align: center;
padding: 20px;
color: white;
background: orangered;
}
<section id="boxes">
<div class="box">
<h1>SMRT Logo</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
<div class="box">
<h1>Pimentos Del Pardon</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
<div class="box">
<h1>Tomato Plant</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
</section>
<footer>
This is the fourth project &cc 2021
</footer>
float: center doesn't exist. What you're trying to do is have the footer clear the floating boxes. When it's not doing that, the behavior you're seeing is expected. You do that with clear: both (or clear: left, either works, but most people use "both" in case there are floats coming from both directions):
#boxes .box {
text-align: center;
float: left;
margin-top: 20px;
width: 30%;
padding: 10px;
}
#boxes .box img {
width: 90px;
}
footer {
clear: both;
text-align: center;
padding: 20px;
color: white;
background: orangered;
}
<section id="boxes">
<div class="box">
<h1>SMRT Logo</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
<div class="box">
<h1>Pimentos Del Pardon</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
<div class="box">
<h1>Tomato Plant</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
</section>
<footer>
This is the fourth project &cc 2021
</footer>
These days grid and flexbox are the more viable layout options and are widely supported. I recommend learning these eventually so you no longer have to worry about floats. Here's a grid example (which has the bonus of truly centering the boxes, where they were off-center before in your float layout):
#boxes {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
#boxes .box {
text-align: center;
margin-top: 20px;
padding: 10px;
}
#boxes .box img {
width: 90px;
}
footer {
text-align: center;
padding: 20px;
color: white;
background: orangered;
}
<section id="boxes">
<div class="box">
<h1>SMRT Logo</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
<div class="box">
<h1>Pimentos Del Pardon</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
<div class="box">
<h1>Tomato Plant</h1>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
</div>
</section>
<footer>
This is the fourth project &cc 2021
</footer>
So basically I need to create a 3 grid layout which looks like:
-------------------------------------
| Image | The name of logo | > |
-------------------------------------
I have somewhat do this with :
<div class="panel panel-default">
<div class="card-header">
<a class="card-link row" href="/webview/topup">
<p style="font-size: 14sp; margin-bottom: 0">
<img src="../images.png" th:src="#{../images/image.png}" width="10%"
height="10%" style="vertical-align: middle; font-family: 'Barlow', sans-serif;">
The name of logo
<img src="../arrow.png" th:src="#{../arrow.png}" width="2%" height="2%"
style="vertical-align: middle;" align="right";>
</p>
</a>
</div>
</div>
But somehow my arrow is not centered because it only uses align right. How can I make my arrow to be align right and centered at the same time?
Im sorry to ask such basic questions, because Im kinda new to html/css. Thanks.
There are multiple methods to achieve this.
You can use flexbox on the parent:
{
display: flex;
align-items: center;
justify-content: flex-start;
}
and add:
{
margin-left: auto;
}
to the last child. In your example, the arrow.
A good visual introduction/overview of flexbox is available here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
A concrete example of this with your code:
.card-link {
display: flex;
align-items: center;
justify-content: flex-start;
}
.arrow {
margin-left: auto;
width: 1em;
height: 1em;
}
.logo {
width: 2em;
height: 2em;
}
img {
width: 100%;
height: auto
}
<div class="panel panel-default">
<div class="card-header">
<a class="card-link row" href="/webview/topup">
<img class="logo" src="https://via.placeholder.com/150">
<p class="text">The name of logo </p>
<img class="arrow" src="https://via.placeholder.com/150">
</a>
</div>
</div>
This can be done using css "grid" or "flex". You can refer to many
articles related to 'css flex' and 'css grid'. You can easily align
items in both vertical and horizontal. And there are many ways to align items inside a grid. This will be suitable for your case.
.grid {
display: grid;
height: 100px;
background-color: #f9f9f9;
grid-template-columns: auto 1fr auto;
align-items: center;
grid-gap: 20px;
}
<div class="grid">
<div>Image</div>
<div>The name of logo</div>
<div>></div>
</div>