I'm trying to implement a specific design but have stumbled upon quite a lot of complexities by now.
The main problem remains the background of linear gradient - it shall be stretched on the whole viewport to have the satisfactory effect (position: absolute;width: 100%;height: 100%).
But that's not the only problem, we also have a background image P above that gradient image (with higher z-index and opacity 0.3) and the gradient shall be only visible for header and footer (anything below must only have P and not gradient).
And I did that. (JSFiddle, view the code below)
Code
#index_header {
display: block;
position: relative;
}
#index_navigation {
position: relative;
top: 0px;
padding-top: 25px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
min-width: 850px;
width: 80%;
margin: 0 auto;
}
#index_logo {
display: block;
width: 150px;
height: 52px;
background-image: url("images/index/logo.png");
background-size: contain;
background-repeat: no-repeat;
}
#index_navigation_left {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_navigation_center {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
-ms-flex-preferred-size: 80%;
flex-basis: 80%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_navigation_right {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_navigation_core {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
list-style-type: none;
text-align: center;
min-width: 420px;
padding: 0;
width: 60%;
}
#index_navigation_core li {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
#index_navigation_core li a {
color: white;
font-size: 1.250em;
text-decoration: none;
cursor: pointer;
}
#navigator_authentication {
display: block;
background-color: white;
text-decoration: none;
color: #860001;
cursor: pointer;
font-size: 1.125em;
padding: 10px 30px 10px 30px;
border-radius: 20px;
}
#index_footer {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
min-width: 850px;
width: 80%;
margin: 0 auto;
}
#index_footer_left {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_footer_right {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_footer_left p {
font-size: 0.938em;
font-family: 'bpg_arialregular';
color: white;
}
#social_media_btns {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
padding: 0;
list-style-type: none;
}
#social_media_btns li {
display: inline-block;
margin-left: 10px;
margin-right: 10px;
}
#social_media_btns li a {
display: block;
width: 30px;
height: 30px;
}
#social_media_facebook {
background-size: cover;
background-image: url("images/social_media_icons/universal/facebook.png");
}
#social_media_youtube {
background-size: cover;
background-image: url("images/social_media_icons/universal/youtube.png");
}
#social_media_twitter {
background-size: cover;
background-image: url("images/social_media_icons/universal/twitter.png");
}
.present {
border-bottom: solid white 3px;
}
.nav_button {
-webkit-transition: border 0.35s ease;
-o-transition: border 0.35s ease;
transition: border 0.35s ease;
}
.nav_button:hover {
border-bottom: solid white 3px;
}
#mobile_menu {
display: none;
width: 80px;
height: 80px;
cursor: pointer;
background-image: url("images/icons/menu.png");
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
}
#media only screen and (max-width: 880px) {
#index_navigation {
min-width: 300px;
}
#index_navigation_center {
display: none;
}
#mobile_menu {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_footer {
min-width: 300px;
}
}
#media only screen and (max-width: 500px) {
#navigator_authentication {
font-size: 0.9em;
padding: 5px 10px 5px 10px;
}
#mobile_menu {
width: 60px;
height: 60px;
}
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
background-color: #F5F5F5;
}
#index_overlay {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
width: 100%;
height: 100%;
z-index: 0;
}
#index_header {
z-index: 3;
}
#about_pattern {
position: absolute;
z-index: 1;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-image: url("https://i.imgur.com/F8SFW2p.png");
background-size: cover;
background-repeat: no-repeat;
width: 100%;
height: 100%;
opacity: 0.3;
}
#about_pattern_2 {
position: absolute;
z-index: -1;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: linear-gradient(180deg, rgba(100, 0, 1, 0.75) 0%, rgba(189, 0, 1, 0.75) 24.86%, rgba(210, 0, 1, 0.75) 82.87%, rgba(100, 0, 1, 0.75) 100%);
border: 1px solid #000000;
box-sizing: border-box;
}
#index_navigation {
padding-bottom: 25px;
}
#nav_background {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
}
#about_center {
position: relative;
display: flex;
z-index: -1;
overflow-y: scroll;
flex-grow: 1;
}
#about_background {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #F5F5F5;
z-index: -1;
}
#foot_background {
display: inline-block;
position: absolute;
width: 100%;
height: 100%;
}
#intro_text {
position: relative;
padding-left: 10%;
padding-right: 10%;
padding-top: 60px;
padding-bottom: 60px;
font-size: 1.125em;
text-decoration: none;
line-height: normal;
flex-direction: column;
justify-content: space-between;
min-height: 100%;
overflow-y: auto;
text-align: left;
color: #4F4F4F;
}
footer {
position: relative;
padding-top: 25px;
padding-bottom: 25px;
flex-shrink: 0;
z-index: 3;
}
<!DOCTYPE html>
<html lang="ge">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="about.css" type="text/css" charset="utf-8">
<link rel="stylesheet" href="universal.css" type="text/css" charset="utf-8">
</head>
<body>
<div id="index_overlay">
<div id="about_pattern"></div>
<div id="about_pattern_2"></div>
<header id="index_header">
<div id="nav_background"></div>
<div id="index_navigation">
<div id="index_navigation_left">
<a id="index_logo" href="/"></a>
</div>
<div id="index_navigation_center">
<ul id="index_navigation_core">
<li>
btn1
</li>
<li>
btn2
</li>
<li>
btn3
</li>
</ul>
</div>
<div id="mobile_menu"></div>
<div id="index_navigation_right">
btn4
</div>
</div>
</header>
<div id="about_center">
<div id="about_background"></div>
<div id="intro_text">
<div style="text-align: center;">text here</div>
<br><br> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<footer>
<div id="foot_background"></div>
<div id="index_footer">
<div id="index_footer_left">
<p>© 2018 mysite</p>
</div>
<div id="index_footer_right">
<ul id="social_media_btns">
<li>
<a target="_blank" id="social_media_facebook"></a>
</li>
<li>
<a target="_blank" id="social_media_youtube"></a>
</li>
<li>
<a id="social_media_twitter"></a>
</li>
</ul>
</div>
</div>
</footer>
</div>
<script src="scripts/jquery/jquery.js"></script>
<script src="scripts/custom/main.js"></script>
</body>
</html>
Problem:
Even though I visually achieved it, there's a significant concern for practical usage.
If you look at the code, #about_pattern is a background image P and #about_pattern_2 is a gradient image.
#about_center element that is stuck between header and footer, must have lower z-index compared to #about_pattern (so it can pass through) and equal or higher z-index compared to #about_pattern2 (so we don't have gradient effect there).
But #about_pattern being on the top, makes every element in #about_center not accessible to user. Which seems to be a big problem if someone wants to for example scroll through text...
Is it possible to achieve this effect without blocking the central element? Thank you!
A solution is to remove z-index from #about_center to avoid stacking context issue1 then you will able to place #about_background and #intro_text like you want as they will be in the same stacking context of the gradient background. You can then place one below and the other above.
So you remove this:
#about_center {
position: relative;
display: flex;
/*z-index: -1; */
overflow-y: scroll;
flex-grow: 1;
}
And add this:
#intro_text {
....
z-index:3;
}
Full code:
https://jsfiddle.net/tfx9pLrq/3/
#index_header {
display: block;
position: relative;
}
#index_navigation {
position: relative;
top: 0px;
padding-top: 25px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
min-width: 850px;
width: 80%;
margin: 0 auto;
}
#index_logo {
display: block;
width: 150px;
height: 52px;
background-image: url("images/index/logo.png");
background-size: contain;
background-repeat: no-repeat;
}
#index_navigation_left {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_navigation_center {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
-ms-flex-preferred-size: 80%;
flex-basis: 80%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_navigation_right {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_navigation_core {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
list-style-type: none;
text-align: center;
min-width: 420px;
padding: 0;
width: 60%;
}
#index_navigation_core li {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
#index_navigation_core li a {
color: white;
font-size: 1.250em;
text-decoration: none;
cursor: pointer;
}
#navigator_authentication {
display: block;
background-color: white;
text-decoration: none;
color: #860001;
cursor: pointer;
font-size: 1.125em;
padding: 10px 30px 10px 30px;
border-radius: 20px;
}
#index_footer {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
min-width: 850px;
width: 80%;
margin: 0 auto;
}
#index_footer_left {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_footer_right {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_footer_left p {
font-size: 0.938em;
font-family: 'bpg_arialregular';
color: white;
}
#social_media_btns {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
padding: 0;
list-style-type: none;
}
#social_media_btns li {
display: inline-block;
margin-left: 10px;
margin-right: 10px;
}
#social_media_btns li a {
display: block;
width: 30px;
height: 30px;
}
#social_media_facebook {
background-size: cover;
background-image: url("images/social_media_icons/universal/facebook.png");
}
#social_media_youtube {
background-size: cover;
background-image: url("images/social_media_icons/universal/youtube.png");
}
#social_media_twitter {
background-size: cover;
background-image: url("images/social_media_icons/universal/twitter.png");
}
.present {
border-bottom: solid white 3px;
}
.nav_button {
-webkit-transition: border 0.35s ease;
-o-transition: border 0.35s ease;
transition: border 0.35s ease;
}
.nav_button:hover {
border-bottom: solid white 3px;
}
#mobile_menu {
display: none;
width: 80px;
height: 80px;
cursor: pointer;
background-image: url("images/icons/menu.png");
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
}
#media only screen and (max-width: 880px) {
#index_navigation {
min-width: 300px;
}
#index_navigation_center {
display: none;
}
#mobile_menu {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
#index_footer {
min-width: 300px;
}
}
#media only screen and (max-width: 500px) {
#navigator_authentication {
font-size: 0.9em;
padding: 5px 10px 5px 10px;
}
#mobile_menu {
width: 60px;
height: 60px;
}
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
background-color: #F5F5F5;
}
#index_overlay {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
width: 100%;
height: 100%;
z-index: 0;
}
#index_header {
z-index: 3;
}
#about_pattern {
position: absolute;
z-index: 1;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-image: url("https://i.imgur.com/F8SFW2p.png");
background-size: cover;
background-repeat: no-repeat;
width: 100%;
height: 100%;
opacity: 0.3;
}
#about_pattern_2 {
position: absolute;
z-index: -1;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: linear-gradient(180deg, rgba(100, 0, 1, 0.75) 0%, rgba(189, 0, 1, 0.75) 24.86%, rgba(210, 0, 1, 0.75) 82.87%, rgba(100, 0, 1, 0.75) 100%);
border: 1px solid #000000;
box-sizing: border-box;
}
#index_navigation {
padding-bottom: 25px;
}
#nav_background {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
}
#about_center {
position: relative;
display: flex;
overflow-y: scroll;
flex-grow: 1;
}
#about_background {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #F5F5F5;
z-index: -1;
}
#foot_background {
display: inline-block;
position: absolute;
width: 100%;
height: 100%;
}
#intro_text {
position: relative;
padding-left: 10%;
padding-right: 10%;
padding-top: 60px;
padding-bottom: 60px;
font-size: 1.125em;
text-decoration: none;
line-height: normal;
flex-direction: column;
justify-content: space-between;
min-height: 100%;
overflow-y: auto;
text-align: left;
color: #4F4F4F;
z-index: 3;
}
footer {
position: relative;
padding-top: 25px;
padding-bottom: 25px;
flex-shrink: 0;
z-index: 3;
}
<div id="index_overlay">
<div id="about_pattern"></div>
<div id="about_pattern_2"></div>
<header id="index_header">
<div id="nav_background"></div>
<div id="index_navigation">
<div id="index_navigation_left">
<a id="index_logo" href="/"></a>
</div>
<div id="index_navigation_center">
<ul id="index_navigation_core">
<li>
btn1
</li>
<li>
btn2
</li>
<li>
btn3
</li>
</ul>
</div>
<div id="mobile_menu"></div>
<div id="index_navigation_right">
btn4
</div>
</div>
</header>
<div id="about_center">
<div id="about_background"></div>
<div id="intro_text">
<div style="text-align: center;">text here</div>
<br><br> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<footer>
<div id="foot_background"></div>
<div id="index_footer">
<div id="index_footer_left">
<p>© 2018 mysite</p>
</div>
<div id="index_footer_right">
<ul id="social_media_btns">
<li>
<a target="_blank" id="social_media_facebook"></a>
</li>
<li>
<a target="_blank" id="social_media_youtube"></a>
</li>
<li>
<a id="social_media_twitter"></a>
</li>
</ul>
</div>
</div>
</footer>
</div>
1For a more accurate explanation we can refer to the specification:
For those with 'z-index: auto', treat the element as if it created a
new stacking context, but any positioned descendants and descendants
which actually create a new stacking context should be considered part
of the parent stacking context, not this new one.
So by removing z-index it will fall back to auto and we removed the restriction of making our elements in the stacking context of their parent and controled by the z-index of their parent. They now belong to the upper stacking context which is the same as the gradient.
In other words, adding z-index to the parent element will make z-index of child elements to only be consider inside their parent after that everything will be placed considering the z-index of the parent. Either everything will be above the gradient or everything below it.
Related
I am trying to make my website look adaptive for both smartphones and desktops. There're Chart and Info blocks. I want them to be positioned across the width on desktops and laptops, and one above the other on the mobiles. But Chart goes into first block at the small mobile width. What can I do here?
.
It already looks nice and good at desktops.
#media only screen and (min-width: 320px) and (max-width: 1281px) {
/* ??? */
}
<div class="justify-content-flex-start" style="margin-top: 10px; padding-left: 0%; padding-right: 1%;margin-left:15%; min-width: 320px; max-width: 1281px;">
<div class="row" style="margin-top: 10px; padding-left: 1%; padding-right: 1%;">
</div>
</div> <!-- First block -->
<div class="container" style="width: 360px; margin-top: 10px; padding-left: 1%; padding-right: 1%; padding-bottom: 10%; margin-right: 25%">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script src="./src/js/graph.js"></script>
<div id="FlexCGraph justify-content: center" ><iframe class="chartjs-hidden-iframe" style="display: block; overflow: hidden; border: 0px; margin: 0px; inset: 0px; height: 100%; width: 100%; position: absolute; pointer-events: none; z-index: -1;" src=></iframe>
<canvas id="global-speed-chart" style="display: block; height: 250px; width: 100%; padding-right: 1%; margin-right: -8%; margin-top: -78%; padding-bottom: 5%; padding-top: 1%;"></canvas>
</div>
</div>
<!-- Chart -->
#media (min-width: 1920px) {
.dashboard {
padding: 15px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
position: relative;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
align-items:center;
align-content: center;
justify-content: flex-end;
}
}
#media only screen and (min-device-width: 360px) {
.dashboard__desc {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 100%;
position: relative;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
padding-top: 10px;
align-content: center;
align-items: center;
justify-content: flex-start;
}
}
#media only screen and (min-device-width: 360px){
.crypto-card{
width: 360px;
height: 215px;
background: white;
right: 40px;
padding: 10px;
margin: 10px;
border: 0.1px solid rgb(220, 220, 220);
max-width: 360px;
align-content: center;
align-items: center;
justify-content: center;
}
}
#media only screen and (min-device-width: 360px){
.row{
align-content: center;
align-items: center;
justify-content: center;
}
}
#media only screen and (min-device-width: 360px){
.crypto-card .body{
width: 100%;
padding: 20px;
margin: 2px;
font-size: -0.4rem;
font-family: 'Myriad Pro', sans-serif;
position: relative;
top: 5px;
align-content: center;
align-items: center;
justify-content: center;
}
}
#FlexCGraph
{
align-content: center;
align-items: center;
justify-content: flex-end;
position: absolute;
padding: 10px 10px 10px 10px;
margin: auto;
width: 360px;
height: 215px;
max-width: 360px;
-webkit-flex-grow: 0;
flex-grow: 0;
-webkit-flex-shrink: 0;
flex-shrink: 0;
-webkit-align-self: auto;
align-self: auto;
background-color: transparent;
border: 0.1px solid rgb(220, 220, 220);
box-sizing: border-box;
flex: 0 0 50%;
}
#wb_FlexCGraph
{
align-content: center;
align-items: center;
justify-content: flex-end;
padding-left: 10%;
visibility: visible;
display: block;
-webkit-flex-grow: 0;
flex-grow: 0;
-webkit-flex-shrink: 0;
flex-shrink: 0;
-webkit-align-self: auto;
align-self: auto;
}
}
I'm following some tutorials to do some coding, and I've found that for some reason, when i use the ::before pseudo attribute, and try to set the background color of it, nothing is visible.
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #1d061a;
font-family: consolas;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
padding: 40px 0;
}
.container .box {
position: relative;
width: 320px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
margin: 40px 30px;
transition: 0.5s;
}
.container .box::before {
content: '';
position: absolute;
top: 0;
left: 50px;
width: 50%;
height: 100%
background: #fff;
border-radius: 8px;
transform: skewX(15deg);
transition: 0.5s;
}
(I couldn't figure out how to get the code to display correctly)
Little syntax error; all that was missing was a " ; " after your height declaration in the ::before selector, causing your background-color to not be picked up.
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #1d061a;
font-family: consolas;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
padding: 40px 0;
}
.container .box {
position: relative;
width: 320px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
margin: 40px 30px;
transition: 0.5s;
}
.container .box::before {
content: '';
position: absolute;
top: 0;
left: 50px;
width: 50%;
height: 100%;
background: #fff;
border-radius: 8px;
transform: skewX(15deg);
transition: 0.5s;
}
<div class="container">
<div class="box"></div>
</div>
You've got some error in your ::before missing a ; after height declaration.
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #1d061a;
font-family: consolas;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
padding: 40px 0;
}
.container .box {
position: relative;
width: 320px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
margin: 40px 30px;
transition: 0.5s;
background: #f00;
}
.container .box::before {
content: '';
position: absolute;
top: 0;
left: 50px;
width: 50%;
height: 100%;
display: block;
background: #fff;
border-radius: 8px;
transform: skewX(15deg);
transition: 0.5s;
}
<div class="container">
<div class="box"></div>
</div>
When hoovering the menu element a drop down box shall appear. It does but it is cut. Not sure what is wrong here if the Ul nav list cuts it. The drop down menu has been tested ok but not with this menu. I also tried to change the z-index, but without any result. Can you see anything that can inhibit the drop down menu to show?
var navList = document.getElementById("nav-lists");
function Show() {
navList.classList.add("_Menus-show");
}
function Hide() {
navList.classList.remove("_Menus-show");
}
*,
*::before,
*::after {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body {
font-family: sans-serif;
margin: 0;
padding: 0;
}
.container {
height: 80px;
background-color: #333333;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
overflow: hidden;
}
.container .logo {
max-width: 250px;
padding: 0 10px;
overflow: hidden;
}
.container .logo a {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
height: 60px;
}
.container .logo a img {
max-width: 100%;
max-height: 60px;
}
.container .navbar {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 0 10px;
}
.container .navbar ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
list-style: none;
margin: 0;
padding: 0;
}
.container .navbar ul li a {
text-decoration: none;
color: #999999;
font-size: 20px;
text-transform: uppercase;
display: block;
height: 60px;
line-height: 60px;
cursor: pointer;
padding: 0 10px;
}
.container .navbar ul li a:hover {
color: #ffffff;
background-color: rgba(23, 23, 23, 0.9);
}
.container .navbar ul .close {
display: none;
text-align: right;
padding: 10px;
}
.container .navbar ul .close span {
font-size: 40px;
display: inline-block;
border: 1px solid #cccccc;
padding: 0 10px;
cursor: pointer;
}
.container .navbar .icon-bar {
padding: 18px 8px;
width: 50px;
height: 60px;
display: none;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
cursor: pointer;
}
.container .navbar .icon-bar i {
background-color: #ffffff;
height: 2px;
}
#media only screen and (max-width: 650px) {
.container {
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.container .logo {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.container .navbar {
-webkit-box-flex: 0;
-ms-flex: 0;
flex: 0;
}
.container .navbar ul {
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
position: fixed;
left: 100%;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
background: #ffffff;
width: 100%;
height: 100%;
overflow: auto;
-webkit-transition: left .3s;
-o-transition: left .3s;
transition: left .3s;
}
.container .navbar ul li a {
padding: 10px;
font-size: 20px;
height: auto;
line-height: normal;
color: #555555;
}
.container .navbar ul .close {
display: block;
}
.container .navbar .icon-bar {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.container .navbar ._Menus-show {
left: 0;
}
}
.body {
max-width: 700px;
margin: 0 auto;
padding: 10px;
}
/* start of drop down */
/* dropdown css starts here */
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #0009f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 10;
}
.dropdown:hover .dropdown-content {
display: block;
}
.desc {
padding: 15px;
width: 400px;
height: 160px;
font-family: Arial;
}
.desc_Info {
padding: 15px;
width: 400px;
height: 220px;
font-family: Arial;
}
span {
cursor: pointer;
}
/* hand over menu item */
/* END drop down menu */
<html>
<head>
<title>Nav bar</title>
</head>
<body>
<div class="container">
<div class="logo">
<img src="./bilder/logo2.jpg" alt="Start">
</div>
<div class="navbar">
<div class="icon-bar" onclick="Show()">
<i></i>
<i></i>
<i></i>
</div>
<ul id="nav-lists">
<li class="close"><span onclick="Hide()">×</span></li>
<li class="elements">
<div class="dropdown">
Cars
<div class="dropdown-content">
<div class="desc">assadsadsad<br /><br /> asdasdsadasdsadsad
<br /><br /> adsasdsasaasdasdasdsdasad
</div>
</div>
</div>
</li>
<li>Bikes</li>
</ul>
</div>
</div>
<div class="body">
<p>Hello yes !</p>
</div>
</body>
</html>
Remove the overflow: hidden; from the .container. This cuts off the dropdown.
var navList = document.getElementById("nav-lists");
function Show() {
navList.classList.add("_Menus-show");
}
function Hide() {
navList.classList.remove("_Menus-show");
}
*,
*::before,
*::after {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body {
font-family: sans-serif;
margin: 0;
padding: 0;
}
.container {
height: 80px;
background-color: #333333;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.container .logo {
max-width: 250px;
padding: 0 10px;
overflow: hidden;
}
.container .logo a {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
height: 60px;
}
.container .logo a img {
max-width: 100%;
max-height: 60px;
}
.container .navbar {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 0 10px;
}
.container .navbar ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
list-style: none;
margin: 0;
padding: 0;
}
.container .navbar ul li a {
text-decoration: none;
color: #999999;
font-size: 20px;
text-transform: uppercase;
display: block;
height: 60px;
line-height: 60px;
cursor: pointer;
padding: 0 10px;
}
.container .navbar ul li a:hover {
color: #ffffff;
background-color: rgba(23, 23, 23, 0.9);
}
.container .navbar ul .close {
display: none;
text-align: right;
padding: 10px;
}
.container .navbar ul .close span {
font-size: 40px;
display: inline-block;
border: 1px solid #cccccc;
padding: 0 10px;
cursor: pointer;
}
.container .navbar .icon-bar {
padding: 18px 8px;
width: 50px;
height: 60px;
display: none;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
cursor: pointer;
}
.container .navbar .icon-bar i {
background-color: #ffffff;
height: 2px;
}
#media only screen and (max-width: 650px) {
.container {
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.container .logo {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.container .navbar {
-webkit-box-flex: 0;
-ms-flex: 0;
flex: 0;
}
.container .navbar ul {
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
position: fixed;
left: 100%;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
background: #ffffff;
width: 100%;
height: 100%;
overflow: auto;
-webkit-transition: left .3s;
-o-transition: left .3s;
transition: left .3s;
}
.container .navbar ul li a {
padding: 10px;
font-size: 20px;
height: auto;
line-height: normal;
color: #555555;
}
.container .navbar ul .close {
display: block;
}
.container .navbar .icon-bar {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.container .navbar ._Menus-show {
left: 0;
}
}
.body {
max-width: 700px;
margin: 0 auto;
padding: 10px;
}
/* start of drop down */
/* dropdown css starts here */
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #0009f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 10;
}
.dropdown:hover .dropdown-content {
display: block;
}
.desc {
padding: 15px;
width: 400px;
height: 160px;
font-family: Arial;
}
.desc_Info {
padding: 15px;
width: 400px;
height: 220px;
font-family: Arial;
}
span {
cursor: pointer;
}
/* hand over menu item */
/* END drop down menu */
<html>
<head>
<title>Nav bar</title>
</head>
<body>
<div class="container">
<div class="logo">
<img src="./bilder/logo2.jpg" alt="Start">
</div>
<div class="navbar">
<div class="icon-bar" onclick="Show()">
<i></i>
<i></i>
<i></i>
</div>
<ul id="nav-lists">
<li class="close"><span onclick="Hide()">×</span></li>
<li class="elements">
<div class="dropdown">
Cars
<div class="dropdown-content">
<div class="desc">assadsadsad<br /><br /> asdasdsadasdsadsad
<br /><br /> adsasdsasaasdasdasdsdasad
</div>
</div>
</div>
</li>
<li>Bikes</li>
</ul>
</div>
</div>
<div class="body">
<p>Hello yes !</p>
</div>
</body>
</html>
I know there are a lot of questions about this, I've tried some of them and I didn't have that much luck.
I have this structure:
HTML:
<header>
<div class="logo">
<a><img style="height: 50px;" src="https://user94.files.wordpress.com/2009/12/ubuntu-logo.png"></a>
</div>
<div class="header-content">
<nav>
About me
Education
Personal life
My work
Contact me
</nav>
</div>
</header>
CSS:
header {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: column;
align-items: center;
align-items: center;
text-align: center;
min-height: 100vh;
width: 100%;
background: url(http://via.placeholder.com/1920x1080) no-repeat 10% 10% / cover;
}
.header-content {
margin-top: 2em;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: column;;
justify-content: center;
align-items: center;
text-align: center;
}
.logo{
padding-right: 0;
}
nav {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: row;
flex-direction: row;
font-weight: 400;
color: rgb(49, 41, 61);
font-size: .8em;
margin-top: 2em;
margin-left: 30em;
}
I'm trying to move the logo to the left without affecting my navigation items to the right, I was so much in trouble getting the nav items to the right and over the image that I don't get how to make both of them positioned correctly.
How can I make it work?
https://codepen.io/anon/pen/zLMzpO
This CSS for header should do what you want:
header {
display: flex;
align-items: baseline;
justify-content: space-between;
min-height: 100vh;
background: url(http://via.placeholder.com/1920x1080) no-repeat 10% 10% / cover;
}
https://codepen.io/anon/pen/YjRQRV
(no column direction, justify-content: space-between; and align-items: baseline; are the essential changes to your version)
Here is my solution:
.logo{
padding-right: 0;
opacity: 1;
}
.logo img{
opacity: 0;
}
.logo::after{
content: "";
width: 50px;
height: 54px;
opacity: 0.99;
position: absolute;
top: 10px;
left: 10px;
background: url("https://user94.files.wordpress.com/2009/12/ubuntu-logo.png") no-repeat;
background-size: 100% 100%;
}
in navigation bar you should use flex-direction: row.
here is a useful link flexbox basic navigation - menu items and logo
body{
margin:0;
}
header {
display: flex;
align-items: baseline;
justify-content: space-between;
min-height: 100vh;
background: url(http://via.placeholder.com/1920x1080) no-repeat 10% 10% / cover;
}
.header-content {
margin-top: 2em;
}
header a,
header a:visited {
color: rgb(252, 252, 252);
text-decoration: none;
padding-bottom: 0.1em;
}
header a:hover {
color: #FA26BF;
}
.logo{
padding-right: 0;
}
.logo img{
vertical-align: bottom;
}
nav {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: row;
flex-direction: row;
font-weight: 400;
color: rgb(49, 41, 61);
font-size: .8em;
margin-top: 2em;
margin-left: 30em;
}
nav a {
margin: 1em;
}
nav a,
nav a:visited {
padding-bottom: 0.1em;
letter-spacing: 0.1em;
text-decoration: none;
color: rgb(252, 252, 252);
}
nav a:hover,
nav a:active {
color: #FA26BF;
}
<header>
<div class="logo">
<a><img style="height: 50px;" src="https://user94.files.wordpress.com/2009/12/ubuntu-logo.png"></a>
</div>
<div class="header-content">
<nav>
About me
Education
Personal life
My work
Contact me
</nav>
</div>
</header>
Hi my friend is having trouble centering the text in the middle of the margins.
When I look at this site in IE 11 it just doesn't seem to center, could some one help me as to why?
<header id="site-header" class="site-header valign-center">
<div class="intro">
<h2>x</h2>
<p> y </p>
<h1>z</h1>
<a class="btn btn-white" data-scroll href="#foo">button</a>
</div>
</header>
The CSS:
.site-header {
width: 100%;
height: 100%;
min-height: 100vh;
position: relative;
text-align: center;
background: url(../images/backgrounds/header.jpg) no-repeat center center/cover;
}
.valign-center {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.site-header .intro {
color: #fff;
position: relative;
text-align: center;
text-transform: uppercase;
width: 100%;
z-index: 1;
padding: 0 15px;
}
I've tried margin: 0 auto; but it doesn't change.
Many Thanks,
Add html, body { height: 100%; }
html,body {
height: 100%;
}
.site-header {
width: 100%;
height: 100%;
min-height: 100vh;
position: relative;
text-align: center;
background: url(../images/backgrounds/header.jpg) no-repeat center center/cover;
}
.valign-center {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.site-header .intro {
position: relative;
text-align: center;
text-transform: uppercase;
width: 100%;
z-index: 1;
padding: 0 15px;
}
<header id="site-header" class="site-header valign-center">
<div class="intro">
<h2>x</h2>
<p> y </p>
<h1>z</h1>
<a class="btn btn-white" data-scroll href="#foo">button</a>
</div>
</header>
Or you can just use height: 100vh on .site-header
.site-header {
width: 100%;
height: 100vh;
position: relative;
text-align: center;
background: url(../images/backgrounds/header.jpg) no-repeat center center/cover;
}
.valign-center {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.site-header .intro {
position: relative;
text-align: center;
text-transform: uppercase;
width: 100%;
z-index: 1;
padding: 0 15px;
}
<header id="site-header" class="site-header valign-center">
<div class="intro">
<h2>x</h2>
<p> y </p>
<h1>z</h1>
<a class="btn btn-white" data-scroll href="#foo">button</a>
</div>
</header>