What is the best way to align a div to the right side of an image?

How can I position an image in the center of the page with a block of text aligned to the left side of the image within a <div class='contain'>, maintaining a 10px space between them?

I want the image to remain centered while the text block floats to the right side of the image inside the <div class='contain'>.

Adding the property clear:both; to either the image or the <div> has not achieved the desired effect.

You can view a demo on jsfiddle here: jsfiddle Demo

Any advice on how to achieve this setup would be greatly appreciated. Thank you.

Here is my current code:

<h1><a id="toptitle" href="http://www.centerwow.com">portfolio</a></h1>
<div id="container">

    <div id="all_pages">

        <div class="page">
            <h1>Home Page</h1>
            <img src="images/yellow_flowers.jpg" width="300px" height="300px">
            <div class='contain'>this is the home page bla bla bla</div>
        </div> <!-- page1 -->
        <div class="page">
            <h1>About Us Page</h1>
            <img src="images/Pink_Flowers.jpg" width="300" height="300px">

        </div> <!-- page2 --> 
        <div class="page">
            <h1>Contact Us Page</h1>
            <img src="images/green_flowers.jpg" width="300" height="300px">

        </div> <!-- page2 --> 

    </div> <!-- #all_pages -->

</div> <!-- #container -->

<div id="menu">
<ul>
    <li id="1" class="link CC3366 active">Home</li>
    <li id="2" class="link 33FF66">About</li>
    <li id="3" class="link FFFF33">Contact Us</li>
</ul>
</div> <!-- #menu -->
<div id="footer"><a class="link" href="http://www.centerwow.com">mysite</a></div>
​
body {
    background: #CC3366 url(images/temp.png) center 130px no-repeat ;
    overflow:hidden;
    margin:0;
    padding:0;
    }
#container { 
    width: 1000px;
    overflow: hidden;
    position: relative;
    height: 450px;
    margin: 0 auto;
 }

#all_pages {
    position: absolute;
    left: 0;
    top: 0;
    width: 3000px;
    }
.page {
    width: 1000px;
    height: 400px;
    float: left;
    text-align: center;
    margin-top: 10px;
    }    
.page img {
    margin-top: 10px;
    }
#menu {
    background: #000;

    }
#menu ul { 
    list-style: none;
    width: 457px;
    height: 35px;
    margin:auto;
    }
#menu ul li {
    float: left;
    color: #FFFF33;
    width: 150px;
    line-height: 35px;
    text-align: center;
    cursor: pointer;
    }
.active {
    color: #fff !important;
    }
#footer a{
    font-size: 25px;
    font-weight: bold;

    }
#footer{
    line-height: 100px;
    background: #CC3366;
    width:100%;
    height:1000px;
    text-align: center;
    display: block;
}
#toptitle {
    position: absolute;
    width:100px;
    top: 30px;
    left: 30px;
    color: #000;
    cursor: pointer;
    z-index:20;
}
a {
text-decoration: none;
}
#contain{
    clear:both;
    float:left;
    margin-left:10px;
    background: blue;
    width:300px;
    height:300px;
}
.clear{

}​

$(".link").click(function(){
        var page = $(this).attr("id");
        var color = $(this).attr("class");
        color = color.substr(5,6);
        $('#all_pages').animate({left: (page-1)*(-1000) }); 
        $("body").animate({backgroundColor: '#'+color});
        $("#menu ul li").removeClass('active');
        $(this).addClass('active'); 
    });

Answer №1

I utilized a table to complete the task and it turned out well.

<center>
 <table>
  <tr>
   <td valign=top align=right width=50%>This is some sample text</td>
   <td width=300px><img src='fun.jpg' width=300px height=300px></img></td>
   <td width=50%></td>
  </tr>
 </table>
</center>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Positioning an absolute element inside a relative parent with a defined maximum width

I am attempting to position #header-supporter at the bottom right of #header-image, with overlapping elements. The challenge lies in setting a max-width of 1280px on #header-supporter-cont to maintain consistency with the site's margins. I have tried ...

Add additional text using the ::after pseudo-element exclusively for a particular class

Here is the HTML code snippet I am currently working with: <style> p::after { content: "%"; } </style> <div class="counter-box"> <p data-value="185">100</p> </div> At present, my CSS applies text injection to ...

Is there a way to integrate notifications into an HTML page using a plugin or through a specific method?

For my web application, I am looking to implement a unique notification box instead of the traditional message box. A plugin I came across is lobibox, which offers customizable notification pop ups that appear from the side and disappear after a set amount ...

Show a notification to the user through a pop-up message when they either select or deselect the checkbox in an Angular application

Suppose the user first selects the value for "Automatic" and then changes it to an unchecked state. An alert message will appear if any of the following accordions are in the "Completed" status. ...

Does the height of a block element change based on the font size?

Does the font size of content affect the height of a block element? Let me demonstrate what I'm talking about, take a look at this example fiddle If you enlarge the font size of the class .p within the div, you'll notice that the div's hei ...

Achieving Layers and Gaps with CSS: A Dive into DIVs

I am relatively new to CSS and I am currently working on creating a timeline similar to what Facebook used to have, where each post would be displayed alternately on the left and right sides. However, I am struggling with the layout of my timeline as the p ...

Is there a way to simplify this "stopwatch" even more?

Looking for advice on simplifying my JS stopwatch timer that currently only activates once and keeps running indefinitely. As a newcomer to JS, this is the best solution I could come up with: let time = 0 let activated = 0 function changePic() { if(a ...

When double quotes are used in a string within an HTML input field, they may display as &

Using PHP, I am retrieving data from an SQL database and generating JavaScript code to create an edit button for each entry. The edit button triggers a text input field within a form. When the user clicks on the generated edit button, the text in this inpu ...

D3.js: Difficulty fitting the chart within my bootstrap div

Currently, I'm encountering a problem where the "card" component from Bootstrap is not adjusting responsively with my d3.chart. The screenshot below displays the outcome: https://i.sstatic.net/2MhBx.png Chart Code const sample = [ { languag ...

Help needed with Wordpress: How to resolve double vertical scrollbars issue on parallax scrolling pages

I am new to coding and have been struggling with a particular issue for quite some time. I am using the Parallax Scroll plugin found here: https://wordpress.org/support/plugin/adamrob-parallax-scroll On my website (), when using the Customizr theme, two v ...

Initial space in model variable not being displayed

Hey there, I am working with a model variable called "name" that is linked to a span element like this: <input type="text" ng-model="name"> <span ng-bind="name"></span> My goal is to display the text entered in the input field without r ...

how to change class on vue function result

I need a way to display the content stored in requestData as li elements. Each list item should have an onclick function that, when clicked (selected), adds a specific value from a reference to an array. If clicked again (unselected), it should remove the ...

Is there a way to have my grid not apply grid-gap if a specific area is vacant?

I am working with a grid layout that has defined grid areas and a grid-gap, but some areas may not always have content. How can I prevent a double gap between items when an area is empty without changing the grid-template? For example: .grid { displa ...

Middle-align (with the help of Bootstrap-CSS)

I've been working on coding for a website and struggling to vertically center text. I've researched various solutions on StackOverflow and other platforms, like using the display:table and display:table-cell methods, along with the top:50%, trans ...

Tips for updating information when a button is chosen

Hello everyone, I need some help with a form that has three select buttons. The button labeled "Distribute" is already selected when the page loads, and it contains information about full name, password, and location. How can I use JavaScript to create a c ...

Image carousel with interactive buttons

I've taken over management of my company's website, which was initially created by someone else at a cost of $24,000. We recently made some edits to the slideshow feature on the site, adding buttons that allow users to navigate to corresponding p ...

What can be done to prevent inputs from shifting when resizing a browser window?

I am struggling to align checkboxes and text on a PHP form I am creating. No matter what I try, they end up misaligned when the browser is resized. Any suggestions on how to solve this alignment issue without changing the format of the rest of my page wou ...

Surprising 'T_ENCAPSED_AND_WHITESPACE' error caught me off guard

Error: An error was encountered while parsing the code: syntax error, unexpected character (T_ENCAPSED_AND_WHITESPACE), expected identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\html\updatedtimel ...

What is the best way to swap out an HTML element based on the size of the screen?

Is it feasible to switch out an <ol> element for a <ul> element based on media query? The desired outcome in desktop mode is: <ol> <li></li> <li></li> <li></li> </ol> while ...

When text is inserted into an inline-block div, it causes the div to shift downwards in

Consider the following HTML code snippet: <div class="one"> Test </div> <div class="two"> </div> <div class="three"> </div> If we apply the following CSS styles: div { display:inline-block; height:30px; ...