Utilize Bootstrap to position text and a form alongside an image in a visually appealing

Here is the HTML code snippet I have:

<div class="row trolibelanja">
    <div class="col-md-3">
        <img src="http://2.bp.blogspot.com/-WGiyrP7xGOk/VQlHwjgporI/AAAAAAAABHI/zLGXTH0-H2w/s1600/Mie%2BAyam%2B(4).jpg" class="detailfoto">
    </div>
    <div class="col-md-4">
        <p class="detailnama">Mie Ayam Bakso</p>
        <p class="detailtoko">Toko Bu Lastri</p>
    </div>
    <div class="col-md-2">
        <p class="detailharga">Rp. 30.000</p>
    </div>
    <div class="col-md-2">
        <div class="input-group">
            <span class="input-group-btn">
            <button class="btnjumlah" type="button">-</button>
            </span>
            <input type="text" class="form-control jumlah" value="1">
            <span class="input-group-btn">
                <button class="btnjumlah" type="button">+</button>
            </span>
        </div>
    </div>
    <div class="col-md-1">
    </div>
</div>

This is how the CSS looks like:

body{
    background-color: #661f61 !important;
    font-family: 'Saira Extra Condensed', sans-serif !important;
}

.container-fluid.keranjang {
    background-color: #e9e9e9;
    flex: 1;
}

.container.keranjang {

}

.row.trolibelanja {
        background-color: #e1e1e1;
    position: relative;
    padding-top: 10px;
    padding-bottom: 23px;
}

