I have got four text objects on a page, all of different length. I want one text object to be, for example, 'left: 2em;' (CSS). I want another text object to be positioned completely opposite the first text object (on other side of page).
I would like to position the text from the middle of the text not the end, so the distance between each text object and the closest edge is the same.
The problem can be seen in the following (low resolution) picture - Because the text is different length, it looks like the text is not positioned equally. Even if 'x' are the same and 'y' are the same.
The problem can also be seen here - The text looks like it is not evenly positioned. Even though the positioning code is:
right: 2em;
left: 2em;
right: 7em;
left: 7em;
It appears using 'right: ;' and 'left: ;' positions text from the end of the text. When you have different sized text, it looks like it is positioned unevenly. Maybe if you could position the text from the middle, it would look like it is evenly spaced.
Is there any other way?
Sorry if this seemed confusing.
Is it something like this?
<div class="parent">
<div class="child-1"></div>
<div class="child-2"></div>
</div>
.parent {
width: 100%;
position: relative;
}
.child-1 {
position: absolute;
top: 0;
left: 5em;
width: 100px;
height: 100px;
background-color: red;
}
.child-2 {
position: absolute;
top: 0;
right: 5em;
width: 100px;
height: 100px;
background-color: red;
}
There are plenty ways to make the elements be positioned oposite other one. Just add some code snippet to see where your problem is.
Related
I'm trying to make the below image.
The blue box is a div, the red square is a centrally-aligned image. The image overlaps the border of the div, but lies under the text in the div.
How would I go about this?
Explanation
Overlap
z-index is nice if you need div in different layer.
A div with smaller z-index will stay at back, so you can label border.
(Although I think it is not necessary in this case)
Center Align
To Align image in the center, add auto margin to image.
Image Position
If you want 30% of image to be inside the border, move top of the image by -70% of the height. So if the height of image is 100px, set top: -70px;
Text Position
Because the original image cover the space above the text, you will have to move text up to cover the blank space. To do this, move top of the text by the height of the image. So in this case, set top: -100px; After moving up the text, the space appear in the bottom of the devision. So to shrink the border, you will need to set margin-bottom: -100px; This will shrink the div to remove the blank taken by
Whole Div Position
Because you moved the image 70px above the whole div, you will need to set margin-top: 70px; to move the whole div down to prevent it being cropped out.
.border-div{
border: 3px solid blue;
margin-top: 70px;
z-index: -1;
}
.redsquare{
height: 100px;
width: 100px;
background-color: red;
z-index: 0;
margin: 0 auto;
position: relative;
top: -50px;
}
.text{
position: relative;
top: -100px;
z-index: 1;
margin-bottom: -100px;
}
<div class="border-div">
<div class="redsquare"></div>
<div class="text">Lorem ipsum has become the industry standard for design mockups and prototypes. By adding a little bit of Latin to a mockup, you’re able to show clients a more complete version of your design without actually having to invest time and effort drafting copy.
But despite all its benefits, seeing the same random Latin text in every design can get a little boring for you and your clients. So if you have a client who’s got a sense of humour or if you’re just tired of going the traditional route in your mockups, here are 15 creative and funny lorem ipsum text generators that are sure to lighten the mood at any client meeting.
</div>
My best suggestion is using position absolute in the children and use position relative in its border then set position to the children. Some thing like: https://jsfiddle.net/c39xej68/4/
.redsqr {
background-color: red;
height: 50px;
width: 50px;
position: absolute;
top: -30px;
margin: auto;
}
.bounder {
position: relative;
}
.text {
border: 1px solid blue;
}
I was wondering what will happen if
I set two images,div elements with
same position ( same coordinates)
on a webpage?
Will first Image get that position?
Will second Image get that position?
Will they get superimposed?
What will happen if the two DIV
elements containing data have same
coordinates on a webpage?
Also as upto I know location of
Images can be set via CSS but is
there any other method exist to set
the location of Image or DIV?
Thanks
The second div or image will be placed on top of the first. You can use this to your advantage. For example, you can place the second div on top, with opacity:0.5 and you'll see through it. This is often used when showing a modal dialog.
This simple example shows you.
By the way, there are lots of tools such as jsFiddle or CodePen that can be used to try things like this on your own.
div {
position: absolute;
left: 100px;
width: 100px;
top: 100px;
height: 100px;
}
#d1 {
background: blue;
opacity: 1;
text-align: right;
}
#d2 {
background: yellow;
opacity: 0.5;
text-align: left;
}
<div id="d1">
Div #1
</div>
<div id="d2">
Div #2
</div>
For the life of me I can't figure out why nothing will centre.
This image explains better than I could about what I want.
I want to centre all fields without changing which way around the kanji appear (For some reason the {{Expression}} field keeps flipping when I try to centre.
http://pastebin.com/PqEN9xMT
In your Templates wrap the Expression field with a div, give the div a class, and then center it with css styling.
If you want the absolute center of the main window try:
Front Template:
<div class='center-me'>
{Front}
</div>
Styling:
.center-me {
width: 100px;
height: 100px;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
I have seen the layout similar to the image below used on some sites before and I really like the design but don't exactly know how to implement the overlapping image (Profile Image). I am using bootstrap if that helps. Any ideas?
Thanks!
I can see three ways to do this generally.
position: absolute
You could give the image or the image's wrapper the attribute of position:absolute and giving its container (in your example the green box) position:relative. Then you would apply top: -100px or whatever and a left attribute of left: 100px or whatever. This gives the effect of the image being out of flow, aligned to the left and offset by 100px, and 100px offset from the top of the green container. The disadvantage of this approach would be that any body content in your green container could appear under the image.
position: relative
This is the same approach as the first one with the exception of how the image flows in the document. Instead of giving the image position:absolute, you would give it position:relative. Relative works differently from absolute. instead of being x and y coordinates of the parent container, it's just shifted by however much you give as a value for top and left. So in this case, you would apply top:-100px and just leave the other directional values as default. this would shift your element by that amount but also leave its original spot in the document flow. As such you end up with a gap below the image that other content will flow around.
negative margin
I honestly would prefer this method in your case. In this method, you can give the image a negative margin (e.g. margin-top:-100px). This will offset the image, collapse the area below the image, and it will still retain some of its flow in the document. This means that the content of the green container will flow around the image but only around the part that is still inside the container. It won't have a ghost area that content flows around like with relative positioning, but it also doesn't entirely take the image out of flow like absolute positioning. One thing to keep in mind, however, is that if you try to use overflow of any kind other than the initial value, it will cause undesirable effects to your image.
Demo
Here's a quick little demo demonstrating all three methods in a simple use case: http://jsfiddle.net/jmarikle/2w4wqfxs/1
The profile image can be set with position: absolute; top: 20px; left: 20px, or something like that to keep in from taking up space in the flow of the page.
make the html element that holds the header image "position:relative". Then put the header image and the profile image in that element. then make the profile image "position:absolute" and utilize "top: XXpx" depending on how far you want it from the top of the header element. Same for "left".
see fiddle here
<div class="header">
<img src="" alt="my image" class="floatdown">
this is my header, image could go here too
</div>
<div class="body">
this is my body content
</div>
.header {
position: relative;
width: 100%;
height: 150px;
border: 2px solid #000;
text-align: right;
}
.body {
position: relative;
width: 100%;
border: 2px solid #000;
height: 500px;
text-align: right;
}
img {
width: 90px;
height: 90px;
border: 2px solid #ddd;
}
.floatdown {
position: absolute;
top: 100px;
left: 20px;
}
You can use the float property on your profile image to take it out of the "flow" of the document, and play with the margins to place it properly.
CSS :
#profile-image{
width: 100px;
height: 100px;
float: left;
margin: 100px;
}
The marginis used to push it down and place it properly.
You can see an example of this in a Fiddle : http://jsfiddle.net/y706d77a/
I wouldn't recommand using position: absolute as you can get very strange results with different resolutions. I would only use that as a last resort.
This can be done many ways.
Anytime you see something like that on the web you can just use your inspector or firebug and see how they are doing it to get some ideas.
It wouldn't hurt to do some research on the web about CSS positioning.
http://www.w3schools.com/css/css_positioning.asp
Another great site.
http://css-tricks.com/
I just finished it.
Here is a codepen link:
http://codepen.io/anon/pen/zxYrxE
HTML:
<div class="main-container">
<div class="header">
<p>This is the header div</p>
</div>
<div class="profile">
<p>Profile</p>
</div>
<div class="content">
<p>Some dummy content div</p>
</div>
</div>
CSS is to big to be pasted here, so just open the link.
Put the profile image in the header, make the position: absolute; and the image position: relative;, and give it a negative bottom value that's half the height of the image, and set left to position it horizontally to taste.
HTML
<header>
<img class="profile">
</header>
<div>Content</div>
CSS
header, div{
min-height: 110px;
background: darkgray;
}
header{
position: relative;
background: gray;
}
img{
position: absolute;
bottom: -50px;
left: 100px;
}
http://jsfiddle.net/dekqn84c/
I have a div with dynamic text content. The amount of text varies between one word and five or ten words (with large font). Right now, it's absolutely positioned some amount from the bottom and the right of its relatively positioned parent.
However, since the content is dynamic, it looks awkward when sometimes there is more text and the text goes further into the main area of the parent. This is because right now, the reference point of the div is its bottom right corner. Is it possible to have it positioned with the center as the reference point, as depicted above?
The parent container is just styled as normal, with position: relative; and 100% width and height
CSS for the child container is also fairly standard:
position: absolute;
bottom: 33%;
right: 33;
I've tried playing with width, max-width, and min-width, but the result is still not desirable
How about this? Compare these two fiddles using the CSS below fiddle1 & fiddle2
HTML
<div id="parent">
<div id="anchor">
<div id="child">
<h1>Some text</h1>
</div>
</div>
</div>
CSS
#parent {
position: relative;
width: 100%;
height: 100%;
}
#anchor {
position: absolute;
right: 33%;
bottom: 33%;
}
#child {
padding: 10px;
margin-right: -50%;
float: right;
}