I have a problem. In my angular project I have the following code:
.portfolio-summary-container {
display: block;
position: fixed;
bottom: 0;
width: 100%;
height: 80px;
}
.portfolio-summary {
display: inline-flex;
position: relative;
width: 100%;
height: 100%;
}
.portfolio-summary .section {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 25%;
border: #c2c2c2 solid 1px;
}
.portfolio-summary .section-operator {
position: absolute;
left: calc(25% - 17px);
margin-top: 23px;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
width: 35px;
height: 35px;
border-radius: 50%;
border: #b9b9b9 solid 1px;
color: #808080;
font-size: 1.8rem;
background-color: white;
}
.portfolio-summary .section .price {
font-size: 1.3rem;
font-weight: bold;
}
.portfolio-summary .section .description {
font-size: 1rem;
color: #808080
}
<div class="portfolio-summary-container">
<div class="portfolio-summary" *ngIf="portfolio">
<div class="section">
<div class="price">$10.00</div>
<div class="description">AVAILABLE</div>
</div>
<div class="section-operator">+</div>
<div class="section">
<div class="price">$12.31</div>
<div class="description">TOTAL ALLOCATED </div>
</div>
<div class="section-operator">+</div>
<div class="section">
<div class="price">$0.73</div>
<div class="description">PROFIT</div>
</div>
<div class="section-operator">=</div>
<div class="section">
<div class="price">$23.04</div>
<div class="description">EQUITY</div>
</div>
</div>
</div>
But I am trying to put the <div class="section-operator">+</div> between every section, so it would look like this:
I read that I need to give the parent: position: relative;, so thats why I created the portfolio-summary-container. The container is sticking to the bottom and the inner div has the position: relative; property, but this isn't working for some reason??? How can I get the result from the photo?
You can position each operator separately. I added z-index for the operators to be in the foreground.
.portfolio-summary {
display: inline-flex;
position: fixed;
bottom: 0;
width: 100%;
height: 80px;
}
.portfolio-summary .section {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 25%;
border: #c2c2c2 solid 1px;
}
.portfolio-summary .section-operator {
position: absolute;
margin-top: 23px;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
width: 35px;
height: 35px;
border-radius: 50%;
border: #b9b9b9 solid 1px;
color: #808080;
font-size: 1.8rem;
background-color: white;
z-index: 2;
}
.portfolio-summary .section .price {
font-size: 1.3rem;
font-weight: bold;
}
.portfolio-summary .section .description {
font-size: 1rem;
color: #808080
}
#op1 {
left: calc(25% - 17px);
}
#op2 {
left: calc(50% - 17px);
}
#op3 {
left: calc(75% - 17px);
}
<div class="portfolio-summary" *ngIf="portfolio">
<div class="section">
<div class="price">$10.00</div>
<div class="description">AVAILABLE</div>
</div>
<div class="section-operator" id="op1">+</div>
<div class="section">
<div class="price">$12.31</div>
<div class="description">TOTAL ALLOCATED </div>
</div>
<div class="section-operator" id="op2">+</div>
<div class="section">
<div class="price">$0.73</div>
<div class="description">PROFIT</div>
</div>
<div class="section-operator" id="op3">=</div>
<div class="section">
<div class="price">$23.04</div>
<div class="description">EQUITY</div>
</div>
</div>
Related
I wan't to add a p like this.
I can add it, but when I use margin-top to put it down, it affects the elements above like this.
I don't know how to solve this.
Thank you.
HTML.
<main>
<section class="home">
<div class="presentation">
<p class="hello">HELLO THERE</p>
<p>I'm Lautaro Rojas</p>
<p>Web developer</p>
<p class="scroll">SCROLL DOWN</p>
</div>
<div class="presentation-buttons">
<button>LATEST PROJECTS</button>
<button>MORE ABOUT ME</button>
</div>
</section>
</main>
CSS:
main {
width: 100%;
height: 100%;
.home {
width: 100%;
height: 100%;
background-image: url("../img/bg.jpg");
background-size: cover;
display: flex;
align-items: center;
.presentation {
width: 70%;
height: 100%;
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
gap: 5px;
p {
width: 50%;
margin: 0;
text-align: left;
color: $WHITE;
font-family: Merriweather-Regular;
font-size: 70px;
letter-spacing: 2px;
}
p[class="hello"] {
font-size: 30px;
color: $PINK;
}
p[class="scroll"] {
margin-top:180px;
font-size: 10px;
}
}
}
}
position: absolute; is your friend...
<main>
<section class="home">
<div class="presentation">
<p class="hello">HELLO THERE</p>
<p>I'm Lautaro Rojas</p>
<p>Web developer</p>
<p class="scroll">SCROLL DOWN</p>
</div>
<div class="presentation-buttons">
<button>LATEST PROJECTS</button>
<button>MORE ABOUT ME</button>
</div>
</section>
</main>
main {
width: 100%;
height: 100%;
.home {
width: 100%;
height: 100%;
background-image: url("../img/bg.jpg");
background-size: cover;
display: flex;
align-items: center;
.presentation {
width: 70%;
height: 100%;
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
gap: 5px;
position: relative;
p {
width: 50%;
margin: 0;
text-align: left;
color: $WHITE;
font-family: Merriweather-Regular;
font-size: 70px;
letter-spacing: 2px;
}
p[class="hello"] {
font-size: 30px;
color: $PINK;
}
p[class="scroll"] {
margin-top:180px;
font-size: 10px;
position: absolute;
}
}
}
}
I have a navbar with a scrollable dropdown item(cart view) to the right side of it.
The problem is that if there are more than one item in the cart, the top part of the dropdown it is not visible anymore.
Could you please tell me where is the problem?
This is the html:
<body>
<div id="root">
<div class="App">
<nav>
<div class="links">
Something, something
</div>
<div class="asd">
bla
</div>
<div class="grand-parent">
<div class="bro">
bla
</div>
<div>
</div>
<div class="dropdown">
<div class="dropdown-content">
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
And this is the CSS:
.App {
padding: 0;
margin: 0;
color: #1D1F22;
}
nav {
display: flex;
position: fixed;
justify-content: space-between;
z-index: 9990;
top: 0;
width: 100%;
background-color: white;
font-size: 1.2rem;
margin-left: 70px;
height: 80px;
}
.links {
justify-self: flex-start;
position: relative;
}
.asd {
align-self: center;
position: relative;
}
.grand-parent {
right: 100px;
text-align: center;
position: relative;
height: 90vh;
}
.bro {
position: relative;
padding: 0;
height: 3px;
width: 6px;
margin-right: 170px;
margin-top: 30px;
}
.dropdown {
position: absolute;
display: inline-block;
height: 90vh;
}
.dropdown-content {
margin-top: 0px;
display: flex;
flex-direction: column;
position: absolute;
right: 0;
width: 325px;
z-index: 9999;
border: 1px solid black;
justify-content: center;
align-items: center;
max-height: 90vh;
overflow-y: auto;
background-color: white;
overflow-x: hidden;
}
The project is done in ReactJS, but I think that this is not so important.
Thank you!
You centered vertically your elements in .dropdown-content with justify-content: center;
To fix it, you need to change it to justify-content: flex-start; and normally it'll works.
I want to create something that looks more like this:
It must look the same for mobile devices:
one 100% block and 2 image with buttons under it.
The picture must occupy the entire width of the block.
The code below has a lot of empty space between blocks with a picture and at lower resolutions it does not work as desired.
.container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
background: #e2eaf4;
padding: 10px;
flex-direction: row;
}
.child {
display: inline-block;
font-family: "Open Sans", Arial;
font-size: 20px;
color: #FFF;
text-align: center;
background: #3794fe;
border-radius: 6px;
padding: 20px;
margin: 12px;
}
.child:first-child {
width: 100%;
}
.link {
background-color:white;}
<div class="container">
<div class="child">Child</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg"width="200" height="200" >
<div class ="link">link </div>
</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" width="200" height="200">
<div class ="link">link </div>
</div>
</div>
Here try something like this:
.container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
background: #e2eaf4;
padding: 10px;
flex-direction: row;
}
.child {
display: inline-block;
font-family: "Open Sans", Arial;
font-size: 20px;
color: #FFF;
text-align: center;
background: #3794fe;
border-radius: 6px;
padding: 20px;
}
.child:first-child {
width: 100%;
}
.child:nth-child(n+2){
width: 49%;
padding: 0px;
margin: 0px;
padding-top: 20px;
margin-top: 12px;
}
.link {
background-color:white;
padding: 20px;
margin: 12px;
}
img {
width: 100%;
height: auto;
}
<div class="container">
<div class="child">Child</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" >
<div class ="link">link </div>
</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" ">
<div class ="link">link </div>
</div>
</div>
.container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
background: #e2eaf4;
padding: 5px;
flex-direction: row;
}
.child {
display: inline-block;
font-family: "Open Sans", Arial;
font-size: 20px;
color: #FFF;
text-align: center;
background: #3794fe;
border-radius: 0px;
padding: 3px;
}
.child:first-child {
width: 100%;
}
.child:nth-child(n+2){
width: 49.9%;
padding: 0px;
margin: 0px;
padding-top: 3px;
margin-top: 3px;
}
.link {
background-color:white;
padding: 20px;
margin: 12px;
}
img {
width: 100%;
height: auto;
}
<div class="container">
<div class="child">Child</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" >
<div class ="link">link </div>
</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" ">
<div class ="link">link </div>
</div>
</div>
To make the image fill the child element, you need to set its width to 100% and height to auto.
Here is the altered snippet:
.container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
background: #e2eaf4;
padding: 10px;
flex-direction: row;
}
.child {
display: inline-block;
font-family: "Open Sans", Arial;
font-size: 20px;
color: #FFF;
text-align: center;
background: #3794fe;
border-radius: 6px;
padding: 20px;
}
.child:first-child {
width: 100%;
}
.child:nth-child(n+2){
width: 49%;
padding: 0px;
margin: 0px;
padding-top: 20px;
margin-top: 12px;
}
.link {
background-color:white;
padding: 20px;
margin: 12px;
}
.container .child img {
width: 100%;
height: auto;
}
<div class="container">
<div class="child">Child</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg"width="200" height="200" >
<div class ="link">link </div>
</div>
<div class="child"><img src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" width="200" height="200">
<div class ="link">link </div>
</div>
</div>
I want to display images inside a container that has a colored background.
I want the background of the container is rounded, and the image is placed at the center.
Also, there is space between the border of the background and the image.
This is the goal:
img
The code so far:
.circle{
border-radius: 50%;
background: #2e374f;
display: flex;
justify-content: center;
align-items: center;
height: 50px;
width: 50px;
display: table-cell;
vertical-align: middle;
}
.title{
color: #ffffff;
font-size: 10px;
text-align: center;
margin-top: 5px;
opacity: 0.5;
}
<div class="circle">
<img src="https://www.fillmurray.com/50/50" class="mx-auto d-block">
<div class="title">
TITLE
</div>
</div>
this is what I achieved so far:
img
you need to remove display: table-cell rule and additionaly you can shrink the image.
.circle{
border-radius: 50%;
background: #2e374f;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 150px;
width: 150px;
}
.title{
color: #ffffff;
font-size: 10px;
text-align: center;
margin-top: 5px;
opacity: 0.5;
}
.img {
max-width: 50%;
max-height: 50%;
}
<div class="circle">
<img src="https://picsum.photos/100/100?grayscale" class="mx-auto d-block img">
<div class="title">
TITLE
</div>
</div>
Please check.
.container-box {
width: 400px;
height: 400px;
background-color: black;
}
.container-circle {
display:inline-block;
margin: 50px;
width: 300px;
height: 300px;
border-radius: 150px;
background-color: gray;
}
.image {
background: url(https://upload.wikimedia.org/wikipedia/commons/c/ce/Font_Awesome_5_solid_arrow-circle-right.svg);
width: 100px;
height: 100px;
display: inline-block;
margin: 100px;
}
<div class="container-box">
<div class="container-circle">
<div class="image">
</div>
</div>
</div>
`
If I see correctly you want the image to be round and not the container. In this case this should help you out:
.circle img {
border-radius: 50%;
max-width: 100%;
}
.circle{
background: #2e374f;
display: flex;
justify-content: center;
align-items: center;
flex-flow: column;
height:100px;
width: 100px;
}
.title{
color: #ffffff;
font-size: 10px;
text-align: center;
margin-top: 5px;
opacity: 0.5;
}
<div class="circle">
<img src="https://www.fillmurray.com/50/50" class="mx-auto d-block">
<div class="title">
TITLE
</div>
</div>
This question already has answers here:
Understanding z-index stacking order
(1 answer)
Why can't an element with a z-index value cover its child?
(5 answers)
Closed 3 years ago.
attempting to make a simple layout and have hit a dead end. I am trying to make a page that perfectly fits the screen such that there is no scrolling what-so-ever. Basically, in the included code, I'd like to have the reddish title bar (at the top) display on top of the yellowish container. The height of the yellowish container is set to 100vh so as to span the height of the viewport. In this way, the page will be perfectly sized such that you will never need to scroll.
I think it has to do with the z-index...which I thought I understood up until this point. I've watched videos, read articles, and tried everything I could think of. My last resort is trying my luck online.
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-color: rgb(171, 171, 175);
}
header h1 {
text-align: center;
position: relative;
margin: 0;
padding-top: 0.8rem;
background-color: coral;
}
.flex-container {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.content-box {
border: solid 6px #e7c022;
border-radius: 0.8rem;
height: 45%;
background-color: rgba(128, 128, 128, 0.7);
}
.main-container {
position: relative;
z-index: 1;
height: 100vh;
width: 55vw;
max-width: 700px;
background-color: burlywood;
}
.code-container {
height: 80%;
align-items: center;
}
.key-container {
height: 20%;
align-items: center;
}
.key-code {
font-size: 20rem;
font-family: 'Yellowtail', cursive;
}
.key {
height: 30%;
width: 20%;
border: solid 4px #e7c022;
border-radius: 0.5rem;
text-align: center;
margin-bottom: 3rem;
font-size: 40px;
font-family: 'Share Tech Mono', monospace;
}
.key div {
margin-bottom: 0.2rem;
}
<div class="bg">
<header>
<h1>Titlebar</h1>
</header>
<div class="flex-container main-container">
<div class="content-box">
<div class="flex-container code-container">
<div class="key-code">
<span>65</span>
</div>
</div>
<div class="flex-container key-container">
<div class="flex-container key">
<div>a</div>
</div>
</div>
</div>
</div>
</div>
Do this if you want you navbar to always stick at the top.
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-color: rgb(171, 171, 175);
}
header {
z-index: 11;
position: fixed;
width:100%
}
header h1 {
text-align: center;
position: relative;
margin: 0;
padding-top: 0.8rem;
background-color: coral;
}
.flex-container {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.content-box {
border: solid 6px #e7c022;
border-radius: 0.8rem;
height: 45%;
background-color: rgba(128, 128, 128, 0.7);
}
.main-container {
position: relative;
z-index: 1;
height: 100vh;
width: 55vw;
max-width: 700px;
background-color: burlywood;
}
.code-container {
height: 80%;
align-items: center;
}
.key-container {
height: 20%;
align-items: center;
}
.key-code {
font-size: 20rem;
font-family: 'Yellowtail', cursive;
}
.key {
height: 30%;
width: 20%;
border: solid 4px #e7c022;
border-radius: 0.5rem;
text-align: center;
margin-bottom: 3rem;
font-size: 40px;
font-family: 'Share Tech Mono', monospace;
}
.key div {
margin-bottom: 0.2rem;
}
<div class="bg">
<header>
<h1>Titlebar</h1>
</header>
<div class="flex-container main-container">
<div class="content-box">
<div class="flex-container code-container">
<div class="key-code">
<span>65</span>
</div>
</div>
<div class="flex-container key-container">
<div class="flex-container key">
<div>a</div>
</div>
</div>
</div>
</div>
</div>
Welcome to SO!
Using position relative with z-index solved the issue on header
When you set position: relative on an element then you establish a new
containing block. All positioning inside that block is with respect to
it.
Setting z-index on an element inside that block will only alter its
layer with respect to other elements inside the same block.
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-color: rgb(171, 171, 175);
}
header {
z-index: 11;
position: relative;
}
header h1 {
text-align: center;
position: relative;
margin: 0;
padding-top: 0.8rem;
background-color: coral;
}
.flex-container {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.content-box {
border: solid 6px #e7c022;
border-radius: 0.8rem;
height: 45%;
background-color: rgba(128, 128, 128, 0.7);
}
.main-container {
position: relative;
z-index: 1;
height: 100vh;
width: 55vw;
max-width: 700px;
background-color: burlywood;
}
.code-container {
height: 80%;
align-items: center;
}
.key-container {
height: 20%;
align-items: center;
}
.key-code {
font-size: 20rem;
font-family: 'Yellowtail', cursive;
}
.key {
height: 30%;
width: 20%;
border: solid 4px #e7c022;
border-radius: 0.5rem;
text-align: center;
margin-bottom: 3rem;
font-size: 40px;
font-family: 'Share Tech Mono', monospace;
}
.key div {
margin-bottom: 0.2rem;
}
<div class="bg">
<header>
<h1>Titlebar</h1>
</header>
<div class="flex-container main-container">
<div class="content-box">
<div class="flex-container code-container">
<div class="key-code">
<span>65</span>
</div>
</div>
<div class="flex-container key-container">
<div class="flex-container key">
<div>a</div>
</div>
</div>
</div>
</div>
</div>
You need to set z-index for header. Ex:
header{
position: relative;
z-index: 9999
}
If you need your header should stick at the top of the screen. add positioning. ex:
header{
position: fixed;
top: 0;
width: 100%;
z-index: 9999
}