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>
Related
I'm designing a blog post preview tile for my personal website. Whatever I try to do, there is always a gap between the image and its own bottom border, or a gap between the image and the border of the container. It appears on mobile, when zooming, and when scaling. It's a really simple design and I'm going crazy and can't figure out how to get it to work. I know it's related to sub pixel rendering issues. Please help me! I would either like the gap gone or to render as the same color as the border so it doesn't look jank.
body {
background: rgba(255, 225, 172, 1);
display: grid;
grid-template-rows: [row-start] 1fr [row-end row2-start] 6fr [row2-end row3-start] 1fr [row3-end];
grid-template-columns: [col-start] 1fr [col-end];
row-gap: 60px;
padding-left: 120px;
padding-right: 120px;
}
.blog_preview_container {
grid-row: 2;
grid-column: 1;
height: 354px !important;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.blog_preview_titlecard {
height: 352px;
width: 272px;
}
.blog_tile {
height: 340px !important;
width: 240px !important;
margin: 1px;
background-color: white;
border: 6px solid black;
box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.65);
color: white;
display: inline;
overflow: hidden;
cursor: pointer;
transform: scale(1);
}
.blog_tile:hover {
transform: scale(1.05);
}
.blog_tile_image {
display: block;
border-bottom: 6px solid black;
}
.blog_tile_text {
height: 138px;
font-family: 'nunito', sans-serif;
font-size: 1rem;
font-weight: 900;
margin: 0;
padding: 16px;
}
<body>
<div class="blog_preview_container">
<img class="blog_preview_titlecard" src="https://example.com/titlecard_location">
<div class="blog_tile">
<img class="blog_tile_image" src="https://example.com/img_location">
<p class="blog_tile_text">Text Goes Here</p>
</div>
</div>
</body>
I play with this image and it seems like you can just change the background-color of your blog_tile as black will remedy it.
body {
background: rgba(255, 225, 172, 1);
display: grid;
grid-template-rows: [row-start] 1fr [row-end row2-start] 6fr [row2-end row3-start] 1fr [row3-end];
grid-template-columns: [col-start] 1fr [col-end];
row-gap: 60px;
padding-left: 120px;
padding-right: 120px;
}
.blog_preview_container {
grid-row: 2;
grid-column: 1;
height: 354px !important;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.blog_preview_titlecard {
height: 352px;
width: 272px;
}
.blog_tile {
height: 340px !important;
width: 240px !important;
margin: 0px;
border: 6px solid black;
box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.65);
color: white;
background-color: white;
}
.blog_tile:hover {
transform: scale(1.05);
margin-top: 0px;
background-color: black;
}
.blog_tile img {
height: 340px;
width: 242px;
object-fit: cover;
margin: -1px 0px 0px -1px;
}
.blog_tile_image {
display: block;
border-bottom: 6px solid black;
}
.blog_tile_text {
height: 138px;
font-family: 'nunito', sans-serif;
font-size: 1rem;
font-weight: 900;
margin: 0;
padding: 16px;
color: white;
}
<body>
<div class="blog_preview_container">
<img class="blog_preview_titlecard" src="https://media.istockphoto.com/photos/picturesque-morning-in-plitvice-national-park-colorful-spring-scene-picture-id1093110112?k=20&m=1093110112&s=612x612&w=0&h=3OhKOpvzOSJgwThQmGhshfOnZTvMExZX2R91jNNStBY=">
<div class="blog_tile">
<img class="blog_tile_image" src="https://media.istockphoto.com/photos/picturesque-morning-in-plitvice-national-park-colorful-spring-scene-picture-id1093110112?k=20&m=1093110112&s=612x612&w=0&h=3OhKOpvzOSJgwThQmGhshfOnZTvMExZX2R91jNNStBY=">
<p class="blog_tile_text">Text Goes Here</p>
</div>
</div>
</body>
Here's a stripped down example that doesn't involve hard-coding any colors. It uses an absolutely positioned psuedo-element with a border that is overlaid above the image. The container is given a padding amount that is 1px smaller than the border width so it is rendered underneath it. The bottom border of the <img> is then relocated to the top of the <p> below it and the image is given a bottom margin of -1px.
*, *::after, *::before { box-sizing: border-box; }
body {
background: rgba(255, 225, 172, 1);
display: grid;
align-items: center;
justify-content: center;
}
.blog_tile {
position: relative;
display: grid;
grid-template-rows: max-content 1fr;
height: 340px;
width: 240px;
padding: 5px;
background-color: white;
box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.65);
color: white;
cursor: pointer;
overflow: hidden;
}
.blog_tile::after {
content: "";
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
border: 6px solid black;
}
.blog_tile:hover {
transform: scale(1.05);
}
.blog_tile img {
display: block;
margin-bottom: -1px;
object-fit: cover;
line-height: 0;
white-space: collapse;
}
.blog_tile p {
margin: 0; padding: 3px;
border-top: 6px solid black;
color: black;
}
<div class="blog_tile">
<img src="https://picsum.photos/300">
<p> TESTING </p>
</div>
Try this may be it will help.
img {
object-fit: contain;
}
I fixed this by having the tile background color match the border color, and then setting the background of the text with my script instead of background color of the tile. That way when gaps are created it matches the border color and doesn't look weird. Now it looks correct at all scales. it doesn't handle non-cropped images but all the images pulled are autocropped to the correct size in my PHP.
window.onload = () => {
var colors = ['#ffffff', '#ffbd4b', '#ff634b', '#4b9fff'];
var nowhitecolors = ['#ffbd4b', '#ff634b', '#4b9fff'];
document.querySelectorAll('.blog_tile').forEach(
el => {
var randcolor = colors[Math.floor(Math.random() * colors.length)];
el.style.backgroundColor = '#ffffff';
el.children[1].style.backgroundColor = randcolor;
if (randcolor ==='#ffffff') {
var randnowhitecolors = nowhitecolors[Math.floor(Math.random() * nowhitecolors.length)];
el.style.borderColor = randnowhitecolors;
el.children[0].style.borderColor = randnowhitecolors;
el.style.backgroundColor =randnowhitecolors;
el.style.color = randnowhitecolors;
};
}
);
};
.blog_preview_container {
grid-row: 2;
grid-column: 1;
height: 354px;
display: flex;
flex-flow: row wrap;
justify-content: center;
column-gap: 40px;
row-gap: 40px;
}
.blog_tile {
height: 340px;
width: 240px;
margin-top: 0px;
border-width: 6px;
border-style: solid;
border-radius: 6px;
box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.65);
color: white;
display: inline;
cursor: pointer;
transform: scale(1);
}
.blog_tile:hover {
transform: scale(1.04);
}
.blog_tile img {
height: 164px;
width: 240px;
padding: 0px;
margin: 0px;
object-fit: cover;
border-bottom-width: 6px;
border-bottom-style: solid;
}
.blog_tile p {
height: 138px;
font-family: 'nunito', sans-serif;
font-size: 1rem;
font-weight: 900;
line-height: 22px;
margin: 0;
padding: 16px;
}
<body>
<div class="blog_preview_container">
<div class="blog_tile">
<img class="blog_tile_image" src="https://example.com/img_location">
<p class="blog_tile_text">Text Goes Here</p>
</div>
</div>
</body>
Looks great at all screen sizes, no more gaps!
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>
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;
}
I would like to use flex box to create a square of 4 blocks (like a grid) in the center of my page but all it keeps giving me a 1 long square column what can i do to change it i tried resizing but dosnt work , i dont know if its any other css in my code thats making it malfunction but any input would help thanks in advance
CSS `#import url(https://fonts.googleapis.com/css?family=Open+Sans:400,800,700,300);
#import url(https://fonts.googleapis.com/css?family=Squada+One);
Body {
/*background-color:rgb(28, 18, 63);*/
background-repeat: no-repeat;
background-image: url("https://www.3d-wallpapers.info/wp-content/uploads/3D-Car-Wallpaper.jpg");
background-attachment: fixed;
}
.div-header {
background-image: url("http://hdwpro.com/wp-content/uploads/2017/09/Art-Metal-Wallpaper.jpg");
border: 2px solid red;
height: 250px;
}
h2,
h1 {
color: green;
}
.formdiv {
border: 2px solid red;
width: 20%;
float: right;
}
H2 {
margin: 20px auto;
color: rgb(151, 1, 1);
font-size: 3.26em;
line-height: 1.5;
text-shadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0, 0, 0, .1), 0 0 5px rgba(0, 0, 0, .1), 0 1px 3px rgba(0, 0, 0, .3), 0 3px 5px rgba(0, 0, 0, .2), 0 5px 10px rgba(0, 0, 0, .25), 0 10px 10px rgba(0, 0, 0, .2), 0 20px 20px rgba(0, 0, 0, .15);
}
.sitename {
border: 2px solid red;
width: 40%;
height: 245px;
size: 2.23em;
float: right;
}
.container {
color: rgb(255, 255, 255);
padding: 0px;
border: 1px red solid;
width: 100%;
height: 600px;
}
.item {
/*color:red;
text-align: center;
margin:5px;
background: oldlace;
width:50%;;
width: 40%;
justify-content: center;*/
width: 40vw;
height: 20vw;
margin: 5px;
background-color: red;
}
.hyper {
background-image: url("http://itsmyideas.com/wp-content/uploads/2013/02/Bugatti-Veyron-2013-2014-Model-picture-with-price-details-520x266.jpg");
background-repeat: no-repeat;
height: 400px;
object-fit: contain;
}
.sport {
background-image: url("C:/carwebsite/Images/mustty2.jpg");
background-repeat: no-repeat;
height: 400px;
}
.exotic {
background-image: url("C:/carwebsite/Images/lamb32.jpg");
background-repeat: no-repeat;
height: 400px;
}
.classic {
background-image: url("C:/carwebsite/Images/must5 (1).jpg");
background-repeat: no-repeat;
height: 400px;
}
.container2 {
justify-content: center;
height: 65px;
background-color: rgb(10, 7, 2);
padding-top: 0px;
width: 100%;
}
.container2 {
justify-content: center;
height: 65px;
background-color: rgb(10, 7, 2);
padding-top: 0px;
width: 100%;
}
.nav {
color: rgb(255, 255, 255);
padding: 15px;
margin: 5px;
background: rgba(14, 11, 6, 0);
margin: 20px;
border-radius: 5px;
list-style: none;
text-align: center;
padding-bottom: 30px;
display: inline;
flex-grow: initial;
}
iframe {
border: 1px solid red;
width: 30%;
}
.youvideo {
margin: 20px auto;
width: 100%;
border: 1px solid red;
justify-content: right;
padding-top: 50px
}
.button {
color: green;
text-align: center;
padding: .625em 1.25em;
background: blueviolet;
border-radius: .35em
}
#media (max-width: 1025px) {
iframe {
width: 250px;
}
.container {
display: flex;
flex-flow: wrap;
height: 250px;
width: 75%;
flex-wrap: wrap;
}
.item {
flex-basis: 0;
height: 150px;
padding-top: 0px
}
}
css flexbox `.container {
/*display: flex;
justify-content: center;
height: 30;
flex-wrap: wrap;
margin: 20px auto;
*/
display: flex;
flex-wrap: wrap;
}
.item {
color: red;
text-align: center;
padding: 15px;
margin: 5px;
background: oldlace;
width: 25%;
justify-content: center;
margin-top: auto;
}
.container2 {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.nav {
flex-basis: 200px;
}
.youvideo {
display: flex;
}
.div-header {
display: flex;
}
.div-header {
display: flex;
}
<!DOCTYPE html>
<HTML>
<body>
<link rel="stylesheet" href="C:\workbenchPrac\prac.css">
<link rel="stylesheet" href="C:\carwebsite\flexobox.css">
<div class="div-header">
<header class="head-image">
<div class="formdiv">
<form action="index.html" method="POST">
<h1>LOG-IN</h1>
<input type="email" id="mail" name="user-email">
<input type="password" id="password" name="user-password">
</div>
<div class="sitename">
<h2>Allmotors<br>alliance</h2>
</div>
</div>
</header>
</div>
<div class="container2">
<ul>
<li class="nav">upcoming races</li>
<li class="nav">shows</li>
<li class="nav">News</li>
<li class="nav">new Releases</li>
</ul>
</div>
<div class="youvideo">
<iframe width="560" height="315" src="https://www.youtube.com/embed/2UKdf0ot0wA?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
<div class="container">
<div class="hyper item"><a class="button">hyper</a></div>
<div class="sport item"><a class="button">hyper</a></div>
<div class="exotic item"><a class="button">hyper</a></div>
<div class="classic item"><a class="button">hyper</a></div>
</div>
</body>
</HTML>
Hope this is what you were looking for .
.main-container{display:flex; min-height:400px; background:red; }
.inner-first-items{flex:1; display:flex; flex-direction:column; }
.inner-square-div{flex:1; border:1px solid #000; text-align:center; }
<div class="main-container">
<div class="inner-first-items">
<div class="inner-square-div">1</div>
<div class="inner-square-div">2</div>
</div>
<div class="inner-first-items">
<div class="inner-square-div">3</div>
<div class="inner-square-div">4</div>
</div>
<div>
use display: flex; as shown below: to container class
.container{
display: flex;
}
I wouldn't think you would need flexbox for such a thing. Something along the lines of
<div class="container">
<div class="container-center">
<div class="hyper item"><a class="button">hyper</a></div>
<div class="sport item"><a class="button">hyper</a></div>
<div class="exotic item"><a class="button">hyper</a></div>
<div class="classic item"><a class="button">hyper</a></div>
</div>
</div>
.container-center{
width:80%;
margin:0 auto;
}
.item {
width:50%;
height:20vw;
float:left;
}
Would get you pretty close.
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.