Container problem with position relative

Afternoon guys!

I have a problem trying to float <h3> within a div.

  • have a look at the “restaurants” and “accommodation” divs under discover.
    Client wants heading floated right within these containers.

It works fine untill you resize the browser window smaller (to 1024px)
(it has to work on different sizes im coding for this as well)

The “restaurants” and “accommodation” headings juts out of the block to the right.
I want to keep these contained in the block

Anyone know what I am doing wrong?

Also, at this width the layout of “products” and “travel” gets messed up and i cannot figure out why!
The code is exactly the same for all the blocks.

What i recommend you do is give you .discovercont selectors a relative position and your h3 elements an absolute position as currently you will have a hard time aligning things due the static widths and positions you have set.

Hi there,
I have tried that,
but then the h3 elements dont float to the right, they float to the left

The text inside the h3 needs to expand from the right as well,
(starting from right inside border of discover cont element)

ie the headings may have different character counts… some are 10 characters some are 7

The problem is that you have fixed-width images in the discovercont divs, but the divs expand and contract because they have a % width.

One thing you could do is float the images right, so that the text is always over the image.

To stop the snagging problem, it’s a good idea to get rid of float: left and use display:inline-block instead:

.discovercont {
  [COLOR="#FF0000"][s]float: left;[/s][/COLOR]

.discovercont img {
  float: right;

hi there,
that worked and it fixed the products/travel alignment issue…

how does the text fall over the image if its the image that is floated right?

Thankyou so much!!

If you stretch the browser wider, the container gets wider, and the text sticks to the right of the container … but the image has a fixed width, and naturally sits to the left of the container … so eventually the text moves off the image. If you float the image to the right of the container, it always stays together with the text. Try it and see. :wink:

ok …check this out…

i tried it for the business blocks on the page
(where it says business showcase - blue blocks)

if you make the browser window smaller - gradually -
you will see that the headings pop out and do not stay contained
ie “jays shop” ends up being above the blue block

I added this to the css:
display: inline-block;

.business img{
float: right;

what did i miss?

I would place them absolutely as already mentioned.


.business h3{

They will then always stick together and expand from the right and bottom up as required