I'm trying to center my div .down-arrow horizontally but without success. The DIV is absolute positioned but margin:0px auto; does not seem to be working. What is the issue? thanks
http://jsfiddle.net/7UNrP/
HTML:
<header>
<div class="down-arrow">arrow</div>
</header>
CSS:
header {
position: relative;
width: 100%;
height: 600px;
min-height: 300px;
margin-right: auto;
margin-left: auto;
background-image: url('http://lorempixel.com/output/nature-q-c-1020-711-1.jpg');
background-size: cover;
background-position: center center;
background-color: rgb(222, 222, 222);
}
.down-arrow {
position: absolute;
margin:0px auto;
bottom: 20px;
display: inline;
padding: 10px;
color: #FFF;
border: 0;
font-weight: 400;
font-size: 12px;
background: red;
-webkit-animation: icon 1.2s infinite;
}
#-webkit-keyframes icon {
from {
opacity: 1;
bottom: 20px;
}
to {
opacity: 0;
bottom: 10px;
}
}
The problem is that you haven't told the arrow div where to be except bottom:20px so it defaults to left:0;
JSfiddle Demo
You need to add this to your arrow CSS
left:50%; /*push the div halfway over*/
-webkit-transform:translateX(-50%); /* bring it back by half its own width */
transform:translateX(-50%);
You might want to refer to this post which had much the same issue. I go into further detail regarding this solution.
Reference Question
The issue is due to using margin:0 auto with the display:inline and position: absolute. You can easily center it by applying text-align:center to the header as your inner content has an inline layout.
Example
You could use
text-align:center;
in header css like this
header {
position: relative;
width: 100%;
height: 600px;
min-height: 300px;
margin-right: auto;
margin-left: auto;
background-image: url('http://lorempixel.com/output/nature-q-c-1020-711-1.jpg');
background-size: cover;
background-position: center center;
background-color: rgb(222, 222, 222);
text-align: center;
}
EDIT:
This aligns the .down-arrow div in the center horizontally and keep it 20 pixel away from the bottom side of the its container
.down-arrow {
position: absolute;
margin-left: 50%;
/* bottom: 20px; */
/* display: inline; */
padding: 10px;
color: #FFF;
border: 0;
font-weight: 400;
font-size: 12px;
background: red;
-webkit-animation: icon 1.2s infinite;
}
Related
I'm learning from a project which uses cards with border-radius 50px. However, on wider screen, the border is not working. It's a quite simple code, bud I don't understand why this is happening
Can you help me?
<div class="panel panel1" style="background-image: url('https://images.unsplash.com/photo-1448375240586-882707db888b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8Zm9yZXN0fGVufDB8fDB8fA%3D%3D&w=1000&q=80')">
<h3>Explore the world</h3>
</div>
body {
font-family: 'Muli', sans-serif;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
.container {
display: flex;
width: 90vw;
overflow: hidden;
}
.panel {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: white;
cursor: pointer;
flex: 0.2;
margin: 15px;
position: relative;
transition: flex 0.7s ease-in;
overflow: hidden;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 60px;
left: 200px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 2;
overflow: hidden;
}
Border radius not working
looking at the print screen it looks like the border radius is working, but the div is being cut, maybe you can solve this by adding a width to the panel
I have tried to build a login form on a HTML page (Angular) that has a full size, centered background image and the form is placed in a div with blurred background, that is centered in the x- and y-axis of the browser window.
That is how far I came: https://codepen.io/surfermicha/pen/ZwpxBa
<div class="login-background-door2">
<div class="aero-background centered">
<h3>Here will be a login form later</h3>
</div>
</div>
Unfortunately i have some issues with that:
The centered box isn't exactly in the center
It's not responsive. The div is to small at small devices. I want 10px margin left and right, but a max-width 500px on bigger screens.
Could anyone help edit the codepen for a working responsive solution
You can set media queries by your needs, like I set into 567px because after 567px view of your center block, don't look nice so I set into 567px.
body, html {
font-family: "roboto", monospace;
color: #EEE;
padding: 0;
width: 100%;
margin: 0;
height: 100%;
overflow-x: hidden;
}
.aero-background::before {
content: '';
background: url("http://placekitten.com/2400/2000") center no-repeat;
filter: blur(6px);
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: -1;
pointer-events: none;
}
.aero-background {
border-radius: 5px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.1);
color: white;
align-items: center;
justify-content: center;
text-shadow: 0 0 10px black;
}
.centered {
max-width: 500px;
min-height: 300px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.login-background-door2 {
background: url("http://placekitten.com/2400/2000") center no-repeat;
height: 100%;
width: 100%;
overflow: hidden;
}
#media screen and (max-width: 567px) {
.centered {
width: 250px;
}
}
<div class="login-background-door2">
<div class="aero-background centered">
<h3>Here will be a login form later</h3>
</div>
</div>
https://codepen.io/anon/pen/MLjXgW
Centered with flex, no media queries
body, html {
font-family: "roboto", monospace;
color: #EEE;
padding: 0;
width: 100vw;
margin: 0;
height: 100vh;
overflow-x: hidden;
}
$login-background-image: "http://placekitten.com/2400/2000";
.aero-background::before{
content: '';
background: url($login-background-image) center no-repeat;
filter: blur(6px);
position: absolute;
left:0; top:0; right:0; bottom:0;
z-index: -1;
pointer-events: none;
}
.aero-background {
border-radius:5px;
box-shadow: 0 0 15px rgba(black, .4);
border:1px solid rgba(white,.1);
color: white;
align-items: center;
justify-content: center;
text-shadow:0 0 10px black;
max-width:500px;
min-height: 300px;
margin-left: 10px;
margin-right: 10px;
display: flex;
text-align: center;
padding: 10px;
}
.login-background-door2 {
background: url($login-background-image) center no-repeat;
height: 100%;
width: 100%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
<div class="login-background-door2">
<div class="aero-background">
<h3>Here will be a login form later</h3>
</div>
</div>
My first time answering so I apologize if missed something
How to let the center div in the mask div align center?
the styles:
<style type="text/css">
.mask {
position: absolute; top: 0px;
filter: alpha(opacity=60);
background-color: #777;
z-index: 1002; left: 0px;
opacity:0.5; -moz-opacity:0.5;
width: 100%;
height: 100%;
}
.center {
margin-left: auto;
margin-right: auto;
}
</style>
the html:
<div id="mask" class="mask">
<div class="center">MASC</div>
</div>
How to let the center div in the mask div align center?
I created a shade layer, and in it there is a div, I want the div align center, but my style code seems not work.
Let you try set position property with the fixed value.
.mask {
position: absolute; top: 0px;
filter: alpha(opacity=60);
background-color: #777;
z-index: 1002; left: 0px;
opacity:0.5; -moz-opacity:0.5;
width: 100%;
height: 100%;
}
.center {
position: fixed;
top: 50%;
left: 50%;
}
Add style text-align: center to your center div.
<style type="text/css">.mask {
position: absolute;
top: 0px;
filter: alpha(opacity=60);
background-color: #777;
z-index: 1002;
left: 0px;
opacity: 0.5;
-moz-opacity: 0.5;
width: 100%;
height: 100%;
}
.center {
text-align: center;
}
</style>
Yeah, You should specify the width of the .center div.
.center {
margin-left: auto;
margin-right: auto;
width: 100px;
}
To center the text you can align center
.center {
text-align:center;
}
There are two good choices here:
1.Use table layout
.mask{
display:table;
}
.center{
display:table-cell;
}
2.Use Flex layout
.mask{
display:flex;
flex-direction:row;
align-items:center;
justify-content:center;
}
I have an image that has a width of 50% and a div with text that is 65% because I want the heading inside the div to overlap the image. But, the problem is that I don't want the other content inside the div to overlap the image - just the heading. I want the text and the button to be next to the image not on top of it.
But I can't seem to figure it out.
Here's a Codepen: https://codepen.io/tayanderson/pen/EbJZxy
.project {
height: 75vh;
margin: 15em 0;
position: relative;
.project-info {
z-index: 100;
display: flex;
flex-direction: column;
justify-content: center;
position: absolute;
width: 65%;
height: 100%;
right: 0;
h2 {
text-transform: initial;
color: #eee;
}
p {
font-weight: 300;
color: #ccc;
margin: 40px 0;
}
.project-desc {
width: 70%;
.button {display:inline-block;}
}
}
.project-img {
background-size: cover;
background-position: center;
height: 100%;
-webkit-filter: grayscale(100%) brightness(50%);
filter: grayscale(100%) brightness(50%);
width: 51.3%;
}
a {text-decoration:none;
color: #fff;}
#media only screen and (max-width: 768px) {
.project-info, .project-img {
width: 100%;
}
.project-info {
left: 0;
padding: 0 20px;
.project-desc>*{
width: 100% !important;
float: left !important;
}
p {display: none;}
}
}
}
You can try something like that using flexbox.
https://codepen.io/dakata911/pen/BmEpeB
.article {
width: 60%;
margin: 0 auto;
display: flex;
}
.article__image,
.article__text {
width: 50%;
}
.article__image {
background: url('http://www.country1067.com/wp-content/uploads/sites/28/2017/07/logoImage_4.jpg') center center no-repeat;
background-size: cover
}
.article__text {
padding: 12px;
background: #c3c3c3;
}
.article__text h2 {
margin-left: -96px;
color: #FFF;
font-size: 40px;
}
why donĀ“t you make the two divs to 50% and give padding to project-info?
You need this attribute for do correctly the padding inside the div
*{
box-sizing:border-box;
}
Here you have the result
https://codepen.io/marcosefrem/pen/BmERmY
I think I understand what you are describing. Instead of using the percentages to position the items use position: relative instead and float the image (remember to put it first in the flow).
Check this out:
https://codepen.io/alexplummer/pen/eeoRmN
.project-info {
display: inline-block;
width: calc(50% - 10px);
height: 100%;
padding-left: 10px;
...
}
.project-img {
width: 50%;
float: left;
...
}
I am trying to put a background image in a content div and make only the image blur but failed so far. I managed to get the background-image to show up when the code for the image is in the content div itself (code below). In other words without making an additional div for the image. But in this case the whole content obviously becomes blur if, for example, I put filter: blur(...);
The second method was to make a background-image div. But I managed either to push the content right under the image or put the image somewhere behind the content so It's not visible.
How would you propose to do a background-image and fix my issue? My codepen - http://codepen.io/anon/pen/hGBjA
CSS
h2 {
font-family: Open Sans;
color: #0099F1;
padding-left: 20px;
text-align: left;
}
#bizpartners ul {
list-style-image: url ("http://www.peopletraining.co.uk/people_training_april_2012002002.jpg");
}
.right {
position: relative;
float: left;
margin-top: 50px;
width: 100%;
min-height: 400px;
max-height: auto;
z-index: 5;
margin-bottom: 5px;
background: rgba (255, 255, 255, 0.3);
border: 1px solid #000000;
background-image: url("http://www.worldswallpapers.org/wp-content/uploads/2014/02/Nature-Wallpapers-2014-2.jpg");
background-size: cover;
filter: blur(5px);
-webkit-filter: blur(5px);
background-repeat: no-repeat;
}
.right p {
margin-left: 30px;
margin-top: 20px;
text-align: center;
}
I made it really quick, i hope it's ok!
FIDDLE: http://jsfiddle.net/81yawoxg/
HTML
<div class="container">
<div class="background"></div>
<div class="text">CONTENT HERE</div>
CSS
.container{
position: relative;
width: 1280px;
height: 700px;
}
.background{
position: absolute;
top: 0;
left: 0;
width: inherit;
height: inherit;
z-index: 100;
background-image: url("http://www.worldswallpapers.org/wp-content/uploads/2014/02/Nature-Wallpapers-2014-2.jpg");
filter: blur(5px);
-webkit-filter: blur(5px);
background-repeat: no-repeat;
}
.text{
position: absolute;
top: 0;
left: 0;
width: inherit;
height: inherit;
z-index: 200;
padding: 20px;
}