How to align a text outside and below a box? - html

So, I'm taking a course in TOP its basically a about web development. Right now I'm working in a project that the website wants me to do.
I've been facing a problem lately regarding aligning a text outside and below a box (div).
.title{
text-align: center;
font-size:36px;
font-weight: bolder;
color: #1F2937;
margin-top: 45px;
}
.second_container{
display: flex;
justify-content: center;
/* align-items: center; */
padding: 30px 0px;
gap:32px;
}
.image{
border: 4px solid dodgerblue;
border-radius: 8px;
width: 150px;
height: 150px;
text-align: center;
}
span.txt{
font-size: 18px;
}
<div class="title">
Some random Information.
</div>
<div class="second_container">
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration
or image.
</span>
</div>
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration
or image.
</span>
</div>
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration
or image.
</span>
</div>
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration
or image.
</span>
</div>
</div> <!--end of the random info container-->
I'm always getting the text inside the box. But I need the text outside and below it

Your text is nested in .image which has the border so it will always be inside without absolute positioning. Put the border on where the img will be, in this case, .img. Then the text will flow underneath.
.title {
text-align: center;
font-size: 36px;
font-weight: bolder;
color: #1F2937;
margin-top: 45px;
}
.second_container {
display: flex;
justify-content: center;
/* align-items: center; */
padding: 30px 0px;
gap: 32px;
}
.img {
border: 4px solid dodgerblue;
height: 150px;
border-radius: 8px;
text-align: center;
}
.image {
width: 150px;
}
span.txt {
font-size: 18px;
}
<!--start of the random info container-->
<div class="title">
Some random Information.
</div>
<div class="second_container">
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration or image.</span>
</div>
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration or image.</span>
</div>
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration or image.</span>
</div>
<div class="image">
<div class="img"></div>
<span class="txt">This is some subtext under an illustration or image.</span>
</div>
</div>
<!--end of the random info container-->

Related

Give a Specific Part of a Text Component Colour

