I know there are a lot of div centering questions but most only revolve that div and not surrounding divs...
I have 4 divs equal of width and height.
On top of that, I would like to have another div but centered (vertical & horizontal) above those 4.
I came this far:
<div class="content">
<div class="logoWrapper"></div>
<div class="topleft" id="wrapper"></div>
<div class="topright" id="wrapper"></div>
<div class="bottomleft" id="wrapper"></div>
<div class="bottomright" id="wrapper"></div>
</div>
.logoWrapper {
width:270px;
height:150px;
position:absolute;
left:50%;
top:50%;
margin:-75px 0 0 -135px;
}
#wrapper {
width: 49%;
height: 49%;
float: left;
background-color: #79be53;
border-color: white;
border-radius: 1%;
border-style: solid;
}
For some reason I dont understand yet this does not center the div...its a bit to the right of my screen! Or am I going crazy...?!
Do you want something like this
Then do this change position to relative and adjust margin accordingly
.logoWrapper {
width: 270px;
height: 150px;
position: relative;
left: 50%;
top: 50%;
margin: 0px 0 0 -135px;
background: #FF0004;
}
As mentioned by #billy id needs to be unique
so change your code in to this
<div class="content">
<div class="logoWrapper"></div>
<div class="topleft" id="wrapper1"></div>
<div class="topright" id="wrapper2"></div>
<div class="bottomleft" id="wrapper3"></div>
<div class="bottomright" id="wrapper4"></div>
</div>
and css to this
#wrapper1,#wrapper2,#wrapper3,#wrapper4 {
}
If you want your div like this
Then just add background color to .logoWrapper(Its transparent by default) its already in center. If its not in center for you just add unique id to those div's that might be causing issue
The easiest way to center div will be
.logoWrapper {
position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
}
No need to adjust margin this property is enough to center div.
Are you looking for something like this? https://jsfiddle.net/81cLt6t6/
This is how I centered the box
.logoWrapper {
width:270px;
background-color: red;
height:150px;
position:absolute;
left: calc(50% - 135px);
top: calc(52% - 75px);
/*margin:-75px 0 0 -135px;*/
z-index: 9999;
}
IDs are unique, so don't repeat them.
I'm not quiet sure what you are trying to achieve, but here is a snippet using calc
.content {
position: relative
}
.logoWrapper {
width: 270px;
height: 150px;
position: absolute;
left: calc(50% - 135px);
top: calc(50% + 135px);
background: blue
}
.wrapper {
width: 49%;
height: 49%;
min-height: 200px;
float: left;
background-color: #79be53;
border-color: white;
border-radius: 1%;
border-style: solid;
}
<div class="content">
<div class="logoWrapper"></div>
<div class="topleftt wrapper"></div>
<div class="topright wrapper"></div>
<div class="bottomleft wrapper"></div>
<div class="bottomright wrapper"></div>
</div>
Related
How do I place an image on top of a button with html and css?
<div>
<img src="photo.jpg">
<button>Text</button>
</div>
I guess it should be something like
div {
position: relative;
}
img {
position: absolute;
top: 10px;
}
but it acts a bit weird.
Is it possible to just have a normal div and then set the img to float on top of everything else in the div element?
I don't know what's your purpose exactly, if you want the image to take the whole line, make the button lay beneath, why don't set the CSS display attribute of the image to display:block;?
hello see the below one its simple with a few line code
<div style="position:relative;" >
<img src="http://www.industrydynamics.ca/images/skype_icon.png" width="100" height="100" >
<input type="button" name="" value="Button" style="position:absolute;width:80px;left:10px;top:120px;" >
</div>
You can use position: absolute with transform: translate() on img.
This calc(-100% - 1px) means
-100% or - height of element (img in this case) that you are performing transform on, so it will translate for its own height up on Y axis
-1px is for top border on div element.
div {
position: relative;
display: inline-block;
border: 1px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 1px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
Just to demonstrate if you have border of 5px then you should use -5px in calc.
div {
position: relative;
display: inline-block;
border: 5px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 5px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
#bottom{
background-repeat: repeat-x;
height:121px;
width: 984px;
margin-left: 20px;
margin-top: 13px;
}
#bottom .content{
width: 182px; /*328 co je 1/3 - 20margin left*/
height: 121px;
line-height: 20px;
margin-top: 0px;
margin-left: 9px;
margin-right:0px;
display:inline-block;
position:relative;
}
<div id="bottom">
<div class="content">
<img src="http://placehold.it/182x121"/>
<button>Text</button>
</div>
</div>
May be you are trying to achieve something like this.
.userIcon {
background: url('https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png') no-repeat;
height:20px;
width:20px;
background-size:20px;
top: 8px;
}
.left {
float:left;
}
.right {
float:right;
}
.clear{
clear:both;
}
.button{
padding:10px;
color: #FFF;
background-color: #0095ff;
border:1px solid #07c;
box-shadow: inset 0 1px 0 #66bfff;
}
.btnText{
margin:2px 0px 0px 10px;
}
<div>
<button class="button">
<span class="left userIcon"></span>
<span class="right btnText">Create user account</span>
<span class="clear"></span>
</button>
</div>
If you just want to make the image to come over the button, you can make the display as block
check the following snippet
div img{
display:block;
}
button{
text-align:center;
margin:40px;
padding:10px;
}
<div>
<img src="https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png">
<button>Text</button>
</div>
Hope this helps
I'm trying to create a vertically aligned image, but also have it float left with a 10px padding.
Here is what I have so far:
<div class="container">
<div class="header">
<div class="headliner"><strong>blaw</strong>
<br />blah</div>
<div class="header_eta"></div>
</div>
<div class="content">
<div class="dummy"></div>
<div class="img-container">
<img src="http://placehold.it/75x75" alt="" />
</div>
</div>
<div class="footers"></div>
</div>
You can also check out this fiddle.
I can't seem to get the img to float: left. It seems to be centered horizontally. Once the I get the image floated left, I need to float some text to the left side of the image.
UPDATE: Something like this https://cdn.shopify.com/s/files/1/0070/7032/files/UberRUSH_Tracking_Page-5_1.png?5766570299208136168
Add text-align:left into img-container with padding-left:10px;
Like this:
.img-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align:left; /* Align center inline elements */
font: 0/0 a;
padding-left:10px
}
try float:lefton the image, then add a div into img-container also floated left with a suitable margin
<div class="img-container">
<img src="http://placehold.it/75x75" alt="" style="float:left;"/>
<div style="float:left;margin-left:10px;">Your Content</div>
</div>
In order to achieve your desired result, you can use the following CSS code:
/* Positioning */
position: absolute;
top: 50%;
left: 0;
transform: translate(0, -50%);
Setting top: 50% and transform: translate(..., -50%) will center your element vertically.
Setting left: 0 and transform: translate(0, ...) will float your element horizontally to the left.
For optical reference you can check my code work in this fiddle.
<div class="container">
<div class="header">
<div class="headliner"><strong>blaw</strong>
<br />blah</div>
<div class="header_eta"></div>
</div>
<div class="content">
<div class="img-container-2">
<div class="img-cell">
<img src="http://placehold.it/75x75" alt="" />
</div>
</div>
</div>
<div class="footer"> </div>
</div>
<style type="text/css">
.content {height:300px; background-color:rgb(239, 65, 59);}
.header {height:60px; background-color:rgb(55, 102, 199);}
.img-container-2 {display:table; height:100%; width:100%; text-align:left;}
.img-cell {display:table-cell; vertical-align:middle;}
.headliner {padding:10px; height:50px;}
.footer {height:40px; background-color:rgb(66, 199, 123);}
</style>
img-container text align to left;
text-align: left;
here you code
.img-container {
position: absolute;
top: 10px;
bottom: 0;
left: 10px;
right: 0;
text-align: left;
/* Align center inline elements */
font: 0/0 a;
}
Once the I get the image floated left I need to float some text to the left side of the image.
So you will need to align two divs horrizontaly. For this you will need to use display: inline-block for both of them. By using this approach, you will need to put the image inside a div, and the text inside another div.
You could also make a table with the first td containing the text and the second td containing the image. Then float table to left.
Do you need like this,
Html code:
<div class="container">
<div class="header">
<div class="headliner"><strong>" blaw "</strong><br />" IS EN ROUTE "</div>
<div class="header_eta"></div>
</div>
<div class="content">
<div class="dummy"></div>
<div class="img-container">
<img src="http://placehold.it/75x75" alt="" />
</div>
</div>
<div class="footer">sdfsd</div>
</div>
css:
.content {
height: 100px;
position: relative;
width: 100%;
border: 1px solid black;
background-color: rgb(239, 65, 59);
}
.header {
height: 60px;
background-color: rgb(55, 102, 199);
}
.dummy {
padding-top: 100%; /* forces 1:1 aspect ratio */
}
.img-container {
position: absolute;
top: 10px;
bottom: 0;
left: 10px;
right: 0;
text-align: left;
}
.img-container:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.img-container img {
vertical-align: middle;
display: inline-block;
}
.headliner {
padding:10px;
height:50px;
}
.footer {
height: 40px;
padding-bottom: 0px;
padding-left: 5px;
padding-top: 5px;
background-color: rgb(66, 199, 123);
text-align: left;
}
you can refer a link:https://jsfiddle.net/vpbu7vxu/5/
I am trying to create a div with a background image (background-size:cover) with this shape cut out in the center top of the div.
The div above the div I want to cut this shape out of has background-image:cover on it as well. I'm trying to do this with a CSS shape, moving the lower div up using a negative margin top, so the background image on the div above shows through the cut out shape.
Note: The shape has to look identical or almost identical to the image, as it is part of a site designed by someone else, and they are very specific with their designs.
Anyone out there know how to create this shape?
EDIT: #SZenC offered a really cool solution that I implemented, except it leaves me with colored shapes overlayed on top of background images. See image:
I need the light blue pattern to show through where the gray is, and the purple texture to show through where the white is. I'm not sure at this point if this is possible, at least with CSS.
The best solution using CSS would be to use some nested elements.
You could create a div (.pointy) with two other divs inside it (.curve-left & .curve-right).
The inner divs should be sided so that they each have half of the curve. So if your curve drops 10px and goes 20px horizontal, it's height should be 10px and the width 20px. Then give it a border radius in the top-left or top-right corner of 100%. Now the curve will go trough the entire div. You could then give it a gray background-color and the parent div white in the background. Then some simple CSS-tricks to center the .pointy-div and do the backgrounds, and voila, there is your curvy triangle-y thingy.
So example below.
#c1 {
position: relative;
width: 200px;
height: 190px;
overflow: hidden;
}
#c2 {
position: relative;
top: 0px;
width: 200px;
height: 200px;
background-color: gray;
}
.pointy {
position: absolute;
top: 0px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 10px;
background-image: url("http://lorempixel.com/output/technics-q-c-200-200-4.jpg");
background-position:center bottom;
}
.pointy>.curve-left,
.pointy>.curve-right{
position:absolute;
background-color:red;
width:20px;
height:10px;
background-image:url("http://lorempixel.com/output/technics-q-c-200-200-1.jpg");
}
.pointy>.curve-left{
border-top-right-radius:100%;
background-position:120px 0;
left:0;
}
.pointy>.curve-right{
border-top-left-radius:100%;
background-position:80px 0;
right:0;
}
<div id="c1">
<img src="http://lorempixel.com/output/technics-q-c-200-200-4.jpg" />
</div>
<div id="c2">
<div class="pointy">
<div class="curve-left"></div>
<div class="curve-right"></div>
</div>
<img src="http://lorempixel.com/output/technics-q-c-200-200-1.jpg" />
</div>
Here you could use a couple of pseudo elements with border radius to create that curved shape.
note there are multiple elements in this demo to show how this could be used in practice
.image {
height: 300px;
width: 80%;
background: url(http://lorempixel.com/900/500);
position: relative;
display: inline-block;
}
.shape {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: url(http://lorempixel.com/900/400);
background-position: 0 60px;
}
.shape:before,
.shape:after {
content: "";
position: absolute;
background: inherit;
height: 100%;
top: 0;
width: 50%;
transform: translateY(-100%);
}
.shape:before {
left: 0;
border-radius: 0 50% 0 0;
background-position: 0 90px;
}
.shape:after {
left: 50%;
border-radius: 50% 0 0 0;
background-position: -100% 90px;
}
<div class="image">
<div class="shape"></div>
</div>
Another, more in practical approach (with responsiveness), would be something like:
.wrap{
width:100%;display:inline-block;
position:relative;
height:600px;
}
.wrap img:first-child{
top:0;z-index:5;
}
.wrap img:last-child{
top:40%;
}
.wrap img{
position:absolute;
height:50%;width:100%;
}
.wrap .splitter{
z-index:10;
position:absolute;
top:40%; width:100%;
height:10%;
}
.wrap .splitter:before, .wrap .splitter:after{
content:"";
position:absolute;
width:50%;
height:100%;
background-size:200% 500%;
border-radius: 0 100% 0 0;
}
.wrap .splitter:after{
left:50%;
background-position:-100% 0;
border-radius: 100% 0 0 0;
}
.wrap .partA:before, .wrap .partA:after{ background-image:url("http://lorempixel.com/450/250");}
<div class="wrap">
<img src="http://lorempixel.com/900/500"/>
<span class="splitter partA"></span>
<img src="http://lorempixel.com/450/250"/>
</div>
How do I position 2 divs that overlap plus a third div just to the right of those overlapping divs (but the third not floated all the way right)?
<div id=one>I overlap id=two.</div>
<div id=two>I overlap id=one.</div>
<div id=three>I am just to the right of one and two.</div>
The desired layout is:
| one-overlaps-two | three |
http://i.imgur.com/4CMNaUh.png
I know I can overlap the first 2 divs using a wrapper div that's position:relative and setting divs one & two to position:absolute
<div id="wrapper">
<div id=one>I overlap id=two.</div>
<div id=two>I overlap id=one.</div>
</div>
#wrapper{position:relative;}
#one,#two{position:absolute;}
But how can I get div id=three just to the right of overlapping divs one & two?
What I've got so far: http://jsfiddle.net/justAsking/cXrBA/
A solution can be as follows:
http://jsfiddle.net/cXrBA/2/
HTML
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
CSS
.wrapper {
padding-left: 100px;
width: 100px;
height: 100px;
position: relative;
}
.one , .two {
width: 100px;
position: absolute;
left: 0;
}
.one {
background-color: blue;
height: 50px;
top: 0;
z-index: 1;
}
.two {
background-color: red;
height: 100px;
top: 0;
}
.three {
background-color: green;
width: 100px;
height: 100px;
}
Give the second div a negative margin-left;
http://jsfiddle.net/HXH76/
div {
display: inline-block;
}
#one {
background: hsla(0,100%, 50%, 0.50);
}
#two {
background: hsla(90,100%, 50%, 0.50);
margin-left: -40px;
}
#three {
background: hsla(180,100%, 50%, 0.50);
}
I have a selection of squares (squares turned 45° to look like diamonds) which I want to use to make up a big diamond shape with a central red diamond.
I am having issues organising the diamonds themselves and the href seems to fail.
How do I position the responsive diamonds in a regular grid?
Her is my code:
body {
background: black;
color: #000000;
font: 13px georgia, serif;
line-height: 1.4;
font-weight: lighter;
text-rendering: optimizelegibility;
}
#diamond {
width: 0;
height: 0;
border: 50px solid transparent;
border-bottom-color: white;
position: relative;
top: -50px;
}
#diamond:after {
content: '';
position: absolute;
left: -50px;
top: 50px;
width: 0;
height: 0;
border: 50px solid transparent;
border-top-color: white;
}
#diamond_red {
width: 0;
height: 0;
border: 50px solid transparent;
border-bottom-color: #AA1C08;
position: relative;
top: -50px;
}
#diamond_red:after {
content: '';
position: absolute;
left: -50px;
top: 50px;
width: 0;
height: 0;
border: 50px solid transparent;
border-top-color: #AA1C08;
}
<a class="navigation">
<center>
<div id="diamond"></div>
<div id="diamond"></div>
<div id="diamond" href="/photos/"></div>
<div id="diamond_red"></div>
<div id="diamond" href="/projects/"></div>
<div id="diamond"></div>
<div id="diamond"></div>
<div id="diamond" href="/archive/"></div>
</center>
</a>
The responsive grid of diamons:
I don't think you have the right aproach to achieve a regular responsive diamond grid layout. It would be much simpler to:
create a responsive grid of squares (3x3 or whatever grid you feel like)
then rotate the grid 45 degrees.
That way you won't have to fiddle with borders, pseudo elements (:after, :before) and positioning each diamond.
Here is a responsive example
It uses percentage width and padding-bottom to keep the diamonds responsive and transform:rotate(45deg); to rotate te whole grid and make it look like a diamond grid:
body{background:#000;}
#big_diamond {
width: 50%;
margin:15% auto;
overflow:hidden;
transform: rotate(45deg);
}
.diamond {
position: relative;
float: left;
width: 31.33%;
padding-bottom: 31.33%;
margin: 1%;
background: #fff;
transition:background-color .4s;
}
.diamond a {
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
}
#red{background-color: #AA1C08;}
.diamond:hover, #red:hover{background-color:darkorange;}
<div id="big_diamond">
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond" id="red"></div>
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond"></div>
</div>
As other people have mentioned, there are some errors in your HTML that I corrected like: Ids need to be unique and href can't be used on divs.
You're going to need to be more specific / clear on your first question.
First of all, you are using the ID 'diamond' many times. IDs are meant to be unique and used for one element. You should be using classes for this, not IDs.
Second, you can't use href within div tags. You could wrap the divs in a tags like this:
<div class="diamond"></div>
Or, even better so that the whole shape is clickable you can put the a inside of the div and make the a a block level element that is 100% width and height like this:
<div class="diamond"></div>
div a{
width: 100%;
height: 100%;
display: block;
}
JSFiddle Example: http://jsfiddle.net/kQj24/1/
This html has fallback for browsers that don't support transform in that the diamond becomes a square. Also the <div> elements can be wrapped in <a> tags using this method without altering any existing css rules for a. If transform isn't supported the text inside the square class doesn't rotate either.
<center>
<div class="diamond">
<div class="row">
<div class="square"><p>Text</p></div>
<div class="square"></div>
<div class="square"><p>Text</p></div>
</div>
<div class="row">
<div class="square"><p>Text</p></div>
<div class="square red"><p>Text</p></div>
<div class="square"><p>Text</p></div>
</div>
<div class="row">
<div class="square"><p>More</p></div>
<div class="square"></div>
<div class="square"><p>Text</p></div>
</div>
</div>
</center>
CSS, using your existing body rule:
.diamond {
padding-top: 50px;
transform:rotate(45deg);
-ms-transform:rotate(45deg);
-webkit-transform:rotate(45deg);
}
.square {
background-color: white;
display: inline-block;
height: 50px;
overflow: hidden;
width: 50px;
}
.square:hover {
background-color: green;
}
.square p {
transform:rotate(-45deg);
-ms-transform:rotate(-45deg);
-webkit-transform:rotate(-45deg);
}
.red {
background-color: red;
}
http://jsfiddle.net/5Q8qE/8/