CSS - Button border gradient [duplicate] - html

This question already has answers here:
Border Gradient with Border Radius
(2 answers)
Closed 1 year ago.
After searching extensively I am stuck on how I might go about replicating this button in CSS, specifically the border as I deed to use this on other elements if possible.
The Designed Button
button.rounded-button {
box-sizing: border-box;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 1.125rem 2rem;
position: absolute;
width: 13.5919rem;
height: 4.375rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(0.7942rem);
border-radius: 5.8652rem;
border-image-slice: 1 1 0 0;
border: 1px solid;
border-image-source: linear-gradient(257.34deg, #FFFFFF 4.56%, rgba(255, 255, 255, 0) 29.19%);
font-size: 1.25rem;
line-height: 2.125rem;
color: #fff;
}
body {
background: #393939;
}
<!-- SVG Not included with the example -->
<button type="button" class="rounded-button">
Watch video
<!-- <img src="/assets/img/glyphs/ic-play.svg" alt="Watch video"> -->
</button>
Ideally I am looking to have a class that I can apply to any element which adds the desired effect and that can be reversed, I have tried pseudo elements such as :after but to no joy
I really am not sure if this can be acvhieved in pure css 🤦🏻‍♂️

Consider using a ::before hidden behind. This is the closest I can make it without additional elements.
button.rounded-button {
box-sizing: border-box;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 1rem 2.25rem;
border-radius: 1000px;
border: none;
position: relative;
background: #343434;
font-size: 1.25rem;
line-height: 2rem;
color: #fff;
}
button.rounded-button::before {
content: '';
display: block;
position: absolute;
border-radius: 1000px;
top: -0.1em;
bottom: -0.1em;
right: -0.1em;
left: -0.1em;
z-index: -1;
background: linear-gradient(240deg, #ffffff 0%, #343434 25%);
}
body {
background: #1d1d1d;
padding: 2rem;
}
<button type="button" class="rounded-button">
Watch video
</button>
But it would be better to have a wrapper around the button as ::before with z-index: -1 is a bit of a hack.
Bonus
Then you can add some glass like effect to it.
button.rounded-button {
box-sizing: border-box;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 1rem 2.25rem;
border-radius: 1000px;
border: none;
position: relative;
background: #343434;
font-size: 1.25rem;
line-height: 2rem;
color: #fff;
cursor: pointer;
}
button.rounded-button::before {
content: '';
display: block;
position: absolute;
border-radius: 1000px;
top: -0.1em;
bottom: -0.1em;
right: -0.1em;
left: -0.1em;
z-index: -1;
background: linear-gradient(240deg, #343434 0%, #ffffff 20%, #343434 50%);
background-size: 140%;
background-position: 0 0;
transition: background .3s;
}
button.rounded-button:hover::before {
background-position: 100% 0;
}
body {
background: #1d1d1d;
padding: 2rem;
}
<button type="button" class="rounded-button">
Watch video
</button>

You can use box-shadow to apply a border effect on just the right side:
box-shadow: 5px 0 1px -2px grey;
.rounded-button {
box-shadow: 5px 0 1px -2px grey;
}
/* YOUR INITIAL CODE */
button.rounded-button {
box-sizing: border-box;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 1.125rem 2rem;
position: absolute;
width: 13.5919rem;
height: 4.375rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(0.7942rem);
border-radius: 5.8652rem;
border-image-slice: 1 1 0 0;
border: 1px solid;
border-image-source: linear-gradient(257.34deg, #FFFFFF 4.56%, rgba(255, 255, 255, 0) 29.19%);
font-size: 1.25rem;
line-height: 2.125rem;
color: #fff;
}
body {
background: #393939;
}
<button type="button" class="rounded-button">
Watch video
</button>

Related

Overlapping Divs, need them to be vertical on top of each other

I'm trying to stack the on top of each other vertically but they are overlapping for some reason and not sure if it has to do with the positioning. I'm not very good at CSS. Also, is there an easier way to align the datetime span to the right side instead of using padding-left: 1140px? Thank you
<div class="content-box">
<span class="name">John Doe</span>
<span class="datetime">May 2022</span><br><br>
<span class="content">Lorem ipsum</span>
</div>
<div class="content-box">
<span class="name">Jane Doe</span>
<span class="datetime">June 2022</span><br><br>
<span class="content">Lorem ipsum</span>
</div>
.content-box {
justify-content: center;
top: 600px;
position: absolute;
width: 75%;
border: none;
outline: none;
font-family: 'Roboto Mono', monospace;
font-size: 18px;
transform: translate(0);
background-image: linear-gradient(45deg, #4568DC, #B06AB3);
padding: 20px 40px;
border-radius: 5px;
box-shadow: 0 22px 44px rgba(128, 128, 128, 0.1);
transition: box-shadow .25s;
padding: 60px;
}
.content-box .name {
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-image: linear-gradient(45deg, #4568DC, #B06AB3);
font-size: 30px;
}
.content-box .content {
color: #4568DC;
font-size: 20px;
}
.content-box .datetime {
padding-left: 1140px;
color: black;
font-size: 18px;
}
.content-box .content {
color: #4568DC;
font-size: 20px;
}
.content-box:after {
content: '';
border-radius: 4px;
position: absolute;
margin: 1px;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: -1;
background: white;
}
.content-box:hover {
background-image: linear-gradient(-45deg, #00FFFF, #ff1a1a);
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
transition: .5s;
}
.content-box:hover .name {
background-image: linear-gradient(-45deg, #4568DC, #B06AB3);
}
The problem here is that both div has content-box class; this class applies position: absolute; , which is the main cause of overlapping. Removing this css property you should be able to se both div.
Regarding date time span you could change the class .content-box .datetime { color: black; font-size: 18px; } (you have to remove the padding)
And add the following properties to .content-box class to display datetime correctly without padding:
display: flex;
flex-flow: column;

CSS Borders, Unwanted Gaps and Sub-Pixel Rendering Issues

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!

Anchor fails to activate in flexbox item

I have a flex container holding multiple items. I am setting the flex item class inside the anchor tag and trying to enable a link to work when a user clicks the anchored element.
The element is a 3 stage div... the first div is a circle with an icon, the "second" div (if you want to call it a second div...) loads the ::before psuedo element that loads some dimensionality to the circle. and the third div is a text item that appears when the item is hovered.
The issue is that when you hover over the element i am not able to click the follow on link. My guess is the anchor is being covered by the divs.
I have attempted setting z-index's across elements but cant seem to get the anchor to expose itself
HTML:
<div class="flex_row">
<a class="flex_col" src="http://www.cnn.com">
<div class="circle_shape">
<i class="fas fa-sitemap"></i>
<div class="circle_text">
<p>CNN IS A TERRIBLE NEW SOURCE!</p>
</div>
</div>
<div>
<h2>CNN SUCKS</h2>
</div>
</a>
</div>
CSS:
.flex_col{
flex: 1;
margin: 10px;
}
.circle_shape {
position: relative;
display: flex;
padding: 50% 0;
border-radius: 50%;
overflow: hidden;
border: 1px solid gray;
font-size: 16px;
font-family: 'Source Sans Pro', sans-serif;
justify-content: center;
align-items: center;
background: radial-gradient(circle at 50% 120%, #81e8f6, #76deef 10%, #055194 80%, #062745 100%);
}
.circle_shape:before {
content: "";
position: absolute;
top: 1%;
left: 5%;
width: 90%;
height: 90%;
border-radius: 50%;
background: radial-gradient(circle at 50% 0px, #ffffff, rgba(255, 255, 255, 0) 58%);
filter: blur(5px);
z-index: 2;
}
.circle_shape:hover{
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1), 0 1px 2px rgba(0,0,0,0.1);
}
.circle_shape img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.circle_shape i{
position: absolute;
text-align: center;
font-size: 4vw;
text-shadow:
0 0 1px #fff,
0 1px 2px rgba(0,0,0,0.3);
}
.circle_shape h2 {
position: absolute;
bottom: 10%;
font-size: 1vw;
font-weight: 800;
text-align: center;
}
.circle_text{
position: absolute;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0,51,102, 0.9);
border-radius: 50%;
width: 100%;
height: 100%;
overflow: hidden;
opacity: 0;
transition: all 0.4s ease-in-out;
transform: scale(0);
}
.circle_text p {
color: #fff;
padding: 4px;
text-align: center;
font-size: calc(7px + .5vw);
text-shadow:
0 0 1px #fff,
0 1px 2px rgba(0,0,0,0.3);
}
.circle_shape:hover .circle_text{
transform: scale(1);
opacity: 1;
}
fiddle: https://jsfiddle.net/honeynutz/czq9y5fp/4/
I would expect the link in question to load cnn, but instead it does nothing.
The solution is actually very simple and I'm sure you'll kick yourself that you didn't spot it! I'm surprised it took me so long.
The issue is that you're using src on your anchor where you should be using href
More information on HTML Links

Inconsistent margins between Chromium and Firefox

I'm trying to make a tooltip for a button that can have a variable offset. I thought I had found a good solution, but something strange happens when tested in another browser. The code below (and in this fiddle) will render differently between Chromium 72.0.3626.81 and Firefox 66.0b3 (both on Arch Linux). On Chromium it displays as expected, but on Firefox the tooltip is not offset correctly. On Firefox, the margin of the actual tooltip is off by half of what it should be.
Why does this happen, and how can I keep the intended behaviour consistent between browsers?
:root {
font-size: 62.5%;
font-family: 'sans-serif';
--tooltip-offset: 50px;
}
.container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.link {
border-radius: 4px;
height: 4rem;
font-size: 1.6rem;
border: 1px solid hsl(215, 36%, 78%);
padding: 0 1.5rem;
justify-content: center;
align-items: center;
display: inline-flex;
}
.tooltip {
font-size: 1.4rem;
z-index: 2;
width: 225px;
position: absolute;
text-align: center;
padding: 0.7rem 3rem;
border-radius: 4px;
pointer-events: none;
top: 100%;
margin-top: 12px;
border: 1px solid black;
margin-left: calc(0px - var(--tooltip-offset));
}
.tooltip:before {
z-index: 1;
content: ' ';
position: absolute;
bottom: 100%;
border-color: transparent transparent black transparent;
margin-left: var(--tooltip-offset);
left: calc(50% - 12px);
border-width: 12px;
border-style: solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet"/>
<div class="container">
<a class="link" href="example.com">
Go to example.com
</a>
<span class="tooltip">
Click here to go to example.com
</span>
</div>
I'm not sure if Firefox and Chrome handle negative margins differently, so a more reliable way might be to use transform:
:root {
font-size: 62.5%;
font-family: 'sans-serif';
--tooltip-offset: 50px;
}
.container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.link {
border-radius: 4px;
height: 4rem;
font-size: 1.6rem;
border: 1px solid hsl(215, 36%, 78%);
padding: 0 1.5rem;
justify-content: center;
align-items: center;
display: inline-flex;
}
.tooltip {
font-size: 1.4rem;
z-index: 2;
width: 225px;
position: absolute;
text-align: center;
padding: 0.7rem 3rem;
border-radius: 4px;
pointer-events: none;
top: 100%;
margin-top: 12px;
border: 1px solid black;
transform: translateX(calc(0px - var(--tooltip-offset)));
}
.tooltip:before {
z-index: 1;
content: ' ';
position: absolute;
bottom: 100%;
border-color: transparent transparent black transparent;
margin-left: var(--tooltip-offset);
left: calc(50% - 12px);
border-width: 12px;
border-style: solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet"/>
<div class="container">
<a class="link" href="example.com">
Go to example.com
</a>
<span class="tooltip">
Click here to go to example.com
</span>
</div>
That looks like it works correctly in both browsers on my end!

Flexbox child ignores parent's padding

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.