All the other divs worked well but when i got to this point it does not want to center it for some reason? I'm i missing something?
Take a look at the image link. The menu items is what i want to set the auto margins to. The margin for the ehigh works but not the sides.
http://i.imgur.com/PckN9jX.jpg
.Menuitems {
position:absolute;
margin: 120px auto;
width:398px;
height:26px;
z-index:11;
border-style: solid;
}
#mitem1 {
position:absolute;
background-image:url(http://i.imgur.com/cyKwZQj.png);
background-repeat:no-repeat;
background-position:center;
top:0;
left:0;
width:75px;
height:26px;
z-index:6
}
#mitem1:hover {
background-image:url(http://i.imgur.com/BMHScgr.png);
background-repeat:no-repeat;
background-position:center
}
#mitem1:active {
background-image:url(http://i.imgur.com/4Y4sMtq.png);
background-repeat:no-repeat;
background-position:center
}
#mitem2 {
position:absolute;
background-image:url(http://i.imgur.com/GiAoMqC.png);
background-repeat:no-repeat;
background-position:center;
top:0;
left:77px;
width:75px;
height:26px;
z-index:7
}
#mitem2:hover {
background-image:url(http://i.imgur.com/XQKv9yC.png);
background-repeat:no-repeat;
background-position:center
}
#mitem2:active {
background-image:url(http://i.imgur.com/KQ07YMK.png);
background-repeat:no-repeat;
background-position:center
}
#mitem3 {
position:absolute;
background-image:url(http://i.imgur.com/UPERy0F.png);
background-repeat:no-repeat;
background-position:center;
top:0;
left:154px;
width:90px;
height:26px;
z-index:8
}
#mitem3:hover {
background-image:url(http://i.imgur.com/EqkUtsr.png);
background-repeat:no-repeat;
background-position:center
}
#mitem3:active {
background-image:url(http://i.imgur.com/k54mb7V.png);
background-repeat:no-repeat;
background-position:center
}
#mitem4 {
position:absolute;
background-image:url(http://i.imgur.com/QHExEjQ.png);
background-repeat:no-repeat;
background-position:center;
top:0;
left:246px;
width:75px;
height:26px;
z-index:8
}
#mitem4:hover {
background-image:url(http://i.imgur.com/BjKCQbw.png);
background-repeat:no-repeat;
background-position:center
}
#mitem4:active {
background-image:url(http://i.imgur.com/EVwDUoB.png);
background-repeat:no-repeat;
background-position:center
}
#mitem5 {
position:absolute;
background-image:url(http://i.imgur.com/oKrhDAE.png);
background-repeat:no-repeat;
background-position:center;
top:0;
left:323px;
width:75px;
height:26px;
z-index:8
}
#mitem5:hover {
background-image:url(http://i.imgur.com/gnLuhed.png);
background-repeat:no-repeat;
background-position:center
}
#mitem5:active {
background-image:url(http://i.imgur.com/iqFh66v.png);
background-repeat:no-repeat;
background-position:center
}
#menuline {
position:absolute;
background-image:url(http://i.imgur.com/4xOPK1I.png);
background-repeat:no-repeat;
background-position:center;
left:75px;
top:0;
width:2px;
height:26px
}
#menuline2 {
position:absolute;
background-image:url(http://i.imgur.com/4xOPK1I.png);
background-repeat:no-repeat;
background-position:center;
left:152px;
top:0;
width:2px;
height:26px
}
#menuline3 {
position:absolute;
background-image:url(http://i.imgur.com/4xOPK1I.png);
background-repeat:no-repeat;
background-position:center;
left:244px;
top:0;
width:2px;
height:26px
}
#menuline4 {
position:absolute;
background-image:url(http://i.imgur.com/4xOPK1I.png);
background-repeat:no-repeat;
background-position:center;
left:321px;
top:0;
width:2px;
height:26px
}
<div class="topbox">
<!-- Menu Items -->
<div class="Menuitems">
<a href="#">
<div id="mitem1"></div></a> <a href="shows.html">
<div id="mitem2"></div></a> <a href="codes.html">
<div id="mitem3"></div></a> <a href="about.html">
<div id="mitem4"></div></a> <a href="contact.html">
<div id="mitem5"></div></a>
<div id="menuline"></div>
<div id="menuline2"></div>
<div id="menuline3"></div>
<div id="menuline4"></div>
</div>
<a href="#">
<div class="divlogo"></div>
</a>
</div>
The absolute positioning takes it out of the flow of the page and causes the centering from the auto margins not to work.
.topbox {
position:absolute;
width:100%;
z-index:11;
}
.Menuitems {
margin: 120px auto;
width:398px;
height:26px;
border-style: solid;
}
Will get the menu div positioned correctly. Get rid of all the absolute position on your menu items.
I made this Plunker it might be what you're looking for. http://plnkr.co/edit/wcRaJqvg0fsPT9HcBynf?p=preview
Block level elements are greedy. They use margins to take up the entire horizontal space they're in so that nothing is inline with them. If you set auto on both left and right then both sides want all the space, so they share - resulting in a centred object.
If you use position:absolute or fixed on a block level element it removes this greedy behaviour from the element.
Change the position of .Menuitems to relative and that should fix the issue.
Related
Similair question can be found here:
CSS: How to fit an image in a circle where bottom is clipped but top pops out?
However, I would like to have the red outline replaced by an image, e.g.:
I tried among others :before and :after psuedo tags but did not find the soluition. Which direction I should look to achieve this?
You can use multiple background like this:
.box {
width:200px;
height:210px;
border-radius: 0 0 50% 50%/0 0 70% 70%;
background:
url(https://i.stack.imgur.com/bdZeE.png) center/cover,
url(https://i.stack.imgur.com/i7iHM.png) 0 180%/100% auto no-repeat;
position:relative;
}
.box:after {
content:"";
position:absolute;
z-index:1;
bottom:0;
top:50%;
left:0;
right:0;
background:url(https://i.stack.imgur.com/i7iHM.png) 0 90%/100% auto no-repeat;
}
<div class="box">
</div>
You can also control the image inside using CSS variable:
.box {
width:200px;
height:210px;
border-radius: 0 0 50% 50%/0 0 70% 70%;
background:
var(--image) center/cover,
url(https://i.stack.imgur.com/i7iHM.png) 0 180%/100% auto no-repeat;
position:relative;
display:inline-block;
}
.box:after {
content:"";
position:absolute;
z-index:1;
bottom:0;
top:50%;
left:0;
right:0;
background:url(https://i.stack.imgur.com/i7iHM.png) 0 90%/100% auto no-repeat;
}
<div class="box" style="--image:url(https://i.stack.imgur.com/bdZeE.png)">
</div>
<div class="box" style="--image:url(https://i.stack.imgur.com/7A8fP.png)">
</div>
having a problem here. I have a got my skewed div perfect but now I want the image to fit in it without tiling so if anyone can help that would be awesome.
I'm going for this:
And so far I have this:
HTML
<div class="box"></div>
CSS
.box {
position:relative;
width:100%;
height:500px;
background: url(../images/clouds.jpeg);
background-size:contain;
padding:10px;
margin-bottom:100px;
}
.box:after {
position:absolute;
content:'';
width:100%;
height:100%;
top:0;
left:0;
right:0;
background:inherit;
background-size:contain;
transform-origin: top left;
transform:skewY(10deg);
z-index: -1;
}
You should use background-size: cover if you want the img to fill the entire container, and then use background-repeat: no-repeatto have one image.
Something like that should work:
.box {
position:relative;
width:100%;
height:500px;
background: url(../images/clouds.jpeg);
background-size:cover;
background-repeat: no-repeat;
padding:10px;
margin-bottom:100px;
}
That image is not skewed..
div{
display:inline-block;
margin:10px;
postion:relative;
width:100px;
height:100px;
background:cyan;
}
div.covered{
background:
linear-gradient(20deg,white,white,40px,transparent 40px,transparent),cyan;
}
<div>
normal
</div>
<div class="covered">
covered
</div>
Bottom-left part can be done by covering image with white color with tilted linear gradient.
I am trying to center a div inside another div.
I have tried the following HTML and CSS
HTML
<div class="header">
<div class="homeImageText">
<h1>Document Preparation Like Never Before</h1>
</div><!--homeImagetext end-->
</div>
CSS
.homeImageText {
left:0; right:0;
top:0; bottom:0;
margin:auto;
max-width:100%;
max-height:100%;
}
header{
background: url(../images/header1.png) center center no-repeat; ;
height: 600px;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Live
jsfiddle
Demo Fiddle
For vertical centering, make the wrapping div set to display-table and the child to display:table-cell with vertical-align:middle. Horizontal centering can then simply be accomplished with text-align:center;
Try the CSS:
.header {
height: 600px;
display:table;
width:100%;
}
.homeImageText {
height:100%;
display:table-cell;
vertical-align:middle;
text-align:center;
}
This might be the dumbest question, but Im building a single page website, where you have to scroll down to get to the "next page".. It has one background in a fixed position div and so far Ive only implemented css and html. Havent even started the real work.. Just sort of testing the design.. how I'd like to have things.
It works just fin under Chrome and Firefox, but almost dies on Safari.
I wonder if its just my mac or theres something to the way I do things. Safari does not like overlaying divs, or what?! :(
HTML
<div id="background"></div>
<div id="container">
<div id="header">Page title</div>
<!--menu comes here later on-->
<div id="content">CONTENT</div>
</div>
CSS
#background {
position:fixed;
top:0px; left:0px;
width:100%; height:100%;
background:url(bg.jpg) no-repeat center center fixed;
-webkit-background-size:cover; -moz-background-size:cover; -o-background-size:cover; background-size:cover;
}
#container {
position:absolute;
top:0px; left:0px;
width:100%; height:100%;
}
#header {
position:absolute;
top:2%; left:7%;
font-family:"Times New Roman";
font-size:50px;
color:#ffffff;
}
#content {
position:absolute;
top:100%;
width:100%; height:1000px;
background:#ffffff;
box-shadow:0px -3px 25px #252525;
}
Any ideas?!
Thanks!
Ok I have a background that has a clear area that I have balanced content inside and I want it to slide under the top of the image when the user scrolls it up. I have a jsfiddle with it, excuse my sloppy css I have been trying everything to get this to work. I also have a floating nav bar that it should slide under also.
http://jsfiddle.net/CFFwA/
#charset "UTF-8";
/* CSS Document */
html,body {
height:100%;
width:100%;
}
body{
background-image:url(images/1920w.png);
background-size:100%;
background-position:center;
background-attachment:fixed;
background-repeat:no-repeat;
background-color:#E9C9A0;
z-index:5;
}
#bod{
width:100%;
height:100%;
background-image:url(images/1920w.png);
background-size:100%;
background-position:center;
background-attachment:fixed;
background-repeat:no-repeat;
left:0;
z-index:20;
}
#bann{
width:62.5%;
height:100%;
z-index:10;
}
#head{
position:fixed;
margin-top:8.5%;
margin-right:18.75%;
margin-left:18.75%;
width:62.5%;
height:100%;
z-index:32;
}
#content{
padding-top:14%;
width:62.5%%;
height:100%;
margin-left:auto;
margin-right:auto;
z-index:4;
}
An easy fix would be to make your image a separate element with position:fixed
HTML
<img src="/path/to/bg.png" id="body-bg" />
CSS
#body-bg {
width: 100%;
position: fixed;
top: 0;
}
Check the fiddle