Struggling to create HTML divs with CSS styling

Currently working on creating a 768x240 window design. An example of what I have so far:

<div class="global-tab">
   <div class="image" src="link"></div>
   <div class="class1">{{details.name}}</div>
   <div class="class2">{{details.location}}</div>   
</div>

Here is the CSS style being implemented:

.image {
    display: inline-block;
    width: 29.6875%;
    height: 60%;
    padding: 5.208% 3.6458% 3.6458% 2.08%;
}

.class1 {
    display: inline-block;
    font-family: "Arial";
    font-size: 20px;
}

.class2 {
    display: inline-block;
    font-family: "Arial";
    font-size: 12px;
}

The image is positioned to the left, while class1 and class2 are on the right side (with text centered in the middle of the image using line-height). Currently facing challenges with applying margins, paddings, and alignment to these texts as desired due to difficulty in composing divs with that order. Any solutions or advice would be greatly appreciated! Thank you!

Answer №1

To begin, it's important to properly set up the structure of the DOM. I suggest organizing it into two columns if that aligns with your intention. Understanding the box model is key here.

Additionally, there is no need for a DIV element when inserting an image. Instead, utilize the <img> tag and include the "src" attribute accordingly.

Avoid specifying widths and paddings using decimal numbers as this could lead to issues down the line.

I have simplified the code for you below. Hopefully, this meets your requirements:

Below is the HTML and CSS code:

<div class="global-tab">
   <!-- DIV FOR FIRST COLUMN -->
   <div class="left-column">
       <img class="image" src="http://upload.wikimedia.org/wikipedia/en/thumb/d/d0/Chrome_Logo.svg/1024px-Chrome_Logo.svg.png">
   </div>
   <!-- DIV FOR SECOND COLUMN -->
   <div class="right-column">
       <div class="class1">{{details.name}}</div>
       <div class="class2">{{details.location}}</div>
   </div>
</div>

And here is the corresponding CSS:

.global-tab{
    display: inline-block;
    position:relative;
    background-color:#EEE;
    width:90%;
    height: auto;
    padding:10px;
    vertical-align:middle;
    text-align:center;
}

.left-column{
    width:48%;
    display:inline-block;
    vertical-align:middle;
    background-color:#333;
    text-align:center;
}

.left-column img{
    display: inline-block;
    width:100%;
    height:auto;
}

.right-column{
    width:48%;
    display:inline-block;
    vertical-align:middle;
    background-color:#333;
    color:#FFF;
    text-align:left;
}

For a functional JsFiddle example, click on the following link:

http://jsfiddle.net/p7akkxns/

Best regards.

Answer №2

Attempting to eliminate surplus closing curly braces } in the CSS styles for both .class1 and .class2 could potentially resolve the issue at hand.

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

Enhance User Experience by Making Each Background Slideshow Image Clickable

I want to create a background image slideshow for my photography portfolio. Each image should fade in and link to its respective gallery. I also want the text box to fade with the images and link to the corresponding gallery. The challenge is adding the li ...

What steps should I take to resolve the textarea border bottom CSS effect?

My simple border bottom animation is working fine with a basic input element, but it's not functioning properly when used with a textarea. (If using JavaScript is necessary for a solution, please provide guidance) How can I adjust the height of a te ...

PHP line breaks are not functioning as expected

I am having trouble formatting the email with line breaks to display as: Name: Email: Message: I attempted adding \r\n but it had no effect. Then I tried including $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n ...

Troubleshooting: Height setting issue with Kendo UI Grid during editing using Jquery

Issue: My Kendo UI JQuery Grid is fully functional except for a bug that occurs when adding a new record. When I add and save a new record, the grid's footer "floats" halfway up the grid and the scrollbar disappears, making it look distorted. Furth ...

Store Form Input as JSON Data File

Seeking advice on the optimal method to save submitted form data to a separate file called data.json, for future reference. The form layout is quite basic: <form> <fieldset> <label for="name">Name:</label> &l ...

Tips on sending an Ajax POST request to execute a PHP file

//The code below is found in the inserirPF.js file function add(){ var method = 'AddPerson'; $.ajax({ url: "../class/dao/InserirPFDao.class.php", type: 'POST', data: {Method:method, NAME_:NAME, EMAIL_:EMAIL, PASS ...

Upon the initial use of JQuery dialog, two additional dialogs are spontaneously opened

When utilizing JQuery dialog and opening an iframe inside it, the process is as follows: $('#div1').dialog("destroy"); if (criteria1 == "L") { $("#div1").html("<iframe id='dialogFrame1' src='../WebPages/abc.asp ...

What is the reason behind the image not displaying before the AJAX request is initiated and then disappearing once the request is completed?

I am attempting to display a "loading" gif while my AJAX request is being processed. Below are the functions I am using: beforeSend: function () { $('.form-sending-gif').show(); console.log("The beforeSend function was called"); } and ...

Exploring the wonders of retrieving JSON data in PHP through an Ajax request

A front-end developer is sending an array of data formatted as a JSON object using an Ajax call. The JSON object structure is shown below: { "name": " Test Name ", "image_url": "test URL", "include": [ "1" ], "dimension": [ null ], "media_type" ...

The close button on the modal vanishes on a real iPhone

The issue I am facing is that the Close Button appears when testing responsiveness in Chrome, but disappears on a real iPhone. When clicking on an image, the image gallery should appear. However, on an iPhone, only the previous and next buttons are visibl ...

adverse offset and backdrop

To achieve the desired layout, I am trying to adjust the negative margin for the .text div so that it aligns on top of the .image div. <div class="wrap"> <div class="image"><img src="imgage.jpg" /></div> <div class="text ...

Establish the minimum and maximum values for the text field depending on the selection made in the previous dropdown menu

For my project, I need to create a dropdown menu and a text box positioned next to it. I want the text box to have specific character limits based on the option selected from the dropdown. For example, if "Option 1" is chosen, then the textbox should only ...

Utilize the href attribute on an image, whether it be through a class

I work as a designer and I'm looking to extract the same href link from class="kt-testimonial-title", either in id="slick-slide10", or in class="kt-testimonial-item-wrap kt-testimonial-item-0", or in class="kt-testimonial-image". Can this be achieved ...

What is causing the malfunction of the position within this particular section?

On my website, I have a specific section where I want to showcase four products with arrows on both sides for navigation. However, I am facing an issue with the positioning of the elements. Can someone take a look and help me figure it out? Check out this ...

`Achieving synergy with jQuery functions`

As a beginner in jQuery, I have been searching for a solution to my issue. I have created 2 functions and I want them to work together. The first function is submitHandler, which hides a form and adds a class to reveal a hidden element - like a thank you m ...

Obtain the full HTML code for a Facebook album

I am attempting to extract the HTML code from a Facebook album in order to retrieve the photo links. However, since not all photos load at once, cURL only retrieves the links of photos that are initially loaded. Is there a way to fetch the entire loaded H ...

What's the best way to vertically center text in a div with overflow hidden?

In my ASP GridView, I am trying to display a table with a fixed number of lines in each TD element. To achieve this, I have decided to place a div inside each TD so that I can customize the height and layout. table.XDataGridView td div.inner-table-div { h ...

The jQuery pop-up fails to activate on the initial click

I have multiple "Buy Now" buttons for different products. If the button is labeled as "sold-out," it should not do anything, but if it's available, it should trigger a jQuery Magnific Popup. Currently, the popup only opens after the second click becau ...

Place your cursor over the following element to take control

There is a paragraph that needs to be clipped when hovered over. An issue arises where the H1 text shifts its position. Only the phrase "HOVER ABOVE PARAGRAPH" should be concealed. * { margin: 0; box-sizing: border-box; } .wrapper { displ ...

Increase the spacing around the content in a textfield

I'm trying to figure out how to prevent text in a textfield from extending all the way to the end of the field. My setup includes a textfield with a background image and a button positioned on the right side of the textfield. I want to ensure that the ...