Basically, I have some text with a border as such.
However, I want to achieve something like this, where the top bit has an orange colour and there are icons, how do I do so?
Code:
<div>
<p style="font-family: 'Space Grotesk'; margin-top: 100px; margin-left: 230px; border: 2px solid black; width: 250px; padding-left: 20px; height: 280px; padding-top: 40px; border-radius: 10px;">Awesome product! Works well. Easy to wear, great color scheme, does not tear easily and came home in under two days. Worth every rupee, it really helped me save money from buying the one-time use patches and rubber patches and has been a great experience with the patch.</p>
<hr style="height: 2px; background-color: black; margin-top: -314px; width: 270px; margin-left: 232px; border: none; position: relative;">
<h3 style="font-family: 'Space Grotesk'; margin-top: 230px; margin-left: 350px;">Rishan Reddy</h3>
<h3 style="font-family: 'Space Grotesk'; margin-left: 420px; margin-top: -12px;">Indus</h3>
</div>
Also, I want to make three of these divs side by side. How do I accomplish that?
Use fontawesome for your ellipsis. The header and content can be done as two divs in a container as below. It should be self-explanatory however if not, drop me a comment and I'll elaborate
.container {
border: 2px solid black;
border-radius: 1rem;
width: fit-content;
max-width: 30ch;
overflow: hidden;
min-height:10rem;
}
p {
margin: 0;
}
.header {
font-size: 1.5em;
background-color: #FFBF23;
line-height: 1.5rem;
padding-inline: 1rem;
border-bottom: 2px solid black;
}
.content {
padding: 1.5rem 1rem;
}
.signature-container {
margin-top:0.5rem;
display: flex;
justify-content: flex-end;
}
.review-container {
display:grid;
gap:1rem;
grid-template-columns:repeat(3, fit-content(30ch));
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class='review-container'>
<div class='container'>
<div class='header'>
<i class="fa-solid fa-ellipsis"></i>
</div>
<div class='content'>
<p>This is Review 1</p>
<div class='signature-container'>
<div>
<p>Adam Silver</p>
<p>Ashburn</p>
<p>Virginia</p>
</div>
</div>
</div>
</div>
<div class='container'>
<div class='header'>
<i class="fa-solid fa-ellipsis"></i>
</div>
<div class='content'>
<p>This is Review 2</p>
<div class='signature-container'>
<div>
<p>Adam Silver</p>
<p>Ashburn</p>
<p>Virginia</p>
</div>
</div>
</div>
</div>
<div class='container'>
<div class='header'>
<i class="fa-solid fa-ellipsis"></i>
</div>
<div class='content'>
<p>This is Review 3</p>
<div class='signature-container'>
<div>
<p>Adam Silver</p>
<p>Ashburn</p>
<p>Virginia</p>
</div>
</div>
</div>
</div>
<div class='container'>
<div class='header'>
<i class="fa-solid fa-ellipsis"></i>
</div>
<div class='content'>
<p>This is Review 4</p>
<div class='signature-container'>
<div>
<p>Adam Silver</p>
<p>Ashburn</p>
<p>Virginia</p>
</div>
</div>
</div>
</div>
</div>

Card design in CSS

I've been asked to design this section of a webpage from figma
Using the figma tools I can see that it is a card of 453 x 512 px and has a padding of 30px on top left and bottom and image is 393 x280 px . There is a 30px margin between the card image and card body after which it is a standard h1 paragraph and link tag. The following is my code implementation.
.blog {
display: flex;
flex-direction: column;
align-items: center;
}
.blog .icons {
display: flex;
flex-direction: row;
}
.card {
width: 453px;
height: 512px;
padding: 30px;
}
<section class="blog">
<h1>We have Most of Popular Departments</h1>
<div class="icons">
<div class="card">
<img src="./assets/ai.svg" alt="image1" class="top" />
<h3>Artificial Intelligence</h3>
<p>
Assertively parallel task synergistic deliverables after high-quality.
</p>
Learn More
</div>
<div class="card">
<div class="card-top">
<img src="./assets/civil.svg" alt="image1" />
</div>
<div class="card-body">
<h3>Civil Engineering</h3>
<p>
Assertively parallel task synergistic deliverables after high-quality.
</p>
Learn More
</div>
</div>
<div class="card">
<img src="./assets/business.svg" alt="image1" class="top" />
<h3>Business Strategy</h3>
<p>
Assertively parallel task synergistic deliverables after high-quality.
</p>
Learn More
</div>
</div>
<button class="btn btn-secondary">View All Departments</button>
</section>
This what my card looks like:
I figured out a solution and it works pretty well. Here is the code.
<div class="cards">
<div class="card">
<img src="/Untitled.png" alt="" />
<div class="container">
<h1>Artificial Intelligence</h1>
<p>
Assertively parallel task synergistic deliverables after
high-quality.
</p>
<a href="#"
>Learn More <i class="fa-solid fa-arrow-right-long"></i
></a>
</div>
</div>
<div class="card">
<img src="/Untitled.png" alt="" />
<div class="container">
<h1>Artificial Intelligence</h1>
<p>
Assertively parallel task synergistic deliverables after
high-quality.
</p>
<a href="#"
>Learn More <i class="fa-solid fa-arrow-right-long"></i
></a>
</div>
</div>
<div class="card">
<img src="/Untitled.png" alt="" />
<div class="container">
<h1>Artificial Intelligence</h1>
<p>
Assertively parallel task synergistic deliverables after
high-quality.
</p>
<a href="#"
>Learn More <i class="fa-solid fa-arrow-right-long"></i
></a>
</div>
</div>
</div>
In styles.css
.cards {
display: flex;
}
.cards .card {
margin-right: 31px;
}
.cards .card:last-child {
margin-right: 0px;
}
.card {
height: 512px;
width: 453px;
padding: 30px;
border-radius: 20px;
transition: 0.3s all ease-in;
}
.card:hover {
box-shadow: 0px 4px 4px #2b2a2a;
}
.card img {
width: 393px;
height: 280px;
border-radius: 20px 20px 0 0;
}
.card h1 {
font-weight: 700;
font-size: 24px;
line-height: 34px;
}
.card p {
font-size: 1.125rem;
overflow: auto;
color: #6f6f76;
max-width: 393px;
}
.card a {
text-decoration: none;
color: #ffa502;
}
Output looks like this :
Now I have encountered a new problem. When I am building out the entire container whose specification is as follows :
The h1 and cards are enclosed in a container of 1421 x 698 px and there is a h1 which is centered in the container with a dimension of 443 x116 px. Now if I want to apply a height and width to a inline element I should set it as display:inline-block and apply height and width properties. But when I do so this happens :
Why is the width and height of a h1 element affecting the elements of card ?
HTML Code:
<section class="cards-container">
<h1>We have most popular departments</h1>
<div class="cards">...</div>
</section>
Styles.css :
/* Cards Container */
.cards-container {
width: 1421px;
height: 698px;
/* display: flex;
flex-direction: column; */
}
.cards-container h1 {
font-size: 40px;
display: block;
width: 443px;
height: 116px;
align-self: center;
text-align: center;
}

Can't get CSS Flex to act responsive. Divs going off screen

I am trying to create a simple layout that uses css flex to display 4 boxes across the screen on 2 rows.
What I want to happen is I want to be able to add more divs to my HTML, and whenever the divs reach the end of the right hand side of the screen, no more divs are added, and a new row should being. However, whenever I add more than a certain number of divs, the divs start to move off screen. I want the divs to only stay within 100% of the screen size and move onto a NEW ROW once it hits the end of the page view.
The following photo shows what I am current getting and what I should be getting.
Here is some of my code....
HTML
body {
margin: 0;
padding: 0;
box-sizing: border-box;
background-color: #212121;
overflow-x: hidden;
}
header {
display: flex;
width: 100%;
margin: auto;
height: 100px;
align-items: center;
box-shadow: 0px 3px 10px gold;
background: #212121;
position: sticky;
top: 0px;
}
.logoContainer,
.navLinks {
display: flex;
}
.logoContainer {
flex: 1;
}
nav {
flex: 1;
}
.navLinks {
justify-content: space-around;
cursor: pointer;
margin-right: 20px;
color: white;
}
.navLink {
font-size: 18px;
padding-left: 10px;
padding-right: 10px;
}
ul {
list-style: none;
}
.containers {
display: flex;
background: green;
}
.gold1,
.gold2,
.gold3,
.gold4,
.gold5 {
background-color: white;
border-radius: 10px;
margin-top: 40px;
flex: 1;
}
.title {
text-align: center;
padding-top: 10px;
}
.price {
text-align: center;
margin-top: 40px;
font-size: 24px;
font-weight: bold;
color: black;
}
button {
width: 100px;
height: 35px;
border-radius: 10px;
background: rgb(14, 170, 14);
border: none;
cursor: pointer;
font-size: 16px;
}
.button {
text-align: center;
background-color: white;
}
<div class="containers">
<div class="gold1">
<h1 class="title">shop 1</h1>
<p class="price">$5</p>
<div class="button">
<button>Buy</button>
</div>
</div>
<div class="gold2">
<h1 class="title">shop 2</h1>
<p class="price">$5</p>
<div class="button">
<button>Buy</button>
</div>
</div>
<div class="gold3">
<h1 class="title">shop 3</h1>
<p class="price">$5</p>
<div class="button">
<button>Buy Gold</button>
</div>
</div>
<div class="gold4">
<h1 class="title">shop 4</h1>
<p class="price">$5</p>
<div class="button">
<button>Buy</button>
</div>
</div>
<div class="gold5">
<h1 class="title">shop 5</h1>
<p class="price">$5</p>
<div class="button">
<button>Buy</button>
</div>
</div>
</div>
PLEASE NOTE : For some reason, the code snipet is not showing what my screen is showing. I will try to fix this.
As you can see a few things.
The boxes go off screen.
The boxes do not stack on each other as the screen get smaller ( I want this to be responsive, having all the boxes stack on top of each other 1 by 1 on smaller screens , and only showing 4 boxes / row on larger screens )
Thanks in advance for the help.
You need to add some extra flex properties to css to work fine
You do not need to create a class for each element if it is going to share its properties, if you want to add something you can create classes and add them to the element and to these add or remove properties. What I mean is that .gold1, .gold2, .gold3 ... etc. they are not really necessary you can only use .gold since all those boxes will share their css properties.
CSS selectors
flex-direction: column; // for mobile devices
flex-wrap: wrap;
Flexbox guide
Also you need to use media queries to add or remove properties to your css id's,class,tags...
Here you can see an example of you want (Click on run code snippet and go to full page)
body {
background: #111;
box-sizing: border-box;
}
body>h1 {
text-align: center;
color: white;
}
.container {
margin: auto;
display: flex;
justify-content: center;
flex-direction: column;
background: green;
width: 90%;
}
.gold {
background: white;
border-radius: 10px;
margin-top: 10px;
padding: 10px;
}
.title {
text-align: center;
padding-top: 10px;
}
.price {
text-align: center;
margin-top: 40px;
font-size: 24px;
font-weight: bold;
color: black;
}
.button {
text-align: center;
background-color: white;
}
button {
width: 100px;
height: 35px;
border-radius: 10px;
background: rgb(14, 170, 14);
border: none;
cursor: pointer;
font-size: 16px;
}
#media (min-width: 992px) {
.container {
justify-content: space-between; /* add this */
flex-direction: row; /* change direction */
flex-wrap: wrap; /* wrap content */
}
.gold {
width: 22%; /* assign a lower width */
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Flex</h1>
<div class="container">
<div class="gold">
<h1 class="title">Shop 1</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 2</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 3</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 4</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 5</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 6</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 7</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 8</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 9</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 10</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 11</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
<div class="gold">
<h1 class="title">Shop 12</h1>
<p class="price">$5</p>
<div class="button">
<button>Button</button>
</div>
</div>
</div>
</body>
</html>
I found the answer. All I needed to do was add flex-wrap: wrap and it gave me the desired output.
use flex-direction row and then write flex-wrap:wrap in container class

How to align items based on 2 other items?

I'm trying to align 3 items in Flexbox.
To make things easier, here's the current layout
The goal here is to keep the numbers ( 1, 2, 3 etc.. ) on the left, strictly aligned, the texts strictly aligned too ( so that the up arrows are vertically aligned ), and the right icon should go wherever it must go as long as it's in the div.
Here's the code :
.div-container .form-div-container .small-text,
.div-container .form-div-container .longer-text,
.div-container .form-div-container .even-longer-text,
.div-container .form-div-container .longer-longer-longer-text,
.div-container .form-div-container .small-text-two {
display: flex;
justify-content: space-between;
}
The HTML :
<div class="div-container">
<div class="form-div-container">
<div class="small-text">
<p></p>
<div></div>
<img src="" alt="" srcset="">
</div>
<div class="longer-text">
<p></p>
<div></div>
<img src="" alt="" srcset="">
</div>
<div class="even-longer-text">
<p></p>
<div></div>
<img src="" alt="" srcset="">
</div>
<div class="longer-longer-longer-text">
<p></p>
<div></div>
<img src="" alt="" srcset="">
</div>
<div class="small-text-two">
<p></p>
<div></div>
<img src="" alt="" srcset="">
</div>
</div>
</div>
The thing is the icons are not all of the same width, so they push the middle item. How can I make things the way I want ? Thanks !
You could set the widths of the elements that contain the numbers and icons to a fixed percentage value like below:
.box__icon,
.box__number {
width: 15%;
text-align: center;
}
See a full demo below:
/*IGNORE STYLE RULES FROM HERE......*/
body {
margin: 0;
}
i {
font-style: normal;
}
.box {
color: white;
font-family: sans-serif;
font-size: 2rem;
font-weight: bold;
padding: 30px;
}
.box:nth-child(1) {
background: firebrick;
}
.box:nth-child(2) {
background: darkturquoise;
}
.box:nth-child(3) {
background: chocolate;
}
.box:nth-child(4) {
background: midnightblue;
}
.box__text::after {
content: "";
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 0 20px 20px 20px;
border-color: transparent transparent #ffffff transparent;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
}
/*.... TO HERE*/
.box {
align-items: center;
display: flex;
justify-content: space-between;
}
.box__icon,
.box__number {
width: 15%; /*Change this to whatever value you want*/
text-align: center;
}
.box__text {
color: white;
font-family: sans-serif;
text-align: center;
}
<div class="container">
<div class="box">
<div class="box__number">1</div>
<p class="box__text">Small Text</p>
<i class="box__icon">Icon---</i>
</div>
<div class="box">
<div class="box__number">2</div>
<p class="box__text">Longer Text</p>
<i class="box__icon">Icon</i>
</div>
<div class="box">
<div class="box__number">3</div>
<p class="box__text">Even Longer Text</p>
<i class="box__icon">Icon--</i>
</div>
<div class="box">
<div class="box__number">4</div>
<p class="box__text">Longer Longer Longer Text</p>
<i class="box__icon">Icon---</i>
</div>
</div>

Border won't show despite appearing in inspect element

I'm recreating a small widget from a psd and trying to put a thin border-right between the 3 container divs I'm using to separate the page into thirds. The divs have height, and I've tried adding in forced height to ensure that isn't the problem, but for some reason it just won't show up. The CSS has CSS Reset at the start, which you can grab from here.
Thanks for any help!
HTML
<div class="container">
<div class="img"><img src="1.png" alt=""></div>
<div class="txt">
<div><p class="title taa">10</p><p class="title2 tab">,000 hrs</p></div>
<div class="sub a"><p id="ac">Behavioural testing</p></div>
</div>
</div>
<div class="container">
<div class="img"><img src="2.png" alt=""></div>
<div class="txt">
<div><p class="title tba">8</p><p class="title2 tbb">years</p></div>
<div class="sub b"><p id="bc">Creafting successful user <br> experience since 2005</p></div>
</div>
</div>
<div class="container">
<div class="txt">
<div><p class="title tca">87</p><p class="title2 tcb">years</p></div>
<div class="sub c"><p id="cc">Collective experience</p></div>
</div>
<div class="img"><img src="3.png" alt=""></div>
</div>
CSS
.container {
display: inline-block;
width: 600px;
height: 300px;
border-right: 10px red;
}
.img {
display: inline-block;
}
.txt {
display: inline-block;
}
.title {
font-family: Helvetica;
font-weight: bold;
font-size: 91px;
display: inline-block;
}
.title2 {
font-family: Helvetica;
font-weight: bold;
font-size: 57px;
display: inline-block;
}
.sub {
font-family: Helvetica;
font-size: 22px;
}
.a {
position: relative;
left: 8px;
}
Change it to border-right: 10px solid red;
Border requires size and type of border; color is optional.