Large square connected to a smaller squareIn HTML and CSS

I'm attempting to create a square with another smaller square attached to it. My goal is to place text in the larger square and an icon in the smaller square (see example image below).

Since I am using bootstrap 4, I want to achieve this using HTML and CSS to take advantage of the responsive features of BS4 and maintain consistency throughout the entire webpage.

Thank you in advance for any assistance!

Large square with small square attached

Answer №1

Have you ever worked with the ::before and ::after pseudoclasses before?

You can achieve something like this using the following code snippet. Keep in mind that you may need to adjust the background color and size of the ::after element to get your desired look. This example assumes there are existing styles applied to your "big-box" element. For more in-depth information on the capabilities of ::before and ::after, check out the resources provided below by Kevin Powell.

.big-box {
  position: relative;
}

.big-box::after {
  content: url(<icon-image>);
  position: absolute;
  left: 100%;
  top: 15%;
}

Additional Resources on Before & After Pseudo-elements:

Answer №2

Here's a simple way to achieve this design:

HTML:

<div class="parent-container">
    <div class="main-section">
        <p>Our Service</p>
        <p>lorem ipsum</p>
    </div>

    <div class="icon-container">
        <i>icon</i>
    </div>
</div>

CSS:

.parent-container {
    display: flex;
}

.main-section {
    background-color: green;
    border-radius: 8px;
    padding: 12px;
}

.icon-container {
    background-color: green;
    height: 24px; /*height of the icon*/
    position: relative;
    top: 15px;
}

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

Calculating square roots in AngularJS

I'm building a basic calculator using a combination of HTML, CSS, and AngularJS. Overall, everything is functioning correctly, but I’m looking to incorporate a SquareRoot function into the calculator. Here’s a snippet of my code: function _solv ...

Additional padding was included for the jQuery logo

I've been working on fine-tuning my jQuery submenu, but I'm running into some CSS challenges. Here are the issues I'm facing: How can I prevent the navigation from adding extra padding at the bottom each time it is reopened? .sidebar-n ...

Internet Explorer 11 has a problem with excessive shrinking of flex items

I have a flexbox setup with a left and right section, each of equal width. The left side displays an image and the right side contains text. While this layout works fine in Google Chrome, it does not wrap properly in Internet Explorer 11 when the width is ...

When the direction is right-to-left (rtl), the floating labels in Bootstrap slide towards the center

Seeking to implement floating labels in Hebrew using bootstrap v5.2, I encountered a challenge. When switching the direction to rtl and clicking on the input box, the label slides towards the center. Here is my code snippet: <div class="form-f ...

Avoid encountering issues in case Cookies have not been configured

CoffeeNoticeError After trying to search for possible duplicates without success, I have a coffee-centric website primarily developed using HTML 4, CSS3, JavaScript, and some php. On a page named coffee.html, I have inserted an image that creates a cooki ...

What could be the reason behind this button becoming completely ineffective after just one click?

Whenever I click the button (with class "add-book-btn"), I want to insert a new div (with class "book-card"). The code snippet below initially works when I click the button for the first time. However, afterwards something goes wrong an ...

Adjust the size of a nested div with varying height

Hey there! I'm facing an issue with a main div that contains 2 other divs. I need the height of the lower div to change dynamically based on the resize of the main div. Here's the code I have so far: <html> <head> <meta http- ...

The value of the input field in jQuery is not defined

I am encountering an issue with an error: jQuery input val() is undefined. I have 3 inputs that are all referencing one item. When I add a new row, I can create a new item (3 rows). All of these rows need to be organized in an array to be sent to a PHP f ...

Adding a div after a specific child in a bootstrap grid

I've been searching tirelessly, but I just can't seem to crack this puzzle... In my Bootstrap grid, I'm faced with the challenge of injecting a div upon click after the row where the clicked div is located. For instance, I have a series of 5 ...

Tips for creating a scrolling iFrame that moves with the background

I have recently created a website with a unique design feature. The background image acts as a border surrounding the main content, which is located within an iFrame. However, I've encountered an issue where scrolling the iFrame does not affect the ba ...

Is there a way to fill an HTML text box with data retrieved from a session or managed on the server side using C# and HTML?

I have some textbox values on an aspx page that I pass to the next page using sessions. Now, I want to display these values in an HTML textbox. How can I achieve this? The values I have are server-side, while the HTML text box value is client-side (this is ...

"Creating a Two-Column Layout with ASP.NET Core and Bootstrap through POST

I have been working on a simple form for testing and learning purposes. Initially, I used Scaffold New Razor Page in VS to create the form. Afterward, I attempted to modify it in order to have two columns on the create page. Despite trying various methods ...

What is the best way to add a listener for a modification of innerHTML within a <span>?

How can I detect changes inside a particular <span> element in order to attach a handler, but so far have been unsuccessful? Below is the HTML snippet: <span class="pad-truck-number-position"><?php echo $_SESSION['truckId']; ?> ...

Creating a modal popup when a button is clicked

After searching online for a way to make my sign up modal pop up when the signup button in my navbar is pressed, I was unable to find any information on how to achieve this. I suspect it involves JavaScript, but my knowledge of JS is limited. I attempted ...

The process of deleting lines from an image using Javascript

If I have an image of a data-table and I want to eliminate all the grid lines (defined as continuous vertical or horizontal pixels), is there a way to achieve this using Javascript's image data manipulation? I envision looping through a 2D array conta ...

Yet another inquiry about the inexplicable failure of my jQuery Ajax in Internet Explorer

Just need to double-check if my test code below is correct. I've done some research and it appears that html syntax errors can cause the jquery ajax to not work in Internet Explorer? There are several includes where this code is located, so could the ...

Tips for verifying the correct format of an email entered in HTML and PHP

<form action="form.php" method="POST"> username:<input type="text" name="username"> <br> password:<input type="text" name="password"> <input type="submit" value="register"> </form> I need to validate the email field to ...

What causes the slowness of onsubmit=" " function?

Initially, I had the following setup: HTML: <form onsubmit="return validate()"> ... <input type="submit" id="submit-button"/> </form> JS: function validate() { // Extensive validation process with regex and more... $(& ...

What could be causing the CSS to malfunction when the dropdownlist is updated without refreshing the page?

Currently, I have implemented DropKick CSS/JQuery to customize the appearance of my asp:DropDownList: <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:DropDownList AutoPostBack=" ...

Do AngularJS routes allow the use of special characters in URLs?

Issue at hand: Every time I enter http://localhost:53379 in the browser, it redirects me to http://localhost:53379/#/. Why is the /#/ being added? angular .module('app', ['ngRoute', 'ngStorage']) .config([&apo ...