Relative positioning not working correctly CSS - html

so I'm trying to position my content box and its working fine for left, but when I try change the right value it doesn't allow. As you can see I have four images, but I want to show three, so therefore I'm trying to increase the right value so the box can only fit three (and also bring it in to the center a bit more)
I can get it to work by changing it to padding-right instead of right, but I don't understand why that works? My understanding is that : Padding = Distance between the content and the border, and right = how far from the edge?
Image:
This is my content box code (the images are inside it in another box)
.imagesArea {
position:relative;
top:15px;
left:100px;
padding-right:180px;
}
Thanks
edit: html (removed some of the image code)
<div class="imagesArea">
<div class="images">
<figure>
<img src="photos/image1.jpg" alt=”Photo” width=150 height=150>
<figcaption>Watch #1</figcaption>
</figure>
</div>
<div class="images">
<figure>
<img src="photos/image2.jpg" alt=”Photo” width=150 height=150>
<figcaption>Watch #2</figcaption>
</figure>
</div>
<div class="images">
<figure>
<img src="photos/image3.jpg" alt="Photo" width="150" height="150">
<figcaption>watch #3</figcaption>
</figure>
</div>
</div>

Your understanding of relative positioning is completely wrong. It sounds like you are confusing it with margins.
With relative positioning, the element is sized and positioned according to normal flow (i.e. as if it was statically positioned), and then the whole box is offset according to left/right/etc. This can cause it to overlap with other elements.
See this example for a visual representation.
It won't adjust the size of the box at all, so it will have no influence over how much content it can hold.
If you want to control how wide the element is, use width, padding, border and/or margin.

You can use margin for inner content div images
.images{
display: inline-block;
margin:0 20px 0 20px;
}
and set parent div
.imagesArea {
position:relative;
top:15px;
left:100px;
padding-right:180px;
text_align:center;
}
As you want to show 3 images in a row, It will work for you.

Related

HTML make child div expand beyond parent div (without width: 9999px)

I'm having a hard time with HTML/CSS now. I'd love to create some sort of a slider with images placed side by side with hidden overflow (so when you press "next" arrow it will "move" pictures to the left (hiding the left one and showing the one that was hidden).
The problem is I can't make my div to go beyond its parent thus I can't line up my images side by side.
It looks like this:
<div id="slider">
<div id="images">
<div class="image_container">
<img src="" alt="1"/>
</div>
<div class="image_container">
<img src="" alt="2"/>
</div>
...
<div class="image_container">
<img src="" alt="3"/>
</div>
</div>
</div>
Where #slider should be at 95% of width and preferably height based on content,
#images should have "no width" - it should be based on the content and max-height~, .image_container should have the width of the img - these should line up one next to another.
Any ideas how can I achieve that? I've been trying lots of things and none of them work.
Set the display property of the child elements to inline-block and the white-space property of the parent to nowrap.
#parent{
background:#000;
height:100px;
padding:5px;
white-space:nowrap;
width:200px;
}
#parent>div{
display:inline-block;
height:100%;
width:100%;
}
#parent>div:nth-child(odd){background:#f00;}
#parent>div:nth-child(even){background:#0f0;}
<div id="parent"><div></div><div></div><div></div><div></div><div></div></div>

Strange div positioning

