How to make border as big as text in it - html

So it looks like this:
this is the example code of a message:
.allMsg {
width: 100%;
}
.self {
border-radius: 1rem;
background-color: #28a745;
text-align: right;
padding-left: 5px;
padding-right: 5px;
margin-left: 5px;
margin-right: 5px;
}
.friend {
text-align: left;
}
#chatWith {
text-align: center;
font-family: sans-serif;
font-size: 40px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
<div class='allMsg'>
<p class='self chatMsg'>Hello</p>
</div>
How can i make the border as big as the text inside ... I thought the padding was going to work but unfortunately it didn't so please help me.

It's possible if you wrap your messages inside another element. So let's say all messages have a full-width element, but friends messages will aligned to the left and have a blue background, while yours will aligned to the right and have a green background. If you don't want to change your markup so much, the easiest is to wrap your messages inside a span, than you doesn't need to change anything else in your html.
.allMsg {
width: 100%;
}
.self span, .friend span {
border-radius: 1rem;
padding-left: 5px;
padding-right: 5px;
margin-left: 5px;
margin-right: 5px;
}
.self span {
background-color: #28a745;
}
.friend span {
background-color: #2845a7;
}
.self {
text-align: right;
}
.friend {
text-align: left;
}
<div class='allMsg'>
<p class='chatMsg friend'>
<span>hello</span>
</p>
<p class='chatMsg self'>
<span>hy</span>
</p>
<p class='chatMsg friend'>
<span>how are you friend?</span>
</p>
<p class='chatMsg self'>
<span>i'm fine thanks</span>
</p>
</div>

You could use flexbox on the container:
.allMsg {
width: 100%;
display: flex;
flex-flow: column nowrap;
align-items: flex-end;
}
Example:
.allMsg {
width: 100%;
display: flex;
flex-flow: column nowrap;
align-items: flex-end;
}
.self {
border-radius: 1rem;
background-color: #28a745;
text-align: right;
padding-left: 5px;
padding-right: 5px;
margin-left: 5px;
margin-right: 5px;
}
.friend {
text-align: left;
}
#chatWith {
text-align: center;
font-family: sans-serif;
font-size: 40px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
<div class='allMsg'>
<p class='self chatMsg'>Hello</p>
<p class='self chatMsg'>This is a test</p>
</div>

Related

image/content not contained inside div

I'm trying to contain an image inside the first div of this page and it's outside of it for some reason. All the assets are in a flexbox. It works completely fine when I put text inside that div but not an image.
I've circled in red which image and div I'm talking about.
The code snippet won't show you what I'm talking about since it isn't the full code.
.landing {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.introWrapper {
width: 1000px;
}
.intro1 {
font-size: 25px;
text-align: center;
font-family: 'Yapari';
align-items: center;
justify-content: center;
margin-top: 23px;
}
.intro2 {
font-size: 25px;
text-align: center;
font-family: 'Yapari';
/* font-weight: 72; */
margin-top: 50px;
}
#introCircle {
border: 2px solid black;
border-radius: 50%;
width: 230px;
height: 70px;
margin: auto;
}
.icons {
border: 2px solid black;
height: 50px;
}
.icon1 {
width: 30px;
}
<div id='landing' className={styles.landing}>
<div className={styles.introWrapper}>
<div className={styles.icons}>
<img src={icon1} className={styles.icon1}/>
</div>
<div id={styles.introCircle}>
<h1 className={styles.intro1}>HELLO I'M</h1>
</div>
<LastName />
<h1 className={styles.intro2}>A FULL STACK DEVELOPER</h1>
</div>
</div>
From what I understand you have provided a height to the div "icons" . change the height to min-height
.icons {
border: 2px solid black;
min-height: 50px;
}

Updating HTML/CSS so that content displays to the right instead of below

I have tried to simplify my problem into the below snippet - my real project is using React but this should demonstrate the issue:
.page-container {
margin-left: 3rem;
}
.heading-tab {
height: 72px;
width: 294px;
border-top: 1px solid lightgrey;
}
.heading-text {
padding-top: 22px;
padding-bottom: 22px;
padding-left: 32px;
margin-bottom: 0px;
font-size: 16px;
font-weight: bold;
}
.row-group {
display: flex;
border-bottom: 1px solid;
justify-content: space-between;
padding-top: 0.8rem;
padding-bottom: 0.4rem;
}
.row-content {
padding: 0.25rem;
padding-right: 24px;
min-width: 200px;
width: 200px;
}
<div class="page-container">
<div class="heading-tab">
<p class="heading-text">
Heading 1
</p>
<div>
<div class="row-group">
<div class="row-content">My name is CTS and my alignment is all wrong!</div>
</div>
</div>
What I want to do is display my row-group (and it's contents) horizontally level with the heading-tab - as you can see it currently sits below but I need it to set just at the end of my heading-tab div?
Flexbox on the heading tab should work.
.page-container {
margin-left: 3rem;
}
.heading-tab {
height: 72px;
display:flex;
justify-content: space-between;
align-items:flex-start;
border-top: 1px solid lightgrey;
}
.heading-text {
padding-top: 22px;
padding-bottom: 22px;
padding-left: 32px;
margin-bottom: 0px;
font-size: 16px;
font-weight: bold;
}
.row-group {
display: flex;
border-bottom: 1px solid;
justify-content: space-between;
padding-top: 0.8rem;
padding-bottom: 0.4rem;
}
.row-content {
padding: 0.25rem;
padding-right: 24px;
min-width: 200px;
width: 200px;
}
<div class="page-container">
<div class="heading-tab">
<p class="heading-text">
Heading 1
</p>
<div>
<div class="row-group">
<div class="row-content">My name is CTS and my alignment is all wrong!</div>
</div>
</div>

align font awesome icon and a pragraph

it seems like i can't get the green "v" mark icon to be at the same line as the paragraph.
the "v" is always above it.
it started when i used flex or grid to space between the paragraph and the icon
i tried justify content , align items padding top nothing changes it.
anyone know how to fix this?
<style>
.content {
background: #3494db;
color: #fff;
width: 65%;
margin: auto;
display: grid;
grid-template-columns: 1fr 1fr;
}
.column1{
color: black;
line-height: 15px;
text-align: right;
margin-top: 5px;
margin-bottom: 10px;
padding-right: 25px;
}
.column2{
color: black;
line-height: 15px;
text-align: right;
margin-top: 5px;
margin-bottom: 10px;
padding-right: 25px;
}
.column1 i {
display: flex;
justify-content: space-between;
margin-left: 10px;
}
.column2 i {
display: flex;
justify-content: space-between;
margin-left: 10px;
}
.column1 p{
border-bottom: 1px #fff solid;
}
.column2 p{
border-bottom: 1px #fff solid;
}
.content i{
color: rgb(50, 230, 50);
font-size: 18px;
}
</style>
</head>
<body>
<div class="content">
<div class="column1">
<p><i class="far fa-check-circle"></i> Free for all</p>
</div>
<div class="column2">
<p> <i class="far fa-check-circle"></i> Free for all</p>
</div>
</div>
</body>
</html>
Instead of having the column1 i and column 2 i have display: flex; change it to display; float; then on both put float: left;
this will move them both checks in line with the paragraph, but the white underline goes through the check marks. To fix this, I added 5px of padding-bottom to column1 p and column2 p. My CSS for those 4 classes looked like this:
.column1 i {
display: float;
justify-content: space-between;
margin-left: 10px;
float: left;
}
.column2 i {
display: float;
justify-content: space-between;
margin-left: 10px;
float: left;
}
.column1 p{
border-bottom: 1px #fff solid;
padding-bottom: 5px;
}
.column2 p{
border-bottom: 1px #fff solid;
padding-bottom: 5px;
}
Let me know if this is what you were looking for!

Icon and padding

bob i {font-size: 10px} shows a neat horizontal block, and the name titles are aligned. When I increase the font-size for bob i to 30px, then the two spans are not neatly horizontally aligned anymore. The icon is not that big so why does it make the bob span block blow up? Is it possible to have bob i {font-size: 40px} and keep everything neatly horizontally aligned?
.joe span
{
display: block;
padding: 20px;
text-align: left;
}
.pete
{
width: 30%;
float: left;
background-color: green;
}
.bob
{
width: 10%;
float: left;
background-color: blue;
}
.bob i {
font-size: 30px;
padding-left: 10%;
}
<div class="wrapper"><div class="joe"><span class="pete">Pete</span>
<span class="bob">Bob<i class="icon">#</i></span>
</div></div>
Just change these class property
.joe span {
display: flex;
align-items: center;
padding: 20px;
}
.bob i {
font-size: 40px;
padding-left: 10%;
line-height: 0;
}
.joe span {
display: flex;
align-items: center;
padding: 20px;
}
.pete
{
width: 30%;
float: left;
background-color: green;
}
.bob
{
width: 10%;
float: left;
background-color: blue;
}
.bob i {
font-size: 40px;
padding-left: 10%;
line-height: 0;
}
<div class="wrapper"><div class="joe"><span class="pete">Pete</span>
<span class="bob">Bob<i class="icon">#</i></span>
</div></div>

CSS Aligning Things Vertically and Horizontally

See Fiddle
I have an image and two sets of text (one is a "label" and one is a "ranking").
<div class="contentsInfo">
<img src="http://lorempixel.com/90/30" />
<span>Here is some info</span>
<span>20</span>
</div>
I would like to align each to be centered vertically, the label to show up next to the image, and for the ranking data to be right aligned in the container.
However, it is not aligning in the middle, and the info and ranking "columns" are being switched (the ranking shows up in the middle, and the label to the right side).
Here is my css:
.contentsInfo
{
font-size: 0.80em;
border-bottom: 1px grey dotted;
vertical-align: middle;
display: table;
width: 100%;
}
.contentsInfo>span
{
float: right;
margin-left: 5px;
vertical-align: middle;
display: table-cell;
}
.contentsInfo span
{
font-size: 1.1em;
}
.contentsInfo img
{
height: 30px;
vertical-align: middle;
margin-right: 2px 5px 2px 0px;
padding: 2px 0px;
}
Wrap your contents in elements and do the following:
HTML:
<div class="contentsInfo">
<div>
<img src="http://lorempixel.com/90/30" />
<span>Here is some info</span>
</div>
<div>
<span>20</span>
</div>
</div>
CSS:
body,
html {
padding: 0px;
margin: 0px;
}
.contentsInfo {
font-size: 0.80em;
border-bottom: 1px grey dotted;
vertical-align: middle;
display: table;
width: 100%;
}
.contentsInfo>div {
margin-left: 5px;
vertical-align: middle;
display: table-cell;
}
.contentsInfo > div:first-child {
width: 100%;
}
.contentsInfo > div:last-child {
white-space: nowrap;
}
.contentsInfo span {
font-size: 1.1em;
}
.contentsInfo img {
height: 30px;
vertical-align: middle;
margin-right: 2px 5px 2px 0px;
padding: 2px 0px;
}
Working Fiddle
You can do like following way using display:flex. I have added on class ranking to align it right side.
*{
margin:0;
}
.contentsInfo
{
font-size: 0.80em;
border-bottom: 1px grey dotted;
display: flex;
align-items: center;
}
.contentsInfo>span
{
margin-left: 5px;
display: flex;
flex: 1 1 auto;
margin-right: 5px;
}
.ranking{
justify-content: flex-end;
}
.contentsInfo span
{
font-size: 1.1em;
}
.contentsInfo img
{
height: 30px;
padding: 2px 0px;
}
<div class="contentsInfo">
<img src="http://lorempixel.com/90/30" />
<span>Here is some info</span>
<span class="ranking">20</span>
</div>
Fiddle