CSS - Circle with letters in the middle - html

I'm trying to do this
As you can see, the icon is not centered. I want the circle to be "pulled up" a bit so it looks nice.
Here is my html (angular):
// Icon component
<div>
<i><ng-content></ng-content></i>
</div>
// Parent Component
<div>
<p>Connect with <app-initials-icon>OT</app-initials-icon> {{ contact }} </p>
</div>
// For Simplicity (ignoring angular, so you can ignore above if you're not familiar)
<div>
<p>Connect with
<div> // the div that the css below applies to
<i>OT</i>
</div>
</p>
</div>
Here is my css
div {
display: inline-block;
}
div i {
text-align: center;
border-radius: 50%;
background-color: blue;
color: white;
font-size: 7px;
padding: 3px;
font-style: normal;
}
Any idea how?

Add vertical-align: middle; to your div i css to vertically align the circle.
Full css:
div {
display: inline-block;
}
div i {
text-align: center;
border-radius: 50%;
background-color: blue;
color: white;
font-size: 7px;
padding: 3px;
font-style: normal;
vertical-align: middle;
}

div {
display: block;
}
div i {
text-align: center;
border-radius: 50%;
background-color: blue;
color: white;
font-size: 7px;
padding: 3px;
font-style: normal;
}
i {
position: relative
}
i.one {
top:-15px;
}
i.two {
bottom:-15px;
}
<div>
<p>Connect with
<div> // the div that the css below applies to
<i class="one">OT</i>
</div>
</p>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<div>
<p>Connect with
<div> // the div that the css below applies to
<i class="two">OT</i>
</div>
</p>
</div>
You can put position directly on the i tag and you can control it's x and y using top, left, right, and bottom

Related

How can I move the text position downwards using CSS?

I want to move the text "Hi" downwards because the PNG file makes it separate too much from the rest of the text.
body {
background-color: #1d1d1d;
}
.content {
padding-top: 200px;
padding-bottom: 200px;
padding-left: 100px
}
.content > h1 {
color: white;
font-family: 'Montserrat', sans-serif;
font-size: 30px;
}
<article id="main" class="content">
<h1>Hi, <br/>
I'm <img src="../Sources/Untitled-2.png" alt="V">ictor,
<br/> just another Video Editor.
</h1>
</article>
You can add a <p> tag to your "Hi," to be able to refer to that part of the text only. In this case, I added a class as well <p class="hiText">Hi, </p>.
Then in the CSS, I referred to the hiText class and applied the following properties:
position: absolute; This sets the position of the text to absolute.
padding-top: -40px; This moves the text downwards. You can change 40px to any desired number and/or measurement unit.
Hope this answers your question!
body {
background-color: #1d1d1d;
}
.content {
padding-top: 200px;
padding-bottom: 200px;
padding-left: 100px
}
.content > h1 {
color: white;
font-family: 'Montserrat', sans-serif;
font-size: 30px;
}
.hiText {
position: absolute;
padding-top: -40px;
}
<article id="main" class="content">
<h1><p class="hiText">Hi, </p><br/>
I'm <img src="../Sources/Untitled-2.png" alt="V">ictor,
<br/> just another Video Editor.
</h1>
</article>
I put "Hi," in a <p class="hiText"> </p> and then used
.hiText {
position: relative;
top: 38px;
}

2 lines of text. 1st line can have max 2 lines. Bottom needs to ALWAYS be on second line, wrapped behind line 1. CSS only solution please

I have this HTML
<div class="link">
<i class="icon" />
<div class="text-wrapper">
<span class="label">Some label which can span at most 2 lines</span>
<span class="subtext">(optional)</span>
</div>
</div>
One way of displaying is:
Notice how the label wraps to the second line while the subtext is trailing behind it.
The other way of display is:
Notice how the label here is not long enough to wrap, but the subtext is still on the second line.
Can anyone suggest how I can achieve the above with HTML/CSS only? Feel free to ignore the icon in the solution. I have that already. Thanks in advance.
The code I have so far...
.link {
position: relative;
font-size: 0.875rem;
padding-left: 26px;
text-align: left;
line-height: 1.25rem;
}
.icon {
padding: 0;
width: 18px;
height: 18px;
font-size: 18px;
border-radius: 50%;
transform: translateY(2px);
position: absolute;
top: 0;
left: 0;
}
.label {
margin-right: 4px;
color: #007dbb;
}
.subtext { color: #686868; }
Set the first span as display: block; (see css for label-element). That will display the first span as a block element, forcing the second span to begin on a new line.
.link {
position: relative;
font-size: 0.875rem;
padding-left: 26px;
text-align: left;
line-height: 1.25rem;
}
.icon {
padding: 0;
width: 18px;
height: 18px;
font-size: 18px;
border-radius: 50%;
transform: translateY(2px);
position: absolute;
top: 0;
left: 0;
}
.label {
display: block;
margin-right: 4px;
color: #007dbb;
}
.subtext { color: #686868; }
<div class="link">
<i class="icon">Icon</i>
<div class="text-wrapper">
<span class="label">Some label which can span at most 2 lines</span>
<span class="subtext">(optional)</span>
</div>
</div>
Instead of having two separate span for title and subtitle. You can have one parent for title and add subtitle span inside it.
.link {
display: flex;
flex-direction: row;
}
.link i {
margin-right: 10px;
}
.text-wrapper {
display: flex;
width: 175px;
}
.text-wrapper p {
margin-top: 0;
}
.text-wrapper .subtitle {
color: blue;
font-style: italic;
}
<div class="link">
<i class="icon">Icon</i>
<div class="text-wrapper">
<p class="title">Some label which can span at most 2 lines
<span class="subtitle">(optional)</span>
</p>
</div>
</div>

Elements shifting to left even with float-right

Please look into this jsfiddle code.
Elements in right columns are incrementally shifting to left, even though I've used float-right.
I wanted the right column to be aligned to right border, just as the first value under Jenkins.
Please suggest what am I missing.
Thank You
In this case you may probably want to use text-align: right in the parent div instead of a float on the elements themselves. Float is not typically used for aligning content, but for aligning the containers of that content. It's often used for layouts. Text-align makes more sense here, because you want to align text.
Please remove the float-right from a tags of "metrics-content-t2" div and use text-align right.
.metric-div-row {
width: 100%;
display: flex;
}
.metric-div-row>div {
flex: 1;
margin-top: 5px;
margin-bottom: 2px;
margin-left: 10px;
margin-right: 10px;
/* Adding Border */
border-radius: 12px;
border: 2px solid cadetblue;
padding: 20px;
width: 200px;
height: 150px;
padding-top: 10px;
padding-bottom: 30px;
background-color: white;
}
.all-project-heading {
width: 100%;
height: 25px;
font-size: 18px;
font-weight: 600;
color: darkslategray;
}
.metrics-content {
width: 100%;
height: 120px;
}
.metrics-content-t1 {
float: left;
}
.metrics-content-t2 {
float: right;
text-align:right;
}
.metrics-heading {
margin-bottom: 5px;
font-size: 13px;
font-weight: 500;
}
.metrics-value-small {
color: #119bc9;
font-size: 15px;
font-weight: 500;
text-decoration: none;
border: 0px;
margin-bottom: 5px;
}
.floatRight {
float: right;
}
<div class="metric-div-row">
<div class="metric-divs">
<div class="all-project-heading">
CI Statistics
</div>
<br/>
<div class="metrics-content">
<div class="metrics-content-t1">
<span class="metrics-heading">Deployer</span>
<br/>
<a id="ciDeployerCount" class="metrics-value-small">0</a>
<br/>
<br/>
<span class="metrics-heading">GoCD</span>
<br/>
<a id="ciGocdCount" class="metrics-value-small">0</a>
<br/>
<br/>
<span class="metrics-heading">Other</span>
<br/>
<a id="ciOtherCount" class="metrics-value-small">0</a>
</div>
<div class="metrics-content-t2">
<span class="metrics-heading">Jenkins</span>
<br/>
<a id="ciJenkinsCount" class="metrics-value-small">0</a>
<br/>
<br/>
<span class="metrics-heading">TFS</span>
<br/>
<a id="ciTfsCount" class="metrics-value-small">0</a>
<br/>
<br/>
<span class="metrics-heading">None</span>
<br/>
<a id="ciNoneCount" class="metrics-value-small">0</a>
</div>
</div>
</div>

How to float image in div with centered text and correct background

This is what my header bar currently looks like: https://i.imgur.com/Hx67zu6.png
However, I want the text to be centered horizontally and have the image all the way to the left.
When I tried adding float: left to the image's css, it completely messed it up, like this: https://i.imgur.com/UtLC3xk.png
As you can see, the title is not aligned horizontally or vertically, and the bar doesn't stretch to accommodate the image.
HTML:
<div class="EA-header-bar">
<img src="~/Images/EA Icons/YoungDriver_white.png" class="EA-header-image" />
<p class="EA-header-text">
<b>YOUNG DRIVERS</b>
</p>
</div>
CSS:
.EA-header-bar {
background-color: rgb(206,33,39);
text-align: center;
}
.EA-header-image {
margin: 1%;
margin-left: 3%;
height:150px;
float: left;
}
.EA-header-text {
text-align: center;
color: white;
font-size: 6vmin;
display: inline-block;
vertical-align: middle;
font: bolder;
font-family: kalinga;
}
When doing this kind of positioning work try to use flexbox, coding is fast and nifty. Also put tags like <img>,<p> or related inline tags inside <div> just to look pro, but those are just recomendations always look for ways to improve your css.
.EA-header-bar {
display: flex;
background-color: rgb(206,33,39);
text-align: center;
justify-content: center;
align-items: center;
}
.EA-col-img {
padding-left: 20px;
}
.EA-col-txt {
flex:1
}
.EA-header-image {
height:150px;
}
.EA-header-text {
color: white;
font-size: 6vmin;
font: bolder;
font-family: kalinga;
}
<div class="EA-header-bar">
<div class="EA-col-img">
<img src="https://image.flaticon.com/icons/svg/75/75804.svg" class="EA-header-image" />
</div>
<div class="EA-col-txt">
<p class="EA-header-text">
<b>YOUNG DRIVERS</b>
</p>
</div>
</div>
Another example using absolute positionining
I think this one is more accured to your needs
.EA-header-bar {
position: relative;
display: flex;
background-color: rgb(206,33,39);
text-align: center;
justify-content: center;
align-items: center;
}
.EA-col-img {
position: absolute;
left: 5vw;
}
.EA-col-txt {
flex:1
}
.EA-header-image {
height:20vh;
}
.EA-header-text {
color: white;
font-size: 6vmin;
font: bolder;
font-family: kalinga;
}
<div class="EA-header-bar">
<div class="EA-col-img">
<img src="https://image.flaticon.com/icons/svg/75/75804.svg" class="EA-header-image" />
</div>
<div class="EA-col-txt">
<p class="EA-header-text">
<b>YOUNG DRIVERS</b>
</p>
</div>
</div>

Align the two <p> element in the same line

This is the Demo.
I want to align the two <p> element in the same line, but you can see the second one moves down a little bit. Anybody knows the reason?
HTML
<div class="logo">
<p>Hello world</p>
<p class="web_address">Hello all</p>
</div>
CSS
.logo p {
margin:0;
padding:0;
border: solid 1px black;
margin-left: 20px;
font-size: 36px;
display: inline-block;
line-height: 80px;
}
Inline(-block) elements (the paragraphs in this case) are aligned vertically in their baseline by default. You could add vertical-align: top; to fix the alignment issue.
Updated Demo.
.logo p {
/* other styles goes here... */
display: inline-block;
vertical-align: top;
}
For further details you can refer this answer.
<span> might be a better solution:
http://jsfiddle.net/Zxefz/
<div class="logo">
<span>Hello world</span>
<span class="web_address">Hello all</span>
</div>
.logo{
height: 80px;
border:1px solid red;
}
.logo span{
margin:0;
padding:0;
border: solid 1px black;
margin-left: 20px;
font-size: 36px;
display: inline;
line-height: 80px;
}
.logo .web_address{
font-size:26px;
}
the following worked for me:
.toptext {
display: flex;
align-items: center;
}
<div class="toptext">
<p>Please ensure all original documents requested are enclosed</p>
<p id="right">Claim Reference No.: <input type="text" name="" value=""></p>
</div>