Give a Specific Part of a Text Component Colour - html

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>

Related

How to align a text outside and below a box?

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-->

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 do I position the icon to the right of the heading?

I would like the layout to look as so, but also be responsive (so that the heading + paragraph both stay positioned to the left of the icon).
CSS:
.feature {
position: relative;
border: 1px solid #000;
}
.circle {
height: 2.5rem;
width: 2.5rem;
background-color: #64beeb;
border-radius: 50%;
float: right;
}
.icon {
font-size: 1.75rem;
color: #fff;
}
HTML:
<div class="feature">
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
</div>
CODEPEN DEMO
add this to .circle and remove float:right; Then it will be absolutely positioned from the parent relative container.
position: absolute;
top: 10px;
right: 10px;
.feature {
position: relative;
border: 1px solid #000;
}
.circle {
position: absolute;
top: 10px;
right: 10px;
height: 2.5rem;
width: 2.5rem;
background-color: #64beeb;
border-radius: 50%;
}
.icon {
font-size: 1.75rem;
color: #fff;
}
<div class="feature">
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
</div>
And you could add padding-right: 50px; to .feature so the icon (blueih circle) will not be over text. See here https://jsfiddle.net/ymzofeph/
One option is to use flexbox. You can add display: flex to the container (.feature). Add flex: 1 to the text. To create some space around the icon you can use a margin value you find suitable.
.feature {
position: relative;
border: 1px solid #000;
/* for demo */
text-align: right;
display: flex;
}
.text {
flex: 1;
}
.circle {
height: 2.5rem;
width: 2.5rem;
background-color: #64beeb;
border-radius: 50%;
margin: 1rem;
}
.icon {
font-size: 1.75rem;
color: #fff;
}
<div class="feature">
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
</div>
<div class="feature">
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
</div>
<style>
.circle{
float:right;
width:40px;
height:40px;
margin:0 0 0 20px;
}
.text{
overflow:hidden;
}
</style>
Put the float:right div before the .text-right div. Then add padding-right:2.5rem; to the .text-right div.
Example

Vertically Center (Using Bootstrap-CSS)

I have been writing some code for a website, and I'm not able to vertically center text. I have read multiple answers on StackOverflow and other sites about how to vertically center html (mainly using the display:table and display:table-cell methods and the top:50%, transformY method), however, I am not able to implement either of these methods successfully. I have attached my code here, hoping that someone will be able to spot an error of my mine which is causing the code to not work. (In this code, I have used the top:50%, transformY method of vertically centering text). Any help would be greatly appreciated.
HTML:
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="stylesheet.css">
<title>Game Timer and Scorekeeper</title>
</head>
<body>
<div class="container-fluid">
<div class="row" id="heading">
<div class="col-xs-12">
<div class="positioner">
<h1>Game Timer and Scorekeeper</h1>
</div>
</div>
</div>
<div class="row" id="top-labels">
<div class="col-xs-3 labels teamlabel" id="a-label">
<div class="positioner">
<h2>Team A</h2>
</div>
</div>
<div class="col-xs-6 labels" id="gameclock-label">
<div class="positioner">
<h2>Game Clock</h2>
</div>
</div>
<div class="col-xs-3 labels teamlabel" id="b-label">
<div class="positioner">
<h2>Team B</h2>
</div>
</div>
</div>
<div class="row" id="thirdrow">
<div class="col-xs-3 pointsclock teampoints" id="pointsA">
<div class="positioner">
<h1>POINTS A</h1>
</div>
</div>
<div class="col-xs-6 pointsclock" id="gameclock">
<div class="positioner">
<h1>GAME CLOCK</h1>
</div>
</div>
<div class="col-xs-3 pointsclock teampoints" id="pointsB">
<div class="positioner">
<h1>POINTS B</h1>
</div>
</div>
</div>
<div class="row" id="fourthrow">
<div class="col-xs-3 ptcontclock ptcontrol" id="ptcontrolA">
<div class="positioner">
<h2>CONTROL A</h2>
</div>
</div>
<div class="col-xs-6 ptcontclock" id="questionclock">
<div class="positioner">
<h2>QUESTION CLOCK</h2>
</div>
</div>
<div class="col-xs-3 ptcontclock ptcontrol" id="ptcontrolB">
<div class="positioner">
<h2>CONTROL B</h2>
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
.container-fluid {
width: 100vw;
height: 100vh;
}
#heading {
height: 15vh;
border: 2px solid;
}
#top-labels {
height: 10vh;
border: 2px solid;
width: 100vw;
}
#top-labels .labels {
border-right: 2px solid;
border-left: 2px solid;
}
#thirdrow {
height: 40vh;
border: 2px solid;
width: 100vw;
}
#thirdrow .pointsclock {
height: 40vh;
border-right: 2px solid;
border-left: 2px solid;
}
#fourthrow {
height: 35vh;
width: 100vw;
}
#fourthrow .ptcontclock {
border-right: 2px solid;
border-left: 2px solid;
height: 35vh;
}
.positioner{
height:100%;
width:100%;
position: relative;
top: 50%;
transform: translateY(-50%);
}
You can try this.
HTML
<main>
<div>
I'm a block-level element with an unknown height, centered vertically
within my parent.
</div>
</main>
CSS
body {
background: #f06d06;
font-size: 80%;
}
main {
background: white;
height: 300px;
width: 200px;
padding: 20px;
margin: 20px;
display: flex;
flex-direction: column;
justify-content: center;
resize: vertical;
overflow: auto;
}
main div {
background: black;
color: white;
padding: 20px;
resize: vertical;
overflow: auto;
}
<main>
<div>
I'm a block-level element with an unknown height, centered vertically within my parent.
</div>
</main>
check this link for reference https://css-tricks.com/centering-css-complete-guide/

Padding-right too large

My title box is too wide. It should only be as wide as the title-text inside it called "WEBSITE TITLE".
Is it possible to get my padding-right to be the same as my current padding-left which would be around 5px?
FIDDLE HERE... FIDDLE
HTML:
<footer class="main_footer">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="container-fluid">
<div class="text-center-footer-text">
<a href="#">
<h4>WEBSITE<span> TITLE</span></h4>
</a>
</div>
<p>Cool website.</p>
<p>text1</p>
<p>text2</p>
</div>
</div>
</div>
</div>
</footer>
CSS:
.text-center-footer-text h4 {
font-size: 20px;
padding: 5px;
color: green;
font-family: Agency FB;
font-weight: normal;
background-color: black;
border: 5px solid blue;
}
.text-center-footer-text h4 span {
color: red;
}
Set display: inline-block or display: table to h4
.text-center-footer-text h4 {
font-size: 20px;
padding: 5px;
color: green;
font-family: Agency FB;
font-weight: normal;
background-color: black;
border: 5px solid blue;
display: inline-block;
}
.text-center-footer-text h4 span {
color: red;
}
<footer class="main_footer">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="container-fluid">
<div class="text-center-footer-text">
<a href="#">
<h4>WEBSITE<span> TITLE</span></h4>
</a>
</div>
<p>Cool website.</p>
<p>text1
</p>
<p>text2
</p>
</div>
</div>
</div>
</div>
</footer>
try with
display:inline-block.
http://jsfiddle.net/sunp5usj/2/
hope this helps.
Regards!