how to align avatar circle and text content css - html

I want to align text content and the avatar circle. Here are the classes that I have defined
.user-detail {
display: inline-block;
text-transform: uppercase;
text-align: right;
.user-detail__username {
margin: 18px 16px 0px 10px;
display: block;
float: left;
font-size: $font-size;
font-weight: 500;
}
.user-detail__role {
margin: 18px 16px 0px 10px;
display: block;
font-size: $font-size * 0.9;
font-style: normal;
line-height: 13px;
font-weight: 300;
}
.user-detail__avatar-circle {
display: inline-block;
margin: 8px 11px 0px 0px;
width: 45px;
height: 45px;
border-radius: 50%;
border: 1px solid $lightstroke;
}
.user-detail__avatar {
position: relative;
font-size: 51px;
line-height: 43px;
left:-4px;
}
}
and here is the HTML markup
<div class="user-detail right">
<div style="display:inline-block">
<span class="user-detail__username">
Adminstrator
</span>
<span class="user-detail__role">Adminstrator</span>
</div>
<div class="user-detail__avatar-circle">
<i class="material-icons user-detail__avatar">account_circle</i>
</div>
</div>
it shows like this here
I want to text and avatar circle should be bottom aligned. If I inspect element there is space on the top of text div. If I could remove this space problem will be solved. But I don't know how could I do that? Even changing the margin of text div not working? Any help?

As usual, what is a pain to achieve with traditional CSS (float, margin, inline-block, etc.) is a breeze with Flexbox.
.user-detail {
width: 300px;
height: 100px;
border: blue solid 2px;
display: flex;
align-items: center;
justify-content: center;
}
.user-detail>div {
border: green solid 2px;
}
.user-detail .details {
display: flex;
flex-direction: column;
}
<div class="user-detail right">
<div class="details">
<span class="user-detail__username">
Adminstrator
</span>
<span class="user-detail__role">Adminstrator</span>
</div>
<div class="user-detail__avatar-circle">
<i class="material-icons user-detail__avatar">account_circle</i>
</div>
</div>

You should use Flexbox is less pain.
Try making your
.user-detail {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
More about flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

The vertical-align: top setting normally align and positions your div element to top , in your case the "Administrator" text.
You need to change your html as (check the second <div> tag in the below code for the change),
<div class="user-detail right">
<div style="display:inline-block;vertical-align: top">
<span class="user-detail__username">
Adminstrator
</span>
<span class="user-detail__role">Adminstrator</span>
</div>
<div class="user-detail__avatar-circle">
<i class="material-icons user-detail__avatar">account_circle</i>
</div>
</div>
Hope this helps!

Related

my texts keep breaking down into new paragraphs in css and html

HTML CODE
<div class="wrapper">
<div class="flex-container">
<div class="box one">
<img src="img\xii.jpg" alt="phone1" />
<section class="section1">
<p>Xiaomi X15</p>
<br />
<h2>New Powerhouse Phone From The Xiaomi Brand</h2>
<br />
<button> BUY NOW</button>
</section>
</div>
</div>
</div>
CSS CODE
.flex-container {
display: flex;
background-color: #fff;
border: 2px solid black;
flex-wrap: wrap;
}
.wrapper {
width: 100px;
max-width: 960px;
margin: 0 auto;
}
.one p {
position: absolute;
bottom: -350px;
color: white;
font-size: 50px;
left: 500px;
text-align: center;
font-weight: lighter;
font-family: calibri;
}
.section1 h2 {
position: absolute;
bottom: -500px;
left: 300px;
color: white;
}
please help im a beginner in css and this is my first stackoverflow post
my texts are not horizantally in place and keeps breaking down that each word forms a new paragraph how can i solve this please? i have tried the display:inline- block but it didnt work.as you can see from my code i made the div tag that the image is on to be position relative so i can move the h2 and span and button elements to be nn the image. i intend on using flexbox because on i want to position more images to be on the side of the initial image
What you can do is:
Define some width and height (max-width and min-width to be more flexible) for your box;
Use background-image CSS prop instead of HTML <img />, which will ensure the image fills the background of your container;
Use flex-box with its all properties to lay out your elements. There will be no need for position: absolute for the text and header.
Other notes to your code: there are some closing tags missing in your HTML as well as closing } braces in the CSS. That is never a good practice to leave your code without them, even though in some cases the browser can fill them out for you.
Here is an example of how you can achieve what you were asking about:
.wrapper {
width: 100%;
max-width: 960px;
margin: 0 auto ;
display: flex;
justify-content: space-between;
}
.flex-container{
display: flex;
background-color:#fff;
border: 2px solid black;
flex-wrap: wrap;
width: auto;
height: 200px;
min-width: 100px;
max-width: 400px;
}
.one {
background-image: url('https://cdn.thewirecutter.com/wp-content/uploads/2018/05/smartphone-tp-top-2x1-lowres1024-7951.jpg');
background-size: cover;
}
.section1 {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.section1 p{
color: white;
font-size: 25px;
text-align: left;
font-weight: lighter;
font-family: calibri;
padding: 10px;
margin: 0
}
.section1 h2{
color: white;
padding: 10px;
margin: 0
}
button {
max-width: 100px
}
<div class="wrapper">
<div class="flex-container">
<div class="box one">
<section class="section1">
<p>Xiaomi X15 </p>
<h2>New Powerhouse Phone From The Xiaomi Brand</h2>
<button> BUY NOW</button>
</section>
</div>
</div>
<div class="flex-container">
<div class="box one">
<section class="section1">
<p>Xiaomi X15 </p>
<h2>New Powerhouse Phone From The Xiaomi Brand</h2>
<button> BUY NOW</button>
</section>
</div>
</div>
</div>

Text Flows Out of <p> Element With Overflow Hidden And Won't Center

I am trying to make menu items out of the following items, but I'm struggling with making the text inside the paragraph element responsive to its parent. I tried all positioning combinations, as well as every possible combination with percentages and sizing, but nothing worked the way it's supposed to.
I just want to have the text centered inside the circles...
.div-1 {
display: inline-block;
margin: 0 15px;
border: solid 1px blue;
padding: 20px;
height: 80px;
width: 80px;
border-radius: 50%;
}
<span class="navbar-text">
<div class="div-1">
<p>Home</p>
</div>
<div class="div-1">
<p>Services</p>
</div>
<div class="div-1">
<p>Programs</p>
</div>
</span>
You can see I used flexbox to achieve what you wanted.
.navbar-text {
display: flex;
justify-content: space-around;
}
.div-1 {
display: flex;
align-items: center;
justify-content: center;
border: solid 1px blue;
padding: 20px;
height: 80px;
width: 80px;
border-radius: 50%;
}
<span class="navbar-text">
<div class="div-1">
<p>Home</p>
</div>
<div class="div-1">
<p>Services</p>
</div>
<div class="div-1">
<p>Programs</p>
</div>
</span>
Here you go using flex box for aligment.
.div-1 {
display: flex;
margin: 0 15px;
border: solid 1px blue;
padding: 20px;
height: 80px;
width: 80px;
border-radius: 50%;
align-items:center;
justify-content: center;
}
.div-1 p {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<span class="navbar-text" style="display:flex">
<div class="div-1">
<p>Home</p>
</div>
<div class="div-1">
<p>Services</p>
</div>
<div class="div-1">
<p>Programsasdfsdfsdfsdfds</p>
</div>
</span>
I decided to add not-flex approach
You can try to use text-align and line-height. But one issue here - it doesn't support multiline. If you want long texts - then use flex.
.div-1 {
display: inline-block;
margin: 0 15px;
border: solid 1px blue;
padding: 20px;
height: 80px;
width: 80px;
border-radius: 50%;
text-align: center;
line-height: 80px;
}
.div-1 > p {
margin: 0;
}
<span class="navbar-text">
<div class="div-1">
<p>Home</p>
</div>
<div class="div-1">
<p>Services</p>
</div>
<div class="div-1">
<p>Programs</p>
</div>
</span>
.div-1 {
display: flex;
margin: 0 15px;
border: solid 1px blue;
padding: 20px;
height: 80px;
width: 80px;
border-radius: 50%;
align-items:center;
justify-content: center;
}
.div-1 p {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

Trying to left-align text in flex containers with a flex rule

I have a section that has a list of jokes where each joke is individually contained within divs. In each joke are two paragraphs that I'm trying to align to display at the left (start of the flex container). Right now the two main issues I'm facing is that the first paragraph (Q:) is not aligning to the very start of the container
I'm trying to align the paragraphs so that both the abbreviation and question wrap to leftmost boundary of the container's content.
The second issue I'm facing is that the second paragraph (A:) keeps centering itself in the container instead of displaying on the left side. I am not sure why the first paragraph does not center itself but the second paragraph does when displaying the webpage. I've been told that this can be achieved with a single flex rule which I've been trying to find in my div p ruleset.
Overall, I am trying to achieve this expected display:
HTML
<section id="jokes">
<h2>Out Of This World Joke Inventory!</h2>
<p>Hover over each joke to see the answer!</p>
<div id="joke-cards">
<div id="sun-joke">
<img src="img/icon1.png" alt="Icon of shooting star">
<hr>
<p><span class="abbrv">Q:</span> Why did the sun go to school?</p>
<p><span class="abbrv">A:</span> <span class="answer">To get brighter!</span></p>
</div>
<div id="tick-joke">
<img src="img/icon2.png" alt="Icon of rocket blasting off">
<hr>
<p><span class="abbrv">Q:</span> What do you call a tick on the moon?</p>
<p><span class="abbrv">A:</span> <span class="answer">A luna-tick</span></p>
</div>
<div id="restaurant-joke">
<img src="img/icon3.png" alt="Icon of flag on the Moon">
<hr>
<p><span class="abbrv">Q:</span> Why did the people not like the restaurant on the moon?</p>
<p><span class="abbrv">A:</span> <span class="answer">Because there was no atmosphere.</span></p>
</div>
</div>
</section>
CSS
#joke-cards {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-evenly;
}
#joke-cards div {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 15px;
margin-left: 15px;
margin-right: 15px;
margin-bottom: 15px;
height: 400px;
width: 300px;
background-color: #9B580D;
opacity: 80%;
padding: 20px;
}
#joke-cards div img {
height: 150px;
width: 150px;
}
hr {
width: 65%;
}
div p {
align-content: flex-start;
}
.abbrv {
font-size: 28px;
color: #E0DBD7;
}
.answer {
display: none;
font-size: 24px;
color: #191919;
}
#joke-cards div:hover .answer {
display: inline;
}
Use align-items: flex-start; for the divs, width + margin for img and text-align: left; for p
img{ width: 50%; outline: 1px solid blue; margin: 0 auto; }
#joke-cards {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-evenly;
}
#joke-cards div {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-top: 15px;
margin-left: 15px;
margin-right: 15px;
margin-bottom: 15px;
height: 400px;
width: 300px;
background-color: #9B580D;
opacity: 80%;
padding: 20px;
}
#joke-cards div img {
height: 150px;
width: 150px;
}
hr {
width: 65%;
}
div p {
text-align: left;
}
.abbrv {
font-size: 28px;
color: #E0DBD7;
}
.answer {
display: none;
font-size: 24px;
color: #191919;
}
#joke-cards div:hover .answer {
display: inline;
}
<section id="jokes">
<h2>Out Of This World Joke Inventory!</h2>
<p>Hover over each joke to see the answer!</p>
<div id="joke-cards">
<div id="sun-joke">
<img src="img/icon1.png" alt="Icon of shooting star">
<hr>
<p><span class="abbrv">Q:</span> Why did the sun go to school?</p>
<p><span class="abbrv">A:</span> <span class="answer">To get brighter!</span></p>
</div>
<div id="tick-joke">
<img src="img/icon2.png" alt="Icon of rocket blasting off">
<hr>
<p><span class="abbrv">Q:</span> What do you call a tick on the moon?</p>
<p><span class="abbrv">A:</span> <span class="answer">A luna-tick</span></p>
</div>
<div id="restaurant-joke">
<img src="img/icon3.png" alt="Icon of flag on the Moon">
<hr>
<p><span class="abbrv">Q:</span> Why did the people not like the restaurant on the moon?</p>
<p><span class="abbrv">A:</span> <span class="answer">Because there was no atmosphere.</span></p>
</div>
</div>
</section>
You have to wrap your paragraph tags into a container which will have place-items attribute and not each paragraph. Also, you need change display value from block to inherit for each content paragraph.
<div class="content">
<p><span class="abbrv">Q:</span> Why did the sun go to school?</p>
<p><span class="abbrv">A:</span> <span class="answer">To get brighter!</span></p>
</div>
div.content{
display: flex;
flex-direction: column;
width: 100%;
place-self: flex-start;
}
div.content p {
display:inherit;
}

How to align text in the middle beside a canvas element

i need my text elements to be in the middle of the div and beside my canvas element. currently, the texts are beside but aren't in the middle. how can i achieve this effect?
Btw, the canvas contains a chart plugin which i did not include in the code snippets below.
#user-count {
height: 100px;
width: 100px;
}
.card {
background-color: #f4f4f4;
border: none;
padding:10px;
display: inline-block;
}
.card-body {
font-weight: 600;
text-transform: uppercase;
display: inline-block;
}
<div class="row">
<div class="col-md-6">
<div class="card">
<canvas id="user-count"></canvas>
<div class="card-body">
<span>current blood donors</span>
<span>as of 2017</span>
</div>
</div>
</div>
Something like that with Flex :)
#user-count {
height: 100px;
width: 100px;
background-color: red;
}
.card {
background-color: #f4f4f4;
border: none;
padding: 10px;
display: inline-block;
display: flex;
justify-content: center;
align-items: center;
}
.card-body {
font-weight: 600;
text-transform: uppercase;
display: inline-block;
}
<div class="row">
<div class="col-md-6">
<div class="card">
<canvas id="user-count">
</canvas>
<div class="card-body">
<span>current blood donors</span>
<span>as of 2017</span>
</div>
</div>
</div>
You can add this css..
#user-count {
vertical-align: middle;
}
.card {
background-color: #f4f4f4;
border: none;
padding: 10px;
display: flex;
align-items: center;
}
So you can use display:flex instead of inline-block. flex is a bit similar to inline-block but not same and use align-items:center which centers all element to center vertically

How can I vertically align 3 divs in differents containers

I want to align vertically 3 'title' divs. When the title is one word it must to be in the middle, when is longer must automatically align.
One example of what I want to achieve: http://jsfiddle.net/526TD/4/
My problem is that I have my divs in differents containers and not in a same div.
My HTML
<div class="related_news_filter">
<a href="/news/1">
<div class="round-image"></div>
<div>
<div class="title">title</div>
</div>
</a>
<a href="/news/2">
<div class="round-image">title longeeer</div>
<div>
<div class="title">title 2</div>
</div>
</a>
<a href="/news/3">
<div class="round-image"></div>
<div>
<div class="title">title with more words</div>
</div>
</a> </div>
My css
a {
display: inline-block;
width: 81px;
margin: 0 27px 0 8px;
}
.title {
margin-top: 7px;
width: 96px;
text-transform: uppercase;
line-height: 16px;
}
What I see now:
The word "new" and "inbound" are in the first line and not in the middle. They are not correctly vertical aligned.
Just give vertical-align: middle; to a
a {
display: inline-block;
width: 81px;
margin: 0 27px 0 8px;
vertical-align: middle;
}
.title {
margin-top: 7px;
width: 96px;
text-transform: uppercase;
line-height: 16px;
}
<div class="related_news_filter">
<a href="/news/1">
<div class="round-image"></div>
<div>
<div class="title">title</div>
</div>
</a>
<a href="/news/2">
<div class="round-image">title longeeer</div>
<div>
<div class="title">title 2</div>
</div>
</a>
<a href="/news/3">
<div class="round-image"></div>
<div>
<div class="title">title with more words</div>
</div>
</a> </div>
Flexbox can do that....
Support is IE10 and up.
.related_news_filter {
display: flex;
margin: 1em auto;
width: 80%;
justify-content: center;
}
a {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
flex: 0 0 96px;
margin: 0 27px 0 8px;
text-decoration: none;
}
.round-image {
display: flex;
justify-content: center;
align-items: center;
width: 81px;
flex: 0 0 81px;
margin-bottom: 1em;
background: #000;
border-radius: 50%;
color: white;
}
.title {
flex: 1;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
text-transform: uppercase;
}
<div class="related_news_filter">
<a href="/news/1">
<div class="round-image">title</div>
<div class="title">title</div>
</a>
<a href="/news/2">
<div class="round-image">title longeeer</div>
<div class="title">title 2</div>
</a>
<a href="/news/3">
<div class="round-image">title</div>
<div class="title">title with more words</div>
</a>
</div>
Note: This is not actually aligning the "titles" to one another. It merely lays out all the contents of the link 'containers' in the same way after making them all the same height.
There are many ways of doing this. The best method accroding to me would be to use the display:table method. Check the below fiddle -
http://jsfiddle.net/526TD/29/
.related_news_filter {
display: table;
}
a {
display: table-cell;
position: relative;
width: 81px;
margin: 0 27px 0 8px;
vertical-align: middle;
}
.title {
margin-top: 7px;
width: 96px;
text-transform: uppercase;
line-height: 16px;
text-align: center;
}
for more methods of achieving this go to the link -http://www.jakpsatweb.cz/css/css-vertical-center-solution.html