I'm new to html/CSS starting a few weeks ago and I decided work on my first template for my little gaming network and got a issue. The problem is I have a ideal header but when I do CSS for text over a header nothing shows up and the header is covering the text no matter what I do.
This how I would like have it + white text over it .
#header .h-bg {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
background-image: url('https://i.imgur.com/OW0YQWa.png');
background-position: center;
background-size: cover;
max-height: 300px;
}
.h-bg:before {
content: "";
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
display: block;
background-color: rgba(0, 0, 0, 0.5);
}
Assuming you're trying to achieve a dark transparent bar that overlaps a background, you were close. You were setting the height to 100% in more than one way.
However, this is probably not the best way to go about it.
#header .h-bg {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
background-image: url('https://i.imgur.com/OW0YQWa.png');
background-position: center;
background-size: cover;
max-height: 300px;
}
.h-bg:before {
content: "";
position: absolute;
top: 0;
right: 0;
left: 0;
height: 40px;
width: 100%;
display: block;
background-color: rgba(0, 0, 0, 0.5);
}
<div id="header">
<div class="h-bg">
</div>
</div>
If you need the dark transparent bar to be the navigation, you shouldn't use pseudo elements for it. Instead, a set of div elements is all you need.
#header {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
background-image: url('https://i.imgur.com/OW0YQWa.png');
background-position: center;
background-size: cover;
max-height: 300px;
}
.h-bg{
content: "";
position: absolute;
top: 0;
right: 0;
left: 0;
width: 100%;
display: block;
background-color: rgba(0, 0, 0, 0.5);
color: white;
}
.h-bg ul{list-style: none;}
.h-bg ul li{display: inline-block; padding: 0 10px;}
<div id="header">
<div class="h-bg">
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
Related
I'm creating a react-modal that animates in from the bottom of the screen. Once the modal is displayed, I need the modal to have a fixed/sticky footer that is fixed to the bottom of the browser window. For some reason, currently the footer is rendering off the screen using the standard:
position: absolute;
bottom: 0;
left: 0;
right: 0;
Please see the attached code.
.ReactModal__Overlay--after-open {
opacity: 1;
z-index: 99;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(46,46,51,.95);
}
.ReactModal__Content--after-open {
z-index: 100;
position: relative;
width: auto;
max-width: 500px;
margin: 0 auto;
bottom: 0%;
background-color: #FFF;
}
.wrapper {
background: yellow;
position: absolute;
bottom: 0;
left: 0;
right: 0;
top: 112px;
width: 480px;
max-width: 480px;
margin: 0 auto;
border-radius: 12px 12px 0 0;
height: 100vh;
background: white;
}
.contentBody {
background: pink;
}
.contentFooter {
background: orange;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
<div class="ReactModal__Overlay ReactModal__Overlay--after-open">
<div class="ReactModal__Content ReactModal__Content--after-open">
<div class="wrapper">
<div class="contentBody">BODY</div>
<div class="contentFooter">FOOTER</div>
</div>
</div>
</div>
What am I doing wrong which is preventing the footer within the modal from being fixed at the bottom of the screen?
Try this.
.ReactModal__Overlay--after-open {
opacity: 1;
z-index: 99;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(46,46,51,.95);
}
.ReactModal__Content--after-open {
z-index: 100;
position: fixed;
bottom: 0;
left: 0;
right: 0;
width: auto;
max-width: 500px;
margin: 0 auto;
bottom: 0%;
background-color: #FFF;
}
.wrapper {
background: yellow;
position: relative;
margin: 0 auto;
border-radius: 12px 12px 0 0;
height: calc(100vh - 115px);
background: white;
}
.contentBody {
background: pink;
position: absolute;
top: 0;
left: 0;
right: 0;
}
.contentFooter {
background: orange;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
<body>
<div class="ReactModal__Overlay ReactModal__Overlay--after-open">
<div class="ReactModal__Content ReactModal__Content--after-open">
<div class="wrapper">
<div class="contentBody">BODY</div>
<div class="contentFooter">FOOTER</div>
</div>
</div>
</div>
</body>
I want a div to be completely covered by another layer that looks like frosted glass. The div under the frosted glass will be the background for my responsive website. It can be gradient or just a picture like in my fiddle. I managed to cover the the div with the effect. However there is still a little gap between the edges of the layers but I want the effect to cover the entire div. Thanks.
.bg {
position: absolute;
background-image: url(https://images.unsplash.com/photo-1422224832140-0e546210efc3?dpr=1&auto=compress,format&fit=crop&w=1950&h=&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 500px;
margin: 0;
}
.blurred-box {
position: relative;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: inherit;
overflow: hidden;
}
.blurred-box:after {
content: '';
width: 100%;
height: 100%;
background: inherit;
position: absolute;
left: 0;
left position right: 0;
top: 0;
bottom: 0;
top position bottom: 0;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
}
<div class="bg">
<div class="blurred-box"></div>
</div>
One way to fix that is set :after to be bigger then container:
.bg {
position: absolute;
background-image: url(https://images.unsplash.com/photo-1422224832140-0e546210efc3?dpr=1&auto=compress,format&fit=crop&w=1950&h=&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 500px;
margin: 0;
}
.blurred-box {
position: relative;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: inherit;
overflow: hidden;
}
.blurred-box:after {
content: '';
width: 120%;
height: 120%;
background: inherit;
position: absolute;
left: -10%;
top: -10%;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
}
<div class="bg">
<div class="blurred-box"></div>
</div>
Also you could try to scale a little the blurred image container and hide the overflow on .bg:
.bg {
overflow: hidden;
}
.blurred-box:after {
transform: scale(1.08, 1.08);
}
and set padding: 0; margin: 0; on body to get rid of the small offsets. Some styles are redundant. So, my attempt:
body {
padding: 0;
margin: 0;
}
.bg {
position: relative;
background-image: url(https://images.unsplash.com/photo-1422224832140-0e546210efc3?dpr=1&auto=compress,format&fit=crop&w=1950&h=&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 500px;
overflow: hidden;
}
.blurred-box {
width: 100%;
height: 100%;
background: inherit;
}
.blurred-box:after {
content: '';
width: 100%;
height: 100%;
background: inherit;
position: absolute;
top: 0;
left: 0;
top: 0;
bottom: 0;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
transform: scale(1.08, 1.08);
}
<div class="bg">
<div class="blurred-box"></div>
</div>
i'm trying to have ornamented border all along the right and left side of the document, but for some reason I have not managed to get the elements with those border ornaments reach 100% height.
What i have right now is:
html {
height: 100%;
}
body {
min-height: 100%;
background-image: url("../img/bgtile.png");
background-repeat: repeat;
background-color: transparent;
font-size: 18px;
}
body:before {
content: "";
background: transparent url("../img/frame-ornament-left.png") repeat-y 11px 0px;
height: 100%;
width: 30px;
display: block;
left: 0;
position: absolute;
top: 0;
z-index: 0;
}
body:after {
content: "";
background: transparent url("../img/frame-ornament-right.png") repeat-y;
height: 100%;
width: 30px;
display: block;
right: 0;
position: absolute;
top: 0;
z-index: 0;
}
And no matther what i try, those before and after elements always stay as high as viewport is. I've tried setting min-height to 100% on HTML element too, that indeed made html element as long as body, but those elements with ornaments in them still remain as high as viewport...
Set the body to position: relative, so it will be the context for the pseudo elements, instead of the html, and set bottom: 0 to both pseudo elements:
body {
position: relative;
background-image: url('../img/bgtile.png');
background-repeat: repeat;
background-color: transparent;
}
.content-demo {
height: 800px;
}
body:before {
content: "";
background: red;
width: 30px;
display: block;
left: 0;
position: absolute;
top: 0;
bottom: 0;
z-index: 0;
}
body:after {
content: "";
background: blue;
width: 30px;
display: block;
right: 0;
position: absolute;
top: 0;
bottom: 0;
z-index: 0;
}
<div class="content-demo"></div>
I'm using the following HTML / CSS to overlay a box on a website i'm working on. I want the box to center in the screen, not start based on the centering already going on. So basically the white box should be on the center of the page, not the text test
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.loading:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.3);
}
.centrediv {
height: 200px;
width: 800px;
background-color: white;
border: 1px solid black;
}
<div class="loading"><div class="centrediv">Test</div></div>
Use transform: translate(-50%, -50%), top: 50% and left: 50% on .centreDiv to center it horizontally and vertically.
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: visible;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.loading:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
}
.centrediv {
position: absolute;
height: 100px;
width: 200px;
background-color: white;
border: 1px solid black;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
}
<div class="loading">
<div class="centrediv">Test</div>
</div>
Trying to create a contact form in an overlay. I have the overlay div working, but it only works if I set it to "position: absolute". The div inside of the overlay, will not position properly, regardless of what I try.
Need the "form-wrap to be centered vertically & horizontally.
<div id="overlay">
<div id="form-wrap">
<img id="close-btn" src="images/framework/close.png">
<form id="form-box">
<input name="first-name" id="first-name" type="text" maxlength="32">
</form>
</div>
</div>
#overlay{
top: 0;
left: 0;
height:100%;
width: 100%;
position: absolute;
z-index: 899;
display: none;
background-color: rgba(0, 0, 0, 0.41);
}
#form-wrap{
width: 400px;
height: 600px;
position: relative;
z-index: 900;
margin: 0;
background-color: white;
}
try this:
#overlay{
top: 0;
left: 0;
right: 0;
bottom: 0;
position: fixed;
z-index: 899;
display: none;
background-color: rgba(0, 0, 0, 0.41);
}
#form-wrap{
width: 400px;
height: 600px;
position: relative;
top: 50%;
left: 50%;
margin: -300px 0 0 -200px;
background-color: white;
}
Example
This will only work if the height of your overlay is greater than 600px!
#overlay{
top: 0;
left: 0;
height: 100%;
width: 100%;
position: absolute;
z-index: 899;
display: none;
background-color: rgba(0, 0, 0, 0.41);
}
#form-wrap{
width: 400px;
height: 600px;
top: 50%;
position: relative;
z-index: 900;
margin: -300px auto 0 auto;
background-color: white;
}
Example