Trying to make a legend like block and struggling with alignment, need some advice-correction:
.footertext {
display: flex; /* establish flex container */
flex-direction: row; /* default value; can be omitted */
flex-wrap: nowrap; /* default value; can be omitted */
justify-content: space-between;
width: 260px;
margin-top: 30px;
background: yellow;
}
.circlemarker {
height: 15px;
width: 15px;
border-radius: 50%;
margin-right: 78px;
box-shadow: 6px 6px 10px -1px rgba(0, 0, 0, 0.10),
-6px -6px 10px -1px rgba(255, 255, 255, 0.7);
}
.circlemarker p {
padding-left: 20px;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 14px;
}
#accactive {
background: #1698D1;
}
#accdisabled {
background: #979797;
}
#accprivileged {
background: #FF9563;
}
<div class="footertext">
<div>
<div class="circlemarker" id="accactive" ><p>Active</p></div>
</div>
<div>
<div class="circlemarker" id="accdisabled"><p>Disabled</p></div>
</div>
<div>
<div class="circlemarker" id="accprivileged"><p>Privileged</p></div>
</div>
</div>
so its looks almost ok, because I add
margin-right: 78px;
but such kind of "hardcoded" value and if size will change it will not fit well, so how I can change css so its looks same but be independent from margin? Also it seems not centred vertically.
p.S.
Yellow background has been added just to show boundaries of parent
.footertext {
width: 260px;
margin-top: 30px;
background: yellow;
padding: 1rem;
}
.wrapper{
display: flex; /* establish flex container */
flex-direction: row; /* default value; can be omitted */
justify-content: space-between;
}
.circlemarker-wrapper{
display: flex;
align-items: center;
justify-content: space-evenly;
}
.circlemarker {
height: 15px;
width: 15px;
border-radius: 50%;
margin-right: 0.5rem;
box-shadow: 6px 6px 10px -1px rgba(0, 0, 0, 0.10),
-6px -6px 10px -1px rgba(255, 255, 255, 0.7);
}
.circlemarker p {
padding-left: 20px;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 14px;
}
#accactive {
background: #1698D1;
}
#accdisabled {
background: #979797;
}
#accprivileged {
background: #FF9563;
}
<div class="footertext">
<div class="wrapper">
<div class="circlemarker-wrapper">
<div class="circlemarker" id="accactive" ></div>
Active
</div>
<div class="circlemarker-wrapper">
<div class="circlemarker" id="accdisabled"></div>
Disabled
</div>
<div class="circlemarker-wrapper">
<div class="circlemarker" id="accprivileged"></div>
Privileged
</div>
</div>
</div>
Try this.
The problem is "p" is outer the box model of "div class="circlemarker".
Hope this my idea have solved your problem by delete tag "p" and the circle move to div:before
.footertext {
display: flex; /* establish flex container */
flex-direction: row; /* default value; can be omitted */
flex-wrap: nowrap; /* default value; can be omitted */
justify-content: space-between;
width: 260px;
margin-top: 30px;
background: yellow;
padding: 1rem;
}
.circlemarker:before {
content: "";
position: absolute;
left: 0;
height: 15px;
width: 15px;
border-radius: 50%;
box-shadow: 6px 6px 10px -1px rgba(0, 0, 0, 0.10),
-6px -6px 10px -1px rgba(255, 255, 255, 0.7);
}
.circlemarker {
position:relative;
padding-left: 20px;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 14px;
}
#accactive:before {
background: #1698D1;
}
#accdisabled:before {
background: #979797;
}
#accprivileged:before {
background: #FF9563;
}
<div class="footertext">
<div>
<div class="circlemarker" id="accactive" >Active</div>
</div>
<div>
<div class="circlemarker" id="accdisabled">Disabled</div>
</div>
<div>
<div class="circlemarker" id="accprivileged">Privileged</div>
</div>
</div>
Move the text outside the circlemarker to get the width of the flex items correct.
Make the footertext flex items be flexboxes themselves to get vertical centering.
.footertext {
display: flex; /* establish flex container */
flex-direction: row; /* default value; can be omitted */
flex-wrap: nowrap; /* default value; can be omitted */
justify-content: space-between;
width: 260px;
margin-top: 30px;
background: yellow;
}
.footertext > div {
display: flex;
align-items: center;
}
.circlemarker {
height: 15px;
width: 15px;
display: inline-block;
border-radius: 50%;
box-shadow: 6px 6px 10px -1px rgba(0, 0, 0, 0.10),
-6px -6px 10px -1px rgba(255, 255, 255, 0.7);
}
span {
font-size: 12px;
line-height: 14px;
}
#accactive {
background: #1698D1;
}
#accdisabled {
background: #979797;
}
#accprivileged {
background: #FF9563;
}
<div class="footertext">
<div>
<div class="circlemarker" id="accactive"></div><span>Active</span>
</div>
<div>
<div class="circlemarker" id="accdisabled"></div><span>Disabled</span>
</div>
<div>
<div class="circlemarker" id="accprivileged"></div><span>Privileged</span>
</div>
</div>
Related
I want the <div class="tags> elements contents to cause overflow so that one can scroll its contents.
Right now the element simply extends in height when i add more tags/child elements. How can i prevent this?
I've tried many combinations of overflow-y: scroll and min-height: 0 but I don't think I really understand what is happening here. Why does it behave the way it does?
.card {
width: 300px;
height: 200px;
padding: 0.5rem;
margin: 1rem;
background: lightskyblue;
font-size: 0.9rem;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 4px 6px rgba(0, 0, 0, 0.23);
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 0.5rem;
}
.customerAvatar {
background: green;
width: 50px;
height: 50px;
}
.ownerAvatar {
background: red;
width: 50px;
height: 50px;
border-radius: 50%;
align-self: flex-start;
}
.details {
display: grid;
flex-grow: 1;
grid-gap: 5px;
grid-template: 4fr 1fr / 1fr 1fr;
min-height: 0;
min-width: 0;
}
.caseContainer {
display: inline-block;
min-height: 0;
min-width: 0;
}
.tags {
display: flex;
flex-wrap: wrap;
overflow-y: scroll;
}
.tag {
background: lightcoral;
box-sizing: border-box;
margin: 2px;
border-radius: 2rem;
padding: 0.25rem 0.75rem;
max-width: 100%;
word-wrap: break-word;
}
input,
textarea {
width: 100%;
box-sizing: border-box;
background: transparent;
border: none;
font: inherit;
transition: all 0.2s;
}
textarea {
resize: none;
}
textarea::-webkit-scrollbar {
width: 3px;
}
textarea::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}
textarea::-webkit-scrollbar-thumb {
background-color: rgb(47, 147, 241);
border-radius: 3px;
}
input::placeholder,
textarea::placeholder {
color: rgba(0, 0, 0, 0.3);
}
input:focus,
textarea:focus {
outline: none;
box-shadow: -2px 0px 0px 0px rgba(47, 147, 241, 0.5);
}
<div class="card">
<div class="header">
<div class="customerAvatar"></div>
<div class="ownerAvatar"></div>
</div>
<div class="details">
<div class="caseContainer">
<input name="case" id="case" placeholder="Case tags" />
<div class="tags">
<div class="tag">AAAAAAAAAAAAA</div>
<div class="tag">BBBBBb</div>
<div class="tag">CCC</div>
<div class="tag">D</div>
<div class="tag">FFFFFFFFFFFFFFFFF</div>
</div>
</div>
<textarea name="profilert" id="profilert" placeholder="Profilert"></textarea>
<input name="dato_frist" id="dato_frist" placeholder="Dato - Frist"></input>
<input name="kontakt" id="kontakt" placeholder="Kontakt"></input>
</div>
</div>
Is this what you mean by?
I used display: flex and flex:auto to stretch the container as needed.
.card {
width: 300px;
height: 200px;
padding: 0.5rem;
margin: 1rem;
background: lightskyblue;
font-size: 0.9rem;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 4px 6px rgba(0, 0, 0, 0.23);
display: flex;
flex-direction: column;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 0.5rem;
}
.customerAvatar {
background: green;
width: 50px;
height: 50px;
}
.ownerAvatar {
background: red;
width: 50px;
height: 50px;
border-radius: 50%;
align-self: flex-start;
}
.details {
display: grid;
flex-grow: 1;
grid-gap: 5px;
grid-template: 4fr 1fr / 1fr 1fr;
min-height: 0;
min-width: 0;
}
.caseContainer {
display: inline-block;
min-height: 0;
min-width: 0;
display: flex;
flex: auto;
flex-direction: column;
}
.tags {
display: flex;
flex-wrap: wrap;
flex: auto;
overflow: auto;
}
.tag {
background: lightcoral;
box-sizing: border-box;
margin: 2px;
border-radius: 2rem;
padding: 0.25rem 0.75rem;
max-width: 100%;
word-wrap: break-word;
}
input,
textarea {
min-width: 100%;
align-self: flex-start;
box-sizing: border-box;
background: transparent;
border: none;
font: inherit;
transition: all 0.2s;
}
textarea {
resize: none;
}
textarea::-webkit-scrollbar {
width: 3px;
}
textarea::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}
textarea::-webkit-scrollbar-thumb {
background-color: rgb(47, 147, 241);
border-radius: 3px;
}
input::placeholder,
textarea::placeholder {
color: rgba(0, 0, 0, 0.3);
}
input:focus,
textarea:focus {
outline: none;
box-shadow: -2px 0px 0px 0px rgba(47, 147, 241, 0.5);
}
<div class="card">
<div class="header">
<div class="customerAvatar"></div>
<div class="ownerAvatar"></div>
</div>
<div class="details">
<div class="caseContainer">
<input name="case" id="case" placeholder="Case tags" />
<div class="tags">
<div class="tag">AAAAAAAAAAAAA</div>
<div class="tag">BBBBBb</div>
<div class="tag">CCC</div>
<div class="tag">D</div>
<div class="tag">FFFFFFFFFFFFFFFFF</div>
</div>
</div>
<textarea name="profilert" id="profilert" placeholder="Profilert"></textarea>
<input name="dato_frist" id="dato_frist" placeholder="Dato - Frist"></input>
<input name="kontakt" id="kontakt" placeholder="Kontakt"></input>
</div>
</div>
I specified a specific height to its parent element (100px)
Then added height of 90% to your scrolling element.
Reason i used 90% is because the scrollbar's height might overlap the other elements.
this way , your scroll element's height is relative to your parent element.
.card {
width: 300px;
height: 200px;
padding: 0.5rem;
margin: 1rem;
font-size: 0.9rem;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 4px 6px rgba(0, 0, 0, 0.23);
border-radius:10px;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 0.5rem;
}
.customerAvatar {
background: green;
width: 50px;
height: 50px;
}
.ownerAvatar {
background: #e52d27;
width: 50px;
height: 50px;
border-radius: 50%;
align-self: flex-start;
}
.details {
display: grid;
flex-grow: 1;
grid-gap: 5px;
grid-template: 4fr 1fr / 1fr 1fr;
}
.caseContainer {
display: inline-block;
min-height: 0;
min-width: 0;
height:100px;
}
.tags {
display: flex;
flex-wrap: wrap;
overflow-y: scroll;
max-height:90%;
}
.tag {
background: lightcoral;
box-sizing: border-box;
margin: 2px;
border-radius: 2rem;
padding: 0.25rem 0.75rem;
max-width: 100%;
word-wrap: break-word;
}
input,
textarea {
width: 100%;
box-sizing: border-box;
background: transparent;
border: none;
font: inherit;
transition: all 0.2s;
}
textarea {
resize: none;
}
textarea::-webkit-scrollbar {
width: 3px;
}
textarea::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}
textarea::-webkit-scrollbar-thumb {
background-color: rgb(47, 147, 241);
border-radius: 3px;
}
input::placeholder,
textarea::placeholder {
color: rgba(0, 0, 0, 0.3);
}
input:focus,
textarea:focus {
outline: none;
box-shadow: -2px 0px 0px 0px rgba(47, 147, 241, 0.5);
}
<div class="card">
<div class="header">
<div class="customerAvatar"></div>
<div class="ownerAvatar"></div>
</div>
<div class="details">
<div class="caseContainer">
<input name="case" id="case" placeholder="Case tags" />
<div class="tags">
<div class="tag">AAAAAAAAAAAAA</div>
<div class="tag">BBBBBb</div>
<div class="tag">CCC</div>
<div class="tag">D</div>
<div class="tag">FFFFFFFFFFFFFFFFF</div>
</div>
</div>
<textarea name="profilert" id="profilert" placeholder="Profilert"></textarea>
<input name="dato_frist" id="dato_frist" placeholder="Dato - Frist"></input>
<input name="kontakt" id="kontakt" placeholder="Kontakt"></input>
</div>
</div>
Currently, my HTML looks like
However, I want to make it look similar to where the picture and ranking don't overlap.
This is my CSS and HTML for the element.
.star-list {
display: flex;
align-items: center;
padding: 5px;
width: 680px;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0px 10px 20px -6px #1abc9c;
background-color: #fff;
border-radius: 10px;
height: 155px;
margin-top: 20px;
margin-left: 10px;
margin-bottom: 10px;
font-size: 5vw;
}
.star-list>img {
height: 140px;
border-radius: 10px;
}
.star-list>.media-content {
width: 1000px;
display: flex;
justify-content: center;
font-weight: 600;
font: black;
font-size: 5vw;
}
<div class="card_body">
<div>
<div class="card word_shadow2">
<div class="card-header">
RANKING
</div>
<div class="card-body" id="star-box">
<div class="star-list">
1
<img src="https://api.buzzanglemusic.com/images/artists/771" alt="Placeholder image" />
<span class="media-content">
Eagles
</span>
</div>
</div>
</div>
</div>
</div>
I would like the ranking to not overlap with the picture. Thanks.
.star-list {
display: flex;
align-items: center;
padding: 5px;
width: 680px;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0px 10px 20px -6px #1abc9c;
background-color: #fff;
border-radius: 10px;
height: 155px;
margin-top: 20px;
margin-left: 10px;
margin-bottom: 10px;
font-size: 5vw;
}
.star-list p.rank {
padding: 0 50px;
font-weight: 700;
}
.star-list>img {
height: 140px;
border-radius: 10px;
}
.star-list>.media-content {
width: 1000px;
display: flex;
justify-content: center;
font-weight: 600;
font: black;
font-size: 5vw;
}
<div class="card_body">
<div>
<div class="card word_shadow2">
<div class="card-header">
RANKING
</div>
<div class="card-body" id="star-box">
<div class="star-list">
<p class="rank">1</p>
<img
src="https://api.buzzanglemusic.com/images/artists/771"
alt="Placeholder image"
/>
<span class="media-content">
Eagles
</span>
</div>
</div>
</div>
</div>
</div>
I just enclosed the ranking number in a p tag and then gave it an id and then set the left and right margins to 40px.
.star-list {
display: flex;
align-items: center;
padding: 5px;
width: 680px;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0px 10px 20px -6px #1abc9c;
background-color: #fff;
border-radius: 10px;
height: 155px;
margin-top: 20px;
margin-left: 10px;
margin-bottom: 10px;
font-size: 5vw;
}
.star-list > img {
height: 140px;
border-radius: 10px;
}
.star-list > .media-content {
width: 1000px;
display: flex;
justify-content: center;
font-weight: 600;
font: black;
font-size: 5vw;
}
#ranking {
margin-right: 40px;
margin-left: 40px;
}
<div class="card_body">
<div>
<div class="card word_shadow2">
<div class="card-header">
RANKING
</div>
<div class="card-body" id="star-box">
<div class="star-list">
<p id="ranking">1</p>
<img
src="https://api.buzzanglemusic.com/images/artists/771"
alt="Placeholder image"
/>
<span class="media-content">
Eagles
</span>
</div>
</div>
</div>
</div>
</div>
img { /* reasonable defaults site-wide */
display: block;
width: 100%;
height: auto;
}
picture {
display: block; /* inline by default :/ */
}
.parent {
display: flex;
flex-direction: row;
align-items: center;
border: 1px solid red;
padding: 10px;
}
.parent picture {
max-width: 150px; /* let the image parent determine it's size */
margin: 0 10px; /* just to give a little space between text */
}
<div class='parent'>
<h3 class='rank'>10</h3>
<picture>
<img src='https://placehold.it/600x300'>
</picture>
<h2 class='name'>#sheriffderek</h2>
</div>
So, anything within a parent - can be organized with flex - as long as they are direct children! Fun!!!
I have tried using flexbox to center a couple buttons and a p but I'm having some troubles.
I have this code
.container {
background: rgb(255, 126, 50, 0.15);
padding: 0 2rem;
border-radius: 0.375rem;
margin: 3.625rem 1.25rem 2rem 1.25rem;
background: black;
}
.layout {
height: calc(100vh - 4.5rem);
background: balck;
}
.loginSection {
width: 50vh;
margin: 0 auto;
border: 1px solid #ffffff;
}
.loginSection p {
display: flex;
align-items: center;
margin: 16px 0;
text-align: center;
width: 12rem;
border: 1px solid #ffffff;
}
.btn-login {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
.btn-login img {
margin-right: 1rem;
}
.btn-continue {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
But I can center the p
| | Log-In | |
|Enter your email |
| | Continue | |
.container {
background: rgb(255, 126, 50, 0.15);
padding: 0 2rem;
border-radius: 0.375rem;
margin: 3.625rem 1.25rem 2rem 1.25rem;
background: black;
}
.layout {
height: calc(100vh - 4.5rem);
background: balck;
}
.loginSection {
width: 50vh;
margin: 0 auto;
border: 1px solid #ffffff;
}
.layout p {
text-align: center;
width: 12rem;
border: 1px solid #ffffff;
color: white;
margin: auto;
}
.btn-login {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
.btn-login img {
margin-right: 1rem;
}
.btn-continue {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
Flexbox is typically used by setting flex properties on the parent container to affect the layout of the children inside of that container.
It looks like you're adding display: flex and align-items: center on the .loginSection p element, when flex properties should be set on the parent .loginSection.
If your intention is to center all the elements inside of the .loginSection horizontally, then you can get rid of the flex properties on the children, and add the following rules:
.loginSection {
display: flex;
flex-direction: column;
justify-content: center;
// ... other styles here
}
You'll want to add display:flex with flex-direction: column and align-items:center to the .loginSection container.
Typically when using flex, you flex the container and then the children become "flex-items" rather than flexing the items themselves.
.loginSection {
margin: 0 auto;
display: flex;
flex-direction: column;
align-items:center;
}
.loginSection p { text-align:center; }
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
Or if you want them to all be stretched out use align-items:stretch
.loginSection {
margin: 0 auto;
padding: 1rem; /* optional if you don't want it to stretch the whole width */
display: flex;
flex-direction: column;
align-items:stretch;
}
.loginSection p { text-align:center; }
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
I have the following div box:
<div class="requests-container">
<div class="request-box">
<div class="request-details">
<h1>Table 6, 1:00PM</h1>
<h2>
Request made 10 min ago.
</h2>
<div class="status-button">
<button type="button" class="request-button">Assistance Requested</button>
</div>
</div>
</div>
</div>
.status-button {
padding-bottom: 25px;
}
.requests-container {
display: grid;
justify-items: center;
align-items: center;
grid-row-gap: 30px;
}
.request-box {
border: 1px solid #999;
height: 200px;
width: 66%;
border-radius: 5px;
border-color: #a2e8dc;
position: relative;
background-color: white;
font-family: Helvetica;
box-shadow: 0 10px 6px -6px #ededed;
-webkit-box-shadow: 0 10px 6px -6px #ededed;
-moz-box-shadow: 0 10px 6px -6px #ededed;
}
.request-details {
margin: 0;
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
padding-left: 40px;
}
.request-button {
height: 50px;
font-size: 20px;
font-weight: 600;
border: none;
border-radius: 5px;
padding: 10px 25px;
background-size: 150% auto;
background: linear-gradient(to right, rgba(141,227,227,1) 0%, rgba(114,240,218,1) 100%);
cursor: pointer;
}
.request-details h1 {
font-size: 30px;
color: #28bfa6;
}
.request-details h2 {
font-size: 22px;
}
When the screen width is at least 1000px, I want the position of the button in the div to be like the following:
With the button centred vertically in the div and positioned to the right of the box.
I have tried to achieve this through the following CSS:
#media (min-width: 1000px) {
.status-button {
margin: 0;
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
padding-left: 700px;
}
}
The above code gives me the following:
When I use padding-left to position the button to the right, the size of the button gets compressed. Not only that, when I make the screen size smaller, the button escapes the div box:
What is the best way to position my button to the right such that the size of the button does not shrink and the button remains contained in the div box?
Instead of position: absolute, padding and transform. You can use a flex layout to solve it.
Use displat: flex, flex-wrap: wrap, align-items: center and justify-content: space-between in the button element.
So, for status-button element, you use width: 100% and in media query, you set width: auto.
.status-button {
padding-bottom: 25px;
width: 100%;
}
.requests-container {
display: grid;
justify-items: center;
align-items: center;
grid-row-gap: 30px;
}
.request-box {
border: 1px solid #999;
height: 200px;
width: 66%;
border-radius: 5px;
border-color: #a2e8dc;
position: relative;
background-color: white;
font-family: Helvetica;
box-shadow: 0 10px 6px -6px #ededed;
-webkit-box-shadow: 0 10px 6px -6px #ededed;
-moz-box-shadow: 0 10px 6px -6px #ededed;
}
.request-details {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
padding: 0 30px;
height: 100%;
}
.request-button {
height: 50px;
font-size: 20px;
font-weight: 600;
border: none;
border-radius: 5px;
padding: 10px 25px;
background-size: 150% auto;
background: linear-gradient(to right, rgba(141,227,227,1) 0%, rgba(114,240,218,1) 100%);
cursor: pointer;
}
.request-details h1 {
font-size: 30px;
color: #28bfa6;
}
.request-details h2 {
font-size: 22px;
}
#media (min-width: 1000px) {
.status-button {
width: auto;
}
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Requests Page</title>
<link rel="stylesheet" type="text/css" href="requests.css">
</head>
<body>
<div class="requests-container">
<div class="request-box">
<div class="request-details">
<div>
<h1>Table 6, 1:00PM</h1>
<h2>Request made 10 min ago.</h2>
</div>
<div class="status-button">
<button type="button" class="request-button">Assistance Requested</button>
</div>
</div>
</div>
</div>
</body>
</html>
Here is a simple example at codepen
https://codepen.io/themustafaomar/pen/poJOLqE?editors=1100
.requests-container {
border: 1px solid #999;
width: 66%;
border-radius: 5px;
border-color: #a2e8dc;
position: relative;
background-color: white;
font-family: Helvetica;
box-shadow: 0 10px 6px -6px #ededed;
-webkit-box-shadow: 0 10px 6px -6px #ededed;
-moz-box-shadow: 0 10px 6px -6px #ededed;
padding: 30px;
margin: auto;
}
.request-button {
height: 50px;
font-size: 20px;
font-weight: 600;
border: none;
border-radius: 5px;
padding: 10px 25px;
background-size: 150% auto;
background: linear-gradient(
to right,
rgba(141, 227, 227, 1) 0%,
rgba(114, 240, 218, 1) 100%
);
cursor: pointer;
}
.request-details h1 {
font-size: 30px;
color: #28bfa6;
}
.request-details h2 {
font-size: 22px;
}
#media (min-width: 1000px) {
.requests-container {
display: flex;
justify-content: space-between;
align-items: center;
}
}
HTML
<div class="requests-container">
<div class="request-details">
<h1>Table 6, 1:00PM</h1>
<h2>Request made 10 min ago.</h2>
</div>
<div class="status-button">
<button type="button" class="request-button">Assistance Requested</button>
</div>
</div>
Just replace in your css file the following to achive your goal:
.status-button {
margin-left: 25rem;
margin-top: -5rem;
}
and
.request-button {
height:0;
}
My #main element ignores it's wrapper padding. I set position:absolute on children, but when I try to change it from position:static,to position:relative it just ignores parent's height. Any workarounds?
body, html {
height: 100%;
margin: 0;
padding: 0;
}
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding: 25px;
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button, .menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
height: 100%;
width: 100%;
position: absolute;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test
<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
https://jsfiddle.net/Ldmmxw9m/3/
It doesn't ignore the parents height when using position: relative, it simply keeps the padding of the parent, but apart from that it fills the parent - see my snippet. Of course the parent's height has to be set when you use a percentage value for the child's height...
#wrapper-main{
flex:1 1 auto;
display:flex;
align-items:center;
justify-content:center;
position:relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding:25px;
background-color:yellow;
height: 200px;
}
#main{
background-color:green;
height:100%;
width:100%;
position:relative;
}
<div id="wrapper-main">
<main id="main">
some content
</main>
</div>
As Santi said, you can remove position: absolute on #main, since that will place the element relative to it's nearest positioned ancestor, ignoring the ancestor's padding.
Or if that's not an option, you could use top/left/right/bottom values that match the padding amount, and remove the padding on the parent if that's no longer needed.
/* TAGS */
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
/* END OF TAGS */
/* WRAPPERS */
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
/* END OF WRAPPERS */
/* CONTENT */
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button,
.menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
top: 25px;
left: 25px;
right: 25px;
bottom: 25px;
position: absolute;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<body>
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test
<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
</body>
1. Remove position: absolute; from #main.
Absolutely positioned items are "out of the flow". Setting the parent to relative will modify the absolute child element's bounding box to it's own height and width, but padding is not taken into account.
2. Change the wrapper's align-items: center; to align-items: stretch;
It seems to me that you don't want the child to be vertically-aligned in the middle, but rather to take up the entire height of the wrapper. align-items: stretch will apply this behavior.
Updated Fiddle
/* TAGS */
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
/* END OF TAGS */
/* WRAPPERS */
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: stretch;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding: 25px;
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
/* END OF WRAPPERS */
/* CONTENT */
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button,
.menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
width: 100%;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<body>
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
</body>
Try adding this to the parent element:
box-sizing:border-box;
This changes how the width and height is calculated by the browser so it includes padding and borders. With flex, using border-box on the parent has corrected spacing issues.