What is the best way to align a div and two buttons with respect to an image within an li element?

I am trying to adjust the positioning of text on top of an image with a 40px margin. Additionally, I want to place two buttons on each side of the list item (one on the right and one on the left). Despite numerous attempts with various solutions, including the code below, I have not been able to achieve the desired result. The closest I've gotten is shown in the image below, but the buttons are still not positioned correctly. I aim to maintain this layout for every list item on the page.

CSS:

.container {
    width: 100%;
}

.posts {
    position: absolute;
    top: 200px;
    bottom: 0;
    right: 30px;
    margin: 0;
}
.post {
    background-color: #606060;
    border-radius: 30px;
    width: 600px;
    min-height: 300px;
    float: right;
    margin-bottom: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    bottom: auto;
    top: auto;
}

.img { 
    background-color: #606060;
    background-repeat: no-repeat;  
    background-size: contain; 
    width: 90%;
    height: 300px;
    position: relative;
    margin-bottom: 100px;
    border-radius: 50px;
}

.content {
    font-size: 15px;
    text-align: left;
    min-height: 120px;
    position: relative;
    left: 10px;
    color: white;
    font-weight: 700;
    margin-top: 40px;
}

.comment {
    background-color: #006FC4;
    border: 1px solid #00508D;
    font-size: 15px;
    color: #FFFFFF;
    padding: 5px;
    border-radius: 7px;
    height: 30px;
    position: absolute;
    bottom: 0;
    float: left;
}

.like {
    background-color: #006FC4;
    border: 1px solid #00508D;
    font-size: 15px;
    color: #FFFFFF;
    padding: 5px;
    border-radius: 7px;
    height: 30px;
    position: absolute;
    float: right;
}

HTML:

<div class="container">

<ul class="posts">

<li class="post">
<div class="content">Test</div>
<button class="comment" onclick="comment('posts/XiqNjxsov3hUXX1zJLk3ta7mQul2/userPosts/PkIm2NOhjOlTZk7J7Dyk')">Comment</button>
<button class="like" onclick="like('posts/XiqNjxsov3hUXX1zJLk3ta7mQul2/userPosts/PkIm2NOhjOlTZk7J7Dyk')">Like</button><<img class="img" src="https://firebasestorage.googleapis.com/v0/b/mysharify-4ea69.appspot.com/o/posts%2F6.png?alt=media&amp;token=f1881e5e-e9f4-4e90-bf0f-f211a74ccd42 complex_formula_here""><</li><br><br>

<li class="post">
<div class="content">dasdasd</div>
<button class="comment" onclick="comment('posts/hg23gh1beGO7cpUvRSkKpqcY9O22/userPosts/TpiuWCRoZQliuhmlj1su')">Comment</button>
<button class="like" onclick="like('posts/hg23gh1beGO7cpUvRSkKpqcY9O22/userPosts/TpiuWCRoZQliuhmlj1su')">Like</button><</li><br><<br>
</ul>
</section>

Another Image Example:https://i.sstatic.net/ZXDgC.png

Answer №1

Based on your post, I'm not entirely certain about what you're aiming for (a link to something similar would be beneficial), but here is my best attempt.

In the HTML code below, I have eliminated the second LI since all of them will appear identical, and that particular one didn't feature an image:

<div class="container">
    <ul class="posts">
        <li class="post">
            <div class="content">Test</div>
            <button
                class="comment"
                onclick="comment('posts/XiqNjxsov3hUXX1zJLk3ta7mQul2/userPosts/PkIm2NOhjOlTZk7J7Dyk')"
            >
                Comment
            </button>
            <button
                class="like"
                onclick="like('posts/XiqNjxsov3hUXX1zJLk3ta7mQul2/userPosts/PkIm2NOhjOlTZk7J7Dyk')"
            >
                Like
            </button>
            <img
                alt="foo"
                class="img"
                src="https://firebasestorage.googleapis.com/v0/b/mysharify-4ea69.appspot.com/o/posts%2F6.png?alt=media&token=f1881e5e-e9f4-4e90-bf0f-f211a74ccd42"
                onclick="openImage('https://firebasestorage.googleapis.com/v0/b/mysharify-4ea69.appspot.com/o/posts%2F6.png?alt=media&token=f1881e5e-e9f4-4e90-bf0f-f211a74ccd42')"
            />
        </li>
    </ul>
</div>

The CSS styles provided focus on various aspects such as positioning, colors, and sizing to enhance the visual appeal:

.container {
    width: 100%;
}

.posts {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    list-style: none;
}

.post {
    background-color: #606060;
    border-radius: 30px;
    width: 100%;
    float: right;
    position: relative;
    margin: 1rem 0;
}

.img {
    position: relative;
    background-color: #606060;
    background-repeat: no-repeat;
    background-size: contain;
    width: 100%;
    border-radius: 50px;
}

.content {
    font-size: 15px;
    position: absolute;
    z-index: 10;
    color: white;
    font-weight: 700;
    margin: 40px;
}

.comment {
    background-color: #006fc4;
    border: 1px solid #00508d;
    font-size: 15px;
    color: #ffffff;
    padding: 5px;
    border-radius: 7px;
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 10;
}

.like {
    background-color: #006fc4;
    border: 1px solid #00508d;
    font-size: 15px;
    color: #ffffff;
    padding: 5px;
    border-radius: 7px;
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 10;
}

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

When the mouse is moved to the UL LI list, the border color of the Top Hover is reverted back to default

Can you assist me with this issue? I need to modify the code below so that the border color remains blue while a user selects an item from the UL LI list. Here is an image showing the current problem: https://i.sstatic.net/DS7hO.png And here is a pictu ...

What's the best way to adjust the card column for mobile view resizing?

I am trying to modify the card view for mobile devices to display as a 2-column layout. I have adjusted the flex length and grid size in my code, but I still can't achieve the desired result. Can someone guide me on how to make this change? Current d ...

What's the best way to align divs vertically in a compact layout?

Update The reason I require this specific behavior is to ensure that all my content remains in chronological order, both on the web page and in the HTML structure. This way, even if the layout collapses into a single column on smaller screens, the content ...

PHP data is not displayed by Ajax

I seem to be encountering a bit of trouble. I am attempting to utilize ajax to retrieve data from a PHP server, which in turn fetches it from a MySQL database, and then display it within a specific HTML tag location. However, for some unknown reason, nothi ...

The jQuery function .val()/.text() is unable to retrieve information from a particular section of HTML

Implementing HandlebarsJS with PHP and Yii to generate a page. Here is a snippet of the html/handlebars code on the page {{#if embed_link}} <p class='f_hidden_p'> <a href='{{embed_link}}'> {{ ...

Conceal a div element after redirecting to a different HTML page

I have a dilemma with my two HTML pages - index.html and register.html. I am trying to navigate from index.html to register.html, but I want to skip the select region step and go straight to the login page. Here's the code snippet I've been attem ...

The radio button selection cannot be transmitted via email

Only the first radio button is selected <div class="field_radio" name="preference" > <input class="radio1" type="radio" name="preference" id="preference" value="team" onclick="ShowHideDiv()" /><label for="radio1"> ...

Checkbox label covering checkbox

I've been trying to enhance a login page with checkboxes by implementing code from react-bootstrap.github.io The issue I'm facing is that the checkboxes are overlapping their corresponding labels. Below is the snippet from my register.js file: ...

Transition effortlessly between web pages with subtle fading effects

I want to implement smooth page transition effects between two web domains: mcpixel.co.uk/new and mcpaper.co.uk. I am the owner of both domains. When a link in the header is clicked, I'd like the page to fade transition to the new page without any whi ...

Translate data from two "contact form 7" date fields into JavaScript/jQuery to display the date range between them

NEW UPDATE: I was able to get it working, but the code is a bit messy. If anyone can help me clean it up, I would greatly appreciate it. <div class="column one-fourth" id="date-start">[date* date-start date-format:dd/mm/yy min:today+1days placeholde ...

What happens when there is no match found while attempting to edit a form with the UI-Bootstrap typeahead directive?

Here is the code that demonstrates how my typeahead input box functions. Users can enter a name, and the relevant information will populate the rest of the form. If no match is found, users should still be able to input the name and related details into th ...

Tips for ensuring a static html element remains visible at the bottom of the screen even when the soft keyboard is opened in iOS Safari

Within a webpage, there is an input field and a fixed div positioned at the bottom of the window using CSS properties such as position:fixed; and bottom:0;. To better illustrate this setup, I have created a Codepen demo which can be viewed here: https://c ...

Navigating to a Website Based on the Selected Option in a Drop-Down Menu

I am currently working on a form that includes options for selecting a city and social networking site. The goal is to collect information about both the selected city and social network so that it can be stored for future reference. Upon submitting the fo ...

Exploring all the tags of a webpage using Python and Beautifulsoup: A step-by-step guide

I am a beginner in this industry. The website I am looking to crawl is "http://py4e-data.dr-chuck.net/comments_1430669.html" and here is its source code "view-source:http://py4e-data.dr-chuck.net/comments_1430669.html" It is a simple website for practice. ...

Tips for positioning two divs side by side in block formation

I'm attempting to display two distinct div elements as blocks, one for the name and the other for the names. Here is the Fiddle The names block should be displayed as a separate block next to the name div, regardless of screen responsiveness. How ca ...

Can you align a row under its corresponding column in Bootstrap?

Hello, I'm facing a dilemma with my layout. I have a grid consisting of 2 Rows and 4 Columns (col-md-8 & col md-4 in each row). The structure is as follows: Within the container Row 1 Column 1 (md-8) Row 1 Column 2 (md-4) [Accordion] Row 2 Colum ...

Sending numerous HTML forms using a sole submit button through AJAX

On my website, I have a page named publish.php where users can input details for each image they upload. Each image has its own form, but only one form is displayed at a time in a tabbed layout when the user clicks on the corresponding thumbnail. I want to ...

Utilize JavaScript to iterate through a JSON object and retrieve the indices that meet the specified criteria

While I found a previous answer that somewhat addresses my issue, I am seeking guidance on how to return an array of the indexes where a specific value appears. For example, if **18A38** is the target value, it should return the positions [1,3]. The sampl ...

Responsive card design created by Bootstrap element

Hello lovely people, I'm currently facing an issue with two triangles that are supposed to be next to each other with a small gap in between. However, when I resize the screen, they start moving freely and don't stay within the designated card ar ...

Chrome Canary's behavior with CSS border-radius on tiny objects

Is it possible to achieve CSS border-radius on really small objects in Chrome Canary? This experiment with a 3px high line and a 2px border radius, when zoomed in at 600%, doesn't show much difference: It works perfectly fine in regular Google Chrom ...