Tips for positioning an image to the right within a container without relying on the float property

Is there a way to align images in my code to the right, creating two rows with boxes aligned on both sides - left and right? I've tried various methods like float, but always run into issues. Here's my code:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,intial-scale=1">
        <title>Marko's portfolio</title>
        <link href='http://fonts.googleapis.com/css?family=Fredericka+the+Great' rel='stylesheet'>
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link rel="stylesheet" href="css/style.css">
        <script src="js/jquery-2.1.3.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </head>
    <body>
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-6">
                <img src="http://placehold.it/100x100" class="img-responsive logo" alt="Responsive image">
                </div>
                <div class="col-md-6 text-right text-uppercase">
                    <h1>Name</h1>
                    <h3>Front-end Ninja</h3>
                </div>
            </div>
            <div class="row">
            <div class="col-md-12">
            <hr class="line">
            </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <img class="img-responsive picture" alt="Responsive image" src="images/ideja.jpg">
                </div>
            </div>
            <div class="row text-center">
                <div class="col-md-12">
                    <h2>Featured Work</h2>
                </div>
            </div>
            <div class="row text-thin text-center">
                <div class="col-md-6">
                    <img src="http://placehold.it/555x300" class="img-responsive" alt="Responsive image" data-toggle="modal" data-target="#project1">
                        <h3>Appify</h3>
                    <p><a href="http://github.com">Link to project</a></p>
                </div>
                <div class="col-md-6">
                    <img src="http://placehold.it/555x300" class="img-responsive" alt="Responsive image">
                    <h3>Appify</h3>
                    <p><a href="http://github.com">Link to project</a></p>
                </div>
            </div>
            <div class="row text-thin text-center">
                <div class="col-md-6">
                    <img src="http://placehold.it/555x300" class="img-responsive center-block" alt="Responsive image">
                    <h3>Appify</h3>
                    <p><a href="http://github.com">Link to project</a></p>
                </div>
                <div class="col-md-6">
                    <img src="http://placehold.it/555x300" class="img-responsive center-block" alt="Responsive image">
                    <h3>Appify</h3>
                    <p><a href="http://github.com">Link to project</a></p>
                </div>
            </div>
        </div>

Also here is the corresponding CSS styles:

body { font-family: 'Fredericka the Great', cursive;
}

.display {}

.text-thin{font-size: 14px;
}

.line {border-top-width:0px;height:2px;background-color:rgb(42,35,35);
}

.logo { margin-top:20px;
}

.picture { width:1440px; height:500px;}

Thank you for your help!

Answer №1

To align elements, you can utilize the margin-left property with percentages. For example:

.logo { 
    margin-top:20px;
    margin-left: 40%;
}

When working with other images:

.col-md-6 img {
    margin-left: 10%;
}

If you want the image to fit perfectly within its container, adjust the size accordingly:

.col-md-6 img {

    width: 100%;
    height: 100%;
}

Check out the live demo here!

Answer №2

To avoid any layout issues, it is recommended to use a clearfix or precise overflow for the container box. Additionally, you can align the image to float right and the text content in a separate container floating left as shown below:

<div class="col-md-6 clearfix project">
    <img src="http://placehold.it/555x300" alt="Responsive image">
    <div class="description">
        <h3>Appify</h3>
        <p><a href="http://github.com">Link to project</a></p>
    </div>
</div>

Don't forget to add the following CSS styles:

.project {
    overflow: hidden;
}
.project .description {
    float: left;
}
.description {
    float: left;
}

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

Get rid of the box-shadow on the Vuetify element

I currently have a special-table component that includes a box shadow when the row is expanded https://i.stack.imgur.com/8zgjp.png I am aiming for the removal of the box-shadow effect. After inspecting the console-style tab, I identified https://i.stac ...

In Chrome, there is a single pixel missing below the <dl> element

While my website's basic list looks great on Firefox and IE, there seems to be one missing pixel line in Chrome. Check out this JsFiddle link shared by Jared in the comments for reference. If you're not seeing the missing line, try adjusting th ...

Incorporate a PHP file from an external website, as plain text or HTML

My dilemma involves a php file that resides on a particular website (for example: ). This script generates html content, primarily consisting of text formatted with tags like <h2>, <p>, and so on. The task at hand is to take this text and embe ...

Jquery tool for showcasing events along a chronological timeline

Can anyone recommend a Jquery plugin, AngularJS plugin, Bootstrap, or any other plugin to create a Timeline for displaying events? I have already explored TimelineJS, but I am looking for something with a constant focus on the current time, like a monitor ...

I created a custom JavaScript code to animate a cat emoji on a canvas:

An interactive script was designed to move a cat on canvas using HTML input buttons. When clicked, the cat moves 10 pixels in the specified direction (moveUp(); moveDown(); moveLeft(); moveRight();). The script initially works well for the first few clicks ...

"Pair of forms and buttons to enhance user experience with Bootstrap and

Experiencing an issue with my webpage that is built using HTML, Bootstrap, and PHP. The page contains two forms: a contact form and a distribution form within a modal. The problem lies within the distribution form as clicking the button only submits the ...

Incorporate page numbers into meta titles for paginated pages in Wordpress with Yoast SEO

I've come across this question multiple times, and despite reading numerous posts online, none of the answers seem to address my specific issue. My problem lies in adding page numbers to meta titles on paginated pages, including the homepage and taxo ...

What is the deal with this boundary?

Recently, I was experimenting with CSS borders and came up with this interesting result: border-style: double dashed dashed solid; I am curious to understand why it produces such an effect. Adjusting the border-width seems to have unexpected consequences ...

Creating a protective boundary for images and text in HTML

<!DOCTYPE html> <html> <head> <title>Homepage</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <body style="background-color:#38a9e3;"> <link rel="styl ...

What's the best way to ensure images and videos in a div maintain their aspect ratio when resizing?

Is there a way to make the image and video fit inside the div without altering the aspect ratio? The code snippet below is what gets displayed on my website, utilizing bootstrap for responsiveness. <div id="micropost-208"> <di ...

What is the process for generating a printable report using HTML, CSS, and ASP.NET Core?

I am looking to create a customizable report using HTML and CSS, however I am not familiar with designing forms like pay slips that can be easily printed. Please see the images I have shared below for reference. Any help or guidance would be greatly apprec ...

Why does text display differently in HTML (Firefox) on Ubuntu compared to Windows 7?

When viewing the HTML and CSS code in Firefox on Windows, everything appears fine. However, when I view it in Firefox on Ubuntu, it looks out of place. How can this be corrected? Any suggestions? Additional information: The CSS code used for the text show ...

Showing a tooltip on the right side of a control with an arrow pointing towards it in a colored

Can someone help me with displaying a tooltip to the right end of a control, with the arrow facing the same direction and changing the background color of the arrow to red? Here is my attempt so far <input id="age" title="test tooltip"> $( documen ...

Turn off drag and drop functionality and activate selection in HTML

Recently, I encountered a strange issue where selected text became draggable and droppable onto other text, causing it to concatenate. To resolve this problem, I added the following code: ondragstart="return false" onmousedown="return false" However, thi ...

Modifying the border of images in a Weebly gallery

I'm having trouble changing the gallery image borders on Weebly. The client prefers using Weebly for easy backend editing once the design is in place, so I need to work within these parameters. Usually, I can make most code edits easily...but this iss ...

Replace old content with new content by removing or hiding the outdated information

I need to update the displayed content when a new link is clicked index html file <a href="" class="content-board" > <a href="" class="content-listing" > content html file <div class="content-board"> <div class="content-lis ...

The functionality of HTML5 canvas image objects is not functioning as expected

I have been working on a function to retrieve an image object using HTML5 canvas, but I keep encountering an error alert (onerror event) function FetchImage() { var img = new Image(); img.src = "http://localhost/assets/images/loadedsprite.png"; ...

Prevent a div from being displaced by the transform property once it reaches the window's border

Is it possible to prevent the viewer I created using CSS transform from moving when its borders reach the window borders? Should I consider using a different method instead? If you'd like to see the code, you can check it out here. var x=0, y=0 ...

Basic animation feature malfunctioning

So, I'm really new to this whole HTML5 canvas thing and I'm trying to make a pixel move across the screen with an additive tail behind it. The idea is for the tail to scroll away once it reaches a certain point while the pixel continues moving. I ...

Combining table rows using the <td> class in JavaScript

I am currently working on refining the JS code to merge rows with common values and classes in a table. The existing code successfully merged common rows but failed to consider their classes. Snippet of the Table code: <tbody id="property_dtl_table_bo ...