.row.trolibelanja:after{
    background-image: -webkit-linear-gradient(135deg, #6e1c64 25%, #e27f31 25%) !important;
    position: absolute;
    content: " ";
    width: 100%;
    height: 15px;
    bottom: 0;
}

.detailfoto {
    width: 100%;
    height: 110px;
    border: 6px solid white;
}

.detailnama{
    font-size: 20px;
    font-weight: bold;
}

.detailtoko{
    line-height: 20px;
    margin: -17px 0px;
}

.detailharga{
    font-size: 20px;
    font-weight: bold;
    text-align: center;
}

.input-group .jumlah {
    width: 50%;
    text-align: center;
}

.input-group .btnjumlah {
        background-color: #e27f31;
    color: white;
    border: 0;
    font-size: 20px;
    font-weight: bold;
    padding: 0px 10px;
    height: 100%;

}

I am working on aligning text and form next to an image using Bootstrap, similar to the layout in the image below:

View Layout Image

The result of my code:

View Result Image

Please advise on what I might be missing? I have tried different display combinations without success. Thank you.

Answer №1

Organize your columns correctly for optimal display. Place the image in one column (col-md-3) and the remaining content in another column (col-md-9). Then, move all other content to a new row. It's recommended that you familiarize yourself with rows and columns by visiting the Bootstrap website.

Reference: https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp

    <div class="row trolibelanja">
                        <div class="col-md-3">
                            <img src="http://2.bp.blogspot.com/-WGiyrP7xGOk/VQlHwjgporI/AAAAAAAABHI/zLGXTH0-H2w/s1600/Mie%2BAyam%2B(4).jpg" class="detailfoto">
                        </div>
                        <div class="col-md-9">
                          <div class="row">
                            <div class="col-md-4">
                                <p class="detailnama">Mie Ayam Bakso</p>
                                <p class="detailtoko">Toko Bu Lastri</p>
                            </div>
                            <div class="col-md-2">
                                <p class="detailharga">Rp. 30.000</p>
                            </div>
                            <div class="col-md-2">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                    <button class="btnjumlah" type="button">-</button>
                                    </span>
                                    <input type="text" class="form-control jumlah" value="1">
                                    <span class="input-group-btn">
                                        <button class="btnjumlah" type="button">+</button>
                                    </span>
                                </div>
                            </div>
                          </div>
                        </div>
                    </div>

Answer №2

To enforce a flex-wrap: nowrap; on your .row.trolibelanja, simply include it in the CSS:

.row.trolibelanja {
    background-color: #e1e1e1;
    position: relative;
    padding-top: 10px;
    padding-bottom: 23px;
    flex-wrap: nowrap;
}

You can view an example of this implementation on CodePen: https://codepen.io/anon/pen/xYbQLa

Answer №3

After testing your code on bootsnipp, I noticed that everything is aligned side by side except for the fact that you forgot to include img-responsive in the image class. Additionally, the code snippet provided below seems to be causing distortion in your design.

.row.trolibelanja:after{
    background-image: -webkit-linear-gradient(135deg, #6e1c64 25%, #e27f31 25%) !important;
    position: absolute;
    content: " ";
    width: 100%;
    height: 15px;
    bottom: 0;
}

I am not sure what your intention was with this code, but it might be a good idea to review and verify its impact on your design.

Adding your CSS caused significant distortion in the overall layout.

  1. Take a moment to review your CSS to ensure it is properly targeting the intended classes.

  2. Consider adding img-responsive to the img class, and that should resolve the issue.

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

Sign in using your username or email address

Currently, I am working on enabling users to log in using either their username or email along with a password. Below is the query that I have written: SELECT * FROM users WHERE (username = ':username' OR email = ':email') AND passwor ...

The scaling of the slick carousel image is not working as expected

Having an issue with the Slick carousel where images are not resizing based on browser size (original size is 300x228px). Just to clarify: When I shrink the browser window, the number of slides decreases but the images remain the same size. I've bee ...

Technique for integrating a different website within my own website

I am facing a challenge with embedding an external website into my own website in order to have a navigation sidebar with hyperlinks to navigate through other websites. Here are the methods I have attempted: <object data="www.facebook.com" width="100% ...

Jquery panoramic slider - Dynamically adjusting image width to fit screen size

Currently, I am attempting to implement a popular panning slider called Jquery Panning Slider for a website. The details regarding the markup structure, CSS, and jQuery can be found here: Slider Details. However, I encountered an issue with this slider. ...

Styling of static sites in Google Cloud buckets differs from the styling of the local copy

Today I discovered an issue with my static site hosted on a Google storage bucket while using Cloudflare for HTTPS. When visiting the site, I noticed that the styling was broken - some parts were cut off and others were shifted off center, not displaying a ...

Showing formatted JSON in the view using ASP.NET MVC

Is there a method to modify JSON for presentation in the interface? I am looking for a way to automatically update my API documentation when adding new properties. It would be great if I could also apply CSS styling to certain elements. This feature is som ...

Invalid Value Provided for CSS Clip Path

I'm currently attempting to design a sophisticated clip-path using a logo in CSS, but I keep receiving an error stating "Invalid Property Value." The X and Y coordinates have been computed based on dimensions of 508px x 190px https://i.sstatic.net/Yh ...

Tips on setting a background image to a div element

I'm facing an issue with a div setup like this: https://i.sstatic.net/4nuyO.png My goal is to remove a specific section of the circle shape displayed below: https://i.sstatic.net/09IWX.png The desired outcome is to achieve a final shape similar to ...

I'm having trouble grasping the project layout of a Vue project that was generated using vue-cli

Having recently ventured into Vue.js with no prior experience in frontend frameworks, I embarked on a project using the "vue create" command along with standard plugins. Everything seemed to be running smoothly until I decided to start from scratch by dele ...

I have just started a new project in Vue and noticed that the app div has some extra margin around it. Can anyone

In my fresh Vue project, I have the following code: App.vue: <template> <div id="app"> <p>hello</p> </div> </template> <script> export default { name: 'App', components: { } ...

What are the advantages of using the Php include function and the Jquery load function

I currently have 3 distinct folders in my directory: Admin Home Profile Each of these folders contains various css, js, and php files, each consisting of more than 1000 lines. This structure was implemented to keep the files organized and manageable. R ...

The web application located on the server is having trouble recognizing and loading the stylesheet

After deploying the web app on MS Server 2008 R2, I noticed that it is not reading the style sheets on any of the pages. The masterpage only contains a ToolkitScriptManager with no styles. However, the source code shows the style links and accessing them d ...

Tips for creating a menu bar where the entire item area is clickable

Currently, I am working on implementing a menu bar control. Below is the CSS and design code that I have used: CSS : .Menu { background:transparent url(../images/blueslate_background.gif) repeat-x; text-align:center; font-family : "lucida g ...

Concealing and organizing navigation bar items for mobile devices

Currently, my navbar looks like this on a larger screen: But here's how it appears on a smaller screen (phone): What I'm hoping to achieve is to make the U logo on the top left disappear and align "get in touch" closer to the other elements. On ...

What is the technique for transmitting a child element in VueJS?

Is there a way to include HTML code in a VueJS component and have it render properly within the component? <my-vue-component> <div> ect... </div> </my-vue-component> ...

What steps can be taken to limit the impact of CSS frameworks such as tailwindcss and bootstrap on the HTML content of wysiwyg editors such as Tinymce and Ckeditor?

When working with a TinyMCE editor, I have noticed that the output includes proper HTML tags such as h1, h2, b, ul, ol, li. However, when trying to display this output using TailWindCSS or Bootstrap on my own frontend, all the styles for each HTML tag appe ...

Learn how to customize an anchor tag in React to appear as a tile that remains highlighted when clicked

I am trying to style the anchor tag to appear as a rectangular tile (which is already in progress). When the tile/anchor tag is clicked, I need it to do the following two things: Remain selected and highlight with a green color. Upon selection or change b ...

Unexpected disturbance in horizontal alignment of bootstrap4 button caused by insertion of additional text above?

I utilized the grid systems layout in bootstrap to present my 3 courses. In this setup, I positioned the course image at the top, the course title in the middle, and the course enroll button at the bottom. However, when inserting a multi-line title for a s ...

Nested Callbacks

My goal is to trigger a callback function after another one finishes, but currently they all seem to be executing at once. Below is the code snippet: $('video#videopromo').bind('ended',function() { $("#hero").fad ...

In Groovy (or Java), learn the techniques to properly escape double quotes within HTML inner text while leaving attributes untouched

I am currently utilizing an HTML rendering engine that is based on Groovy within a Web Content Management (WCM) system. I have encountered a scenario where the user inputs rich text content into a form based on TinyMCE, which appears as follows: <p> ...