I received HTML & CSS layout that should be working fine. However, I'm experiencing some strange problems for which I'm not sure why do they occur.
At the bottom of the following this website there is slider that should display couple of photos with text and by clicking on arrows it should slide them. The problem is I can't position neither arrows, nor wrapper containing images.
As you can see arrows(CSS classes: .strelica-lijevo and .strelica-desno are currently behind the image wrapper (CSS class: .slike-wrapper) when they should be left (.strelica-lijevo) or right (.strelica-desno).
Code can be seen directly on the website. Any help would be appreciated.
There are some issues with the HTML and CSS - you should either try to contact whoever delivered this slider to get support for implementing it or you could try by yourself as follows (just checked the markup and CSS and maybe this helps):
Your current HTML:
<div class="w-clearfix main-content karta">
<div class="slike-wrapper">
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/zagreb-is-the-capital-and-the-largest-city-of-croatia/5">
<img class="featured-male-slike" src='/Content/610ddd4a-b9a7-45f8-ac56-66eec5968329.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Zagreb is the capital and the largest city of Croatia</div>
</div>
</a>
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/museum-of-broken-relationships/8">
<img class="featured-male-slike" src='/Content/3a6ee262-676f-4599-9f97-6b9c48136449.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Museum of Broken Relationships</div>
</div>
</a>
</div>
<div class="strelica-lijevo"> <img src='/Content/strelica-lijevo.svg' /> </div>
<div class="strelica-desno"> <img src='/Content/strelica-desno.svg' /> </div>
</div>
could be changed into:
<div class="w-clearfix main-content karta">
<div class="strelica-lijevo"> <img src='/Content/strelica-lijevo.svg' /> </div>
<div class="slike-wrapper">
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/zagreb-is-the-capital-and-the-largest-city-of-croatia/5">
<img class="featured-male-slike" src='/Content/610ddd4a-b9a7-45f8-ac56-66eec5968329.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Zagreb is the capital and the largest city of Croatia</div>
</div>
</a>
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/museum-of-broken-relationships/8">
<img class="featured-male-slike" src='/Content/3a6ee262-676f-4599-9f97-6b9c48136449.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Museum of Broken Relationships</div>
</div>
</a>
</div>
<div class="strelica-desno"> <img src='/Content/strelica-desno.svg' /> </div>
</div>
This would just change the order of the elements - 1st the left arrow, than the gallery, than the right arrow - so they're displayed next to each other. Guess this could be changed in another way, but this is the easiest approach withouth having to change too much in the CSS.
In the CSS
.featured-male-slike.karta
{
clear: right;
display: inline;
float: left;
margin-top: 30px;
overflow: hidden;
/* position: absolute; */ /* <--comment position abolute out */
}
comment "position: absolute;" out - you could also remove it, but it's better to keep it just so you can check with whomever created this slider for you, maybe there's some other way to fix the slider as you mentioned it should be working as it is. Because of this position:absolute the gallery would still be displayed above the left arrow, removing it has the purpose to keep the CSS-property float:left for all three elements - left arrow, gallery, right arrow, so they will be displayed next to each other.
Next is up to you - the images are displayed not positioned correctly because they have a different height, and the css for the img is height: auto, meaning that the height for each img depends on the actual calculated height (as both images are scaled down from bigger original images). You could either try to display images with the same size, or you can add css to set a fixed height for both images, e.g.
.slike-wrapper img
{
height:140px;
}
as the left image has a calculated height of 158px and the right image has 140px. As I only tested this directly in the browser's web developer tools, I can't guarantee that this approach would work for you, but you can give it a try.

How to crop and align images next to each other?

On this grammar page there's a main 590px X 183px image at the top and 5 121px X 137px images at the bottom, aligned horizontally next to each other:
The bottom images are a resized crop of the main image at the top. In the screenshot example, the 3rd image at the bottom is the resized crop of the image at the top, buses. If you click on the first bottom images (books) it will take you to a page where books is also the image at the top (like buses above).
All this long-but-hopefully-clear introduction, is to ask how can I horizontally-align the the bottom images as a resized crop of the images at the top?
Now the bottom images were cropped and resized offline, and then uploaded as new files. So to visit all the 5 pages linked to from the bottom images, one has to download 10 image files. But if I could resize and crop (and still have the images horizontally aligned), those would be just 5 files.
I tried margin-left (and height) to resize and crop:
<img style="height:135px; margin-left:-290px;" src="http://www.imparare-inglese.it/uploads/1/1/1/6/11169156/7674785.png"/>
<img style="height:135px; margin-left:-610px;" src="http://www.imparare-inglese.it/uploads/1/1/1/6/11169156/6647450.png"/>
But just as I set the margin-left on the 2nd img, the 2nd image goes over the first. How do I prevent that? What am I missing?
Example with tables: http://jsfiddle.net/EZnAg/
Place the image inside a div, apply a width, height, float:left, position:relative and overflow:hidden on that div containing the image, then absolute position the image as required. If the image needs a faux/css resize, apply that in css too.
* {
padding:0;
margin:0;
}
.panels {
float:left;
}
.placeholder {
width:200px;
height:200px;
float:left;
overflow:hidden;
margin:0 20px 0 0;
}
.placeholder img {
/*width:100%;*/
}
<div class="panels">
<div class="placeholder">
<img src="http://www.jakss.co.uk/common/images/shell/header/client-logo.png" />
</div>
<div class="placeholder">
<img src="http://www.jakss.co.uk/common/images/shell/header/client-logo.png" />
</div>
<div class="placeholder">
<img src="http://www.jakss.co.uk/common/images/shell/header/client-logo.png" />
</div>
</div>
http://jsfiddle.net/seemly/PmUzY/
If you reinstate the width:100%; on the .placeholder img in my jsfiddle, hopefully this provides the effect you want, or at least gives you a head start?
cropped images are actualy new created images (from the original ones)with different aspect ratio. assuming that these images are totally different images(and not the same images just shown as width="smallpx" height=smallpx"), u can place them inside a div something like this
<div id="all_image contained" style="width: 300px;">
<div style="width: 100px; float:left">
<img src="images/img1.jpg" width="80px" height="50px"/>
</div>
<div style="width: 100px; float:left">
<img src="images/img2.jpg" width="80px" height="50px"/>
</div>
<div style="width: 100px; float:left">
<img src="images/img3.jpg" width="80px" height="50px"/>
</div>
</div>
in order to cropping, u have to use jquery script, to create new images with small aspect ratio and dimensions....
or else if u want to display the same large images, in small thumbnail size, then u may use a fixed size div and set overflow as hidden

relative position browser differences, absolute works but has no flow

I am trying to make a shopping cart layout and am having a hard time getting the checkboxes to appear at the right spot. The code here:
http://jsfiddle.net/35Hkj/1/
renders wrong on jsfiddle itself and internet explorer/firefox... It looks right in expression web 4 and chromium. Should be a checkbox beside each color.
If I position one check box with absolute in a relative container it works on all browsers perfectly but loses the flow meaning it doesn't expand the div container dynamically.
Is there a way to position absolute (relative to the parent) without losing the flow??
I'm guessing slicing up the image with css and positioning a checkbox beside each sliced part wouldn't be correct or easy.
Position absolute will allways "lose the flow".
However, you can position the divs absolutely, if they are in the same container as the image. Just change the left value accordingly. The container will be strechted to image's height as the image will remain in the flow.
Wrap the texts beside checkboxes in a label. More semantic + container divs will have enough height to not lose the flow so that you can absolutely position the checkboxes within.
An element with position:absolute is always taken out of the regular flow of relative elements.
What you could do is use a sprite for the background image. Place your checkboxes and your image in float:left and float:right divs or float both of them left and keep a margin between them and modify the background position of the sprite. If you wanted to, you could also use images, though I feel that using a sprite would be faster. For eg.
<div>
<div class='item'>
<div class='image'>
<img alt="" src="http://www.ahornblume.ch/images/img1.jpg" />
</div>
<div class='checkbox'>
<input name="product1[]" type="checkbox" value="skin" />skin
</div>
</div>
<div class='item'>
<div class='image'>
<img alt="" src="http://www.ahornblume.ch/images/img2.jpg" />
</div>
<div class='checkbox'>
<input name="product1[]" type="checkbox" value="face" />face
</div>
</div>
</div>
.item{
float:left;
width:auto;
}
.image{
float:left;
width:auto;
}
.checkbox{
float:right;
width:auto;
}
If you wanted to use sprites, you could give each div an id and define a background position, depending on the image-checkbox pairing.

Stopping text from wrapping around image

I am destroying my mind trying to get this styling done right. I have a fixed size image with an unpredictable height div of text to the right of it. I want the top of the text to line up with the top of the image but to NOT wrap around it. My markup is:
<img height='231px' width='132px' style='float:left' />
<div>Text</div>
I would like to find a solution that doesn't involve using a table, but at the moment I am drained and can't think about how to do it with css/divs
This should do the trick.
<div style="margin-left: 132px">Text</div>
To have space between the text and the image, make the margin larger or add a padding-left.
DanielB's answer nails it, but I just like giving alternative solutions; never know if it might come in handy. You could put the image and the div into a container with a fixed width, set a fixed width on the image and div that adds up to the container's width, and float the div as well.
<div id="container">
<img height='231px' width='123px' style='float:left' />
<div>Text</div>
</div>
#container div
{
float:left;
width: 123px;
}
#container {
width:246px;
}
http://jsfiddle.net/thomas4g/A7ZHg/3/