bar progress stop working with "display: inline-block;" property - html

I'm writing something for the new job and I'm having a problem with the progress bar.
I created the bar along with the number represented, ie if the number is 50 then half of the bar will be filled (as usual).
But when I put the bar and the number on the same line (with display: inline-block), the filling of the bar disappears. Without this property, the bar looks right but the number is not aligned to the same height
html:
<div style="width:100%;">
<div class="progress">
<div class="progress-bar" style="width:{{value}}%"></div>
</div>
<span class="value">{{value | number:0}}</span>
</div>
css:
.progress {
height: 0.3rem;
width: 90%;
display: inline-block;
}
.value {
float: right;
display: inline-block;
vertical-align:top;
}
i dont understand the issue.. need your help.
TNX!!!

Why don't you just use the wonders of FlexBox?
If you are unfamiliar with this, here is a link: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Basically you can do the following:
https://jsfiddle.net/nL3pr8vw/2/
* {
padding: 0;
margin: 0;
}
.load {
display: flex;
justify-content: left;
align-items: center;
background: grey;
padding: 5px;
margin: 10px;
width: 300px;
border-radius: 5px;
}
.bar {
width: 45%;
background: red;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
height:25px;
}
p {
color: white;
font-family: Arial;
font-size: 0.5em;
}
<div class="load">
<div class="bar">
<span class="count"><p>45%</p></span>
</div>
</div>
Now with this code, you can just re-arrange the divs and mess around with the FlexBox in the CSS to get your desired result!

Related

Adjust <p> width to its text content

This seems like an easy question but I've been trying to fix it for a couple of hours now and I still cannot find a solution. I have a box with two columns like in here:
p {
margin: 0;
padding: 0;
margin-right: 2px;
}
.container {
padding: 5px;
width: 90%;
height: 200px;
margin: auto;
border: 1px black solid;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
.half {
width: 50%;
}
.left-col {
display: flex;
}
.right-col {
text-align: right;
}
.tooltip {
position: relative;
border: 1px black solid;
border-radius: 100%;
width: 14px;
height: 14px;
font-size: 12px;
display: flex;
justify-content: center;
align-items: center;
}
<div class="container">
<div class="row">
<div class="half">
<div class="left-col">
<p>Username picked on regitration:</p>
<div class="tooltip">?</div>
</div>
</div>
<div class="half">
<p class="right-col">
John WithLongSurname
</p>
</div>
</div>
</div>
The problem is, that when I open the page on mobiles, the text on the left column is too long and it wraps (which is good), but its width still takes a whole column, so the tooltip is not next to the text but in the center of the box (it sticks to the right side of the column). Example:
I tried to add width: min-content to the "label" class, but then the whole paragraph just collapses to the smallest possible width. How can I adjust the width of the paragraph, so it will take only as much width as it needs to, so the tooltip will always be next to it?
It is because you are using display: flex; for the .left-col class. By default it will distribute the width automatically and evenly.
Try the styling below to see if it works:
p {
margin: 0;
padding: 0;
margin-right: 2px;
}
.container {
padding: 5px;
width: 90%;
height: 200px;
margin: auto;
border: 1px black solid;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
.half {
width: 50%;
}
.left-col {
display: inline;
}
.right-col {
text-align: right;
}
.tooltip {
position: relative;
border: 1px black solid;
border-radius: 100%;
width: 14px;
height: 14px;
font-size: 12px;
display: inline;
}
p.label {
width: auto;
}
<div class="container">
<div class="row">
<div class="half">
<div class="left-col">
<p class="label">Username picked on regitration:
<span class="tooltip">?</span>
</p>
</div>
</div>
<div class="half">
<p class="right-col">
John WithLongSurname
</p>
</div>
</div>
</div>

Centering a div to the viewport with other divs on both sides

I'm currently designing a header bar for a site I'm working on. I would like the header to show a logo at the left, the title in the center, and the user account on the right.
This mockup is what I'm envisioning. Note that the dotted boxes denote a div.
I've made some progress on creating it in HTML/CSS, but I can't seem to get the title to center to the viewport.
As you can see, the title is centering itself between the logo and the account info divs, instead of centering itself on the viewport. This ends up making the page just look a little bit off, and so I would really like to center the title to the viewport.
Here's my code:
.headerBarArea {
background-color: #7785A2;
border: 0;
padding: 0;
width: 100%;
display: inline-block;
text-align: center;
}
.logoArea {
display: inline;
text-align: center;
float: left;
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.minesLogo {
width: 96px;
}
.titleArea {
display: inline-block;
text-align: center;
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.siteTitle {
color: white;
}
.pageTitle {
color: white;
}
.userAccountArea {
display: inline;
text-align: center;
float: right;
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.userAccountIcon {
float: left;
width: 35px;
}
.userAccountText {
float: right;
}
<div className="headerBarArea">
<div className="logoArea">
<img src="assets/mines_logo_stacked.png" className="minesLogo" />
</div>
<div className="titleArea">
<h2 className="siteTitle">This is my site Title</h2>
<h3 className="pageTitle">Page Title</h3>
</div>
<div className="userAccountArea">
<img src="assets/user_account.png" className="userAccountIcon" />
<span className="UserAccountText">John Smith (Student)</span>
</div>
</div>
Any ideas on what I could do to make the title div centered to the viewport, instead of centering between the two divs?
html code
<div class="flex-container">
<div class="flex-item">1</div>
<div class="align-self-center">
<span class="siteTitle">This is my site Title</span>
<br>
<div class="text-center ">Page Title</div>
</div>
<div class="flex-item align-self-end third-item">3</div>
</div>
CSS code
.flex-container {
/* We first create a flex layout context */
display: flex;
/* Then we define the flow direction
and if we allow the items to wrap
* Remember this is the same as:
* flex-direction: row;
* flex-wrap: wrap;
*/
flex-flow: row wrap;
/* Then we define how is distributed the remaining space */
justify-content: space-between;
}
.flex-item {
background: tomato;
padding: 5px;
width: 200px;
height: 150px;
margin-top: 10px;
line-height: 150px;
color: white;
font-weight: bold;
text-align: center;
}
.third-item {
height: 100px;
}
.text-center{
text-align: center;
}
.align-self-end{
align-self:end;
}
.align-self-center{
align-self:center;
}
code output
code solution
used flex to place the items used .flex-container as parent div where flex items are placed in .justify-content: space-between; is used to place space in between the items. align-self:center; is used to place Page Title at center
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
codepen
.headerBarArea{
display:flex;
justify-content: space-between;
align-items: center
}
It is an easy way to the layout.
you can try it.
Try adding margin-left:auto; and margin-right:auto; to the .titleArea class .
I would suggest using a flex-box though.
Replace your css code with this to make title div centered in all the viewport.
.headerBarArea {
background-color: #7785A2;
border: 0;
padding: 0;
width: 100%;
display:flex;
justify-content: space-between;
}
.logoArea , .titleArea , .userAccountArea {
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.minesLogo {
width: 96px;
}
.titleArea {
text-align: center;
}
.siteTitle , .pageTitle{
color: white;
}
.userAccountIcon {
float: left;
width: 35px;
}
.userAccountText {
float: right;
}

How can I draw a line from my left and right box down to the middle of a text in CSS?

I need your help. I've this three boxes including a text below:
#boxes {
display: flex;
margin-right: -20px;
}
.box {
width: 33.33333%;
margin-right: 20px;
height: 300px;
border-radius: 3px;
border: 1px solid;
}
#footer {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 25px;
}
#headline {
font-size: 16px;
font-weight: 700;
padding-bottom: 12px;
}
<div id="boxes">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div id="footer">
<span id="headline">Headline</span>
<span>Small text</span>
</div>
Now I need to somehow connect the boxes together with the text below. For that I want to draw a line down and to the middle text (vertical center) from the left and right box. The problem is that the lines should start at the middle of the left and right boxes and be also centered when the width of the boxes changes - for example when I resize the browser (responsive).
I've first tried using ::before and ::after but I was only able to draw the horizontal lines with total imperfection...
Does anyone has an idea how I can do this?
Go ahead and create a DIV underneath, margin it up, and add borders! You can add a background to the text to section it out.
Big thanks to XLIME for the right hint. This is the answer for my problem:
#boxes {
display: flex;
margin-right: -20px;
}
.box {
width: 33.33333%;
margin-right: 20px;
height: 300px;
border-radius: 3px;
border: 1px solid;
}
#footer {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 25px;
position: relative;
}
#footer-inner {
display: flex;
flex-direction: column;
align-items: center;
background: #ffffff;
z-index: 1;
padding: 0 25px;
}
#headline {
font-size: 16px;
font-weight: 700;
padding-bottom: 12px;
}
#connection-border {
position: absolute;
width: 68%;
height: 98%;
border: 3px solid;
border-top: none;
top: -25px;
}
<div id="boxes">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div id="footer">
<div id="footer-inner">
<span id="headline">Headline</span>
<span>Small text</span>
</div>
<div id="connection-border"></div>
</div>
While the "just make another <div> with borders" answer will probably make your life easier, here's an example built with pseudoelements.
In short, it hangs both the vertical and the horizontal lines off of the first and last .box elements, and makes use of both the :before and :after pseudoelements to create those lines.
The last bit of the illusion (lines stopping before the footer text) is accomplished by setting a page-color background on the footer spans, and giving them enough padding to create the appearance of a gap.
In this snippet, I've made the vertical lines green and the horizontal lines blue so it's easier to trace what's happening.
/* Original styling ===================== */
#boxes {
display: flex;
margin-right: -20px;
}
.box {
width: 33.33333%;
margin-right: 20px;
height: 300px;
border-radius: 3px;
border: 1px solid;
}
#footer {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 25px;
}
#headline {
font-size: 16px;
font-weight: 700;
padding-bottom: 12px;
}
/* Additional styling ===================== */
:root {
--footer-gap-height: 48px;
}
.box {
position: relative;
}
/* vertical lines */
.box:first-child:before,
.box:last-child:before {
border-left: 1px solid #0f0; /* green */
content: '';
display: block;
height: var(--footer-gap-height);
left: 50%;
position: absolute;
top: 100%;
transform: translateX(-50%);
width: 0;
}
.box:first-child:after,
.box:last-child:after {
border-bottom: 1px solid #00f; /* blue */
content: '';
position: absolute;
top: calc(100% + var(--footer-gap-height));
width: 100%;
}
.box:first-child:after {
left: 50%;
right: auto;
}
.box:last-child:after {
left: auto;
right: 50%;
}
#footer {
position: relative;
}
#footer span {
background-color: #fff;
display: block;
padding-left: 1em;
padding-right: 1em;
}
<div id="boxes">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div id="footer">
<span id="headline">Headline</span>
<span>Small text</span>
</div>

Equal space to the left and right of text in all navigation menu items

I'm using flexbox to create a navigation menu and I want to make sure the text to the left and right of each word are exactly even.
Right now, the boxes are perfectly even responsively, but when the characters of the word don't match others, the space around the words are no longer even.
Here's my fiddle: https://jsfiddle.net/omarel/p204jjnr/2/
header {
display: flex;
position: fixed;
bottom: 0px;
width: 100%;
background-color: #000;
padding: 50px;
}
header .tab {
color: #fff;
width: 16.66%;
height: 70px;
border: 1px solid red;
text-align: center;
font-size: 2.4vw;
vertical-align: middle;
line-height: 70px;
}
/* BORDER BOXING */
header,
header .tab {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<header>
<div class="tab">home</div>
<div class="tab">hello</div>
<div class="tab">longer word</div>
<div class="tab">short</div>
<div class="tab">Neighborhood</div>
<div class="tab">Floor Plans</div>
<div class="tab">Views</div>
</header>
UPDATE:
The solution was a combination of answers below:
Both adding flex:auto and removing the width from header .tab
For flexbox you use the flex property to specify your elements length. Look into flex-basis, flex-shrink, and flex-grow. Remove the width and set your flex to auto;
header .tab{
color: #fff;
flex: auto;
height: 70px;
border: 1px solid red;
text-align: center;
font-size: 2.4vw;
vertical-align: middle;
line-height: 70px;
}
Instead of setting a width for each item:
width: 16.66%
Let the width be auto (content-based) and use padding:
width: 16.66% <-- REMOVE
padding: 0 20px
Now, the space to the left and right of the text is consistent in all tabs.
Here's a simplified version of your code:
header {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
background-color: #000;
padding: 50px;
}
header .tab {
padding: 0 20px;
height: 70px;
font-size: 2.4vw;
color: #fff;
border: 1px solid red;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
<header>
<div class="tab">home</div>
<div class="tab">hello</div>
<div class="tab">longer word</div>
<div class="tab">short</div>
<div class="tab">Neighborhood</div>
<div class="tab">Floor Plans</div>
<div class="tab">Views</div>
</header>
jsFiddle

Struggling with text overflowing from within a flexbox

I'm trying to make a simple explanation page with 3 steps along with example code blocks and a short description. If you go to the codepen here, you will see what I am talking about (I have also reproduced the code below).
There are 3 steps, and the HTML/CSS structure of each step is identical. However, some of its contents may vary. If you look at the code pen, you'll see that the first and third steps look relatively okay. But the code block extends to different widths for some reason.
This is problem number one. How do I get it such that the code blocks (i.e. <div class="code">) are equal length for all three of the steps?
The second issue is that the code block for step 2 overflows outside of several of its parent div even though I have set overflow-x: scroll and width: 100%. Ideally, I would want the code block to be the same width as the other two, while allowing the code inside to be scrollable left and right.
This is problem number two. How do you constrain a div inside a flexbox such that it does not overflow outside of its parents and at the same time can allow scrolling within its immediate parent div?
I hope my explanation is sufficient. It's very hard for me to describe this as I am not too familiar with the quirks of Flexbox just yet. Please have a look at the codepen, I am certain it will become a lot clearer.
Thanks in advance and please let me know what else I may need to clarify.
HTML:
<div class="container">
<div class="step">
<div class="number">1</div>
<div class="step-body">
<div class="description">This is a description of the terminal code block below:</div>
<div class="code"><pre>npm install foo bar</pre></div>
</div>
</div>
<div class="step">
<div class="number">2</div>
<div class="step-body">
<div class="description">This is a description of the very very very long single-line code block below:</div>
<div class="code"><pre>foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar</pre></div>
</div>
</div>
<div class="step">
<div class="number">3</div>
<div class="step-body">
<div class="description">This is a description of the JSON code block below:</div>
<div class="code"><pre>{
"custom": {
"key": "a1b2c3d4e5f6"
}
}</pre></div>
</div>
</div>
</div>
CSS:
body {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
position: absolute;
}
.container {
max-width: 50%;
}
.step {
display: flex;
border: 1px solid red;
}
.number {
font-size: 2.5rem;
text-align: right;
flex-shrink: 0;
margin-right: 1rem;
width: 3rem;
}
.step-body {
padding-top: 1rem;
padding-bottom: 1rem;
}
.code {
background-color: black;
color: white;
width: 100%;
padding: 12px;
overflow-x: scroll;
}
Edit: here is a better solution then my first answer
Remove width: 100% from .code and add width: calc(100% - 4rem); to .step-body see fiddle https://jsfiddle.net/0kqx79g9/9/
body {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
position: absolute;
}
.container {
max-width: 50%;
}
.step {
display: flex;
border: 1px solid red;
}
.number {
font-size: 2.5rem;
text-align: right;
flex-shrink: 0;
margin-right: 1rem;
width: 3rem;
}
.step-body {
width: calc(100% - 4rem);
padding-top: 1rem;
padding-bottom: 1rem;
}
.code {
background-color: black;
color: white;
padding: 12px;
overflow-x: scroll;
}
I've adjusted the code you've provided to hopefully solve the issues you're having.
body {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
position: absolute;
}
.container {
max-width: 50%;
-webkit-flex-direction: column;
flex-direction: column;
}
.step {
border: 1px solid red;
-webkit-flex-direction: column;
flex-direction: column;
padding:5%;
}
.number {
font-size: 2.5rem;
text-align: right;
flex-shrink: 0;
margin-right: 1rem;
width: 3rem;
}
.step-body {
width:inherit;
padding-top: 1rem;
padding-bottom: 1rem;
}
.code {
background-color: black;
color: white;
width: 100%;
/* padding: 12px; */
overflow-x: scroll;
}
here is the example:
https://jsfiddle.net/ax0mfc0p/
you can find some more information on flex-box from here:
https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties