What is the best way to showcase labels and values in distinct columns within a view?

I have set up a Drupal 7 view to showcase some user fields, opting for an unformatted list layout. However, I am unsatisfied with the current appearance.

My goal is to arrange the field labels ("Name," "Age," and "Country") and their corresponding values ("Jeroen," "19," and "Belgium") in my view within two outlined columns on the left side.

While I know how to eliminate the colons, I am unsure about how to properly separate the field labels from the values. Is there a way to achieve this?


Edit: After following Ajay's suggestion, I now have the code snippet below:

<div>
 <div class = "user-label">Name</div>
 <div class ="user-value">[field_name]</div>
</div>
<div>
 <div class = "user-label">Age</div>
 <div class ="user-value">[field_age]</div>
</div>
<div>
 <div class = "user-label">Country</div>
 <div class ="user-value">[field_country]</div>
</div>

This is the styling applied:

 .user-label{
    float:left;
    font-weight: bold;
   }

  .user-value{
    float:left;
    margin-left: 20px;
  }

Despite these adjustments, the layout is not visually appealing. How can I align the values neatly into two columns?

Answer №1

It seems that the suggested solutions above are no longer relevant, as they rely on outdated methods such as using floats. A more modern approach would be using CSS grid. Here's how I would implement it:

HTML:

<ul>
  <li><span>Label 1</span><span>Value 1</span></li>
  <li><span>Label 2</span><span>Value 2</span></li>
  <li><span>Label 3</span><span>Value 3</span></li>
</ul>

And CSS:

ul {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

li {
  display: contents;
}

Answer №2

Appreciate the new HTML layout you provided. Consider using float for this:

<!--language:css-->.user-label {
  float:left;
  clear:left;
  width:5em;/* adjust as needed, you could have another div for input too*/
}

Answer №3

1)Established a view named "Test"

2)Navigate to the field section and include a field called "Name" from the user. Beneath it, there is an option in the "Rewrite Result" section.

3)Access the "Rewrite Result" area where you will find a checkbox labeled "rewrite the output of this field". Check the box and insert the following code:

<div class= "main-user">
     <div class = "user-label">Name</div>
     <div class ="user-value">[name]</div>
 </div>

Furthermore, incorporate the style in your custom.css file of the theme

.user-label{
    float:left;
   }

  .user-value{
    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

Capture the onclick attribute with jQuery and then reapply it

I am facing a challenge with a page that has several calendars composed of HTML tables where each day is represented by a td. The td elements have an onClick attribute which I need to manipulate using jQuery. Specifically, I need to remove the onClick attr ...

displaying an item within a text field

I have an input box created using Angular reactive forms <input type="text" formControlName="OrgName" placeholder="Enter name" maxlength="60"> <p class="fieldRequired" *ngIf="showNameMSg" ...

Personalized navigation bar color while hovering in Bootstrap

I can't seem to figure out the right CSS syntax to customize my navbar links when hovering. Here is my navbar structure: <ul class="nav navbar-nav navbar-right"> <li><%= link_to "Home", root_path %></li> <li cla ...

The element positioned with a z-index of -1 will be placed beneath the grandparent's division

Why does using z-index:-1 on an absolutely positioned child element make it go under the grandparent div? How can I ensure that the absolute-child stays under the parent div instead? .grandparent{ background:rgba(0, 128, 0, 0.89); width:500px; } .p ...

What are the steps for troubleshooting LESS in Chrome?

It appears that the art of LESS debugging has made significant progress in the last year, and I am curious to know how many people have experience using developer tools in Chrome/Canary for debugging. My goal is to make sure that when I debug a file, the ...

Please submit information that is not already filled out in the text fields

I am looking to create a table with text fields and buttons as shown below: <table border="1"> <tr> <td>name</td> <td>id</td> <td>icon</td> <td> </td> & ...

What is the proper way to address the error message regarding requestAnimationFrame exceeding the permitted time limit?

My Angular application is quite complex and relies heavily on pure cesium. Upon startup, I am encountering numerous warnings such as: Violation ‘requestAnimationFrame’ handler took 742ms. Violation ‘load’ handler took 80ms. I attempted to resolve ...

What is the set standard for the "minimum computer screen width"?

When creating a responsive website, there comes a point where further shrinking the width of html on a computer screen would not be reasonable (excluding mobile or tablet devices). Do web developers adhere to a specific standard minimum number of pixels f ...

Utilizing CSS3 webkit-transitions with multiple properties on a div element along with multiple webkit-transition-delays

Is there a way to make a div slide 200px to the right and then reduce its scale by half separately? I want it to slide first and then scale, but currently both transformations happen simultaneously. I tried using webkit-transition-delay to set different ...

Is it possible for me to input a variable into the logical process of if(isset($_FILES['whatever']))?

I have recently started learning PHP and I'm in the process of creating a dynamic page that will update based on which form buttons are clicked. The functionality is working correctly, but my goal is to enable users to upload multiple files - either P ...

Django template receiving incomplete data from view: missing variables

I am really confused by this one, any help on the subject would be highly appreciated. This is how I have written my code: @login_required def product(request, prod_id): pr ...

How to Detect Font Resizing in Google Web Toolkit (GWT)

I am trying to find a way in GWT to capture the font resize event that occurs when the user changes the size of the font by using Ctrl-Mouse Scroll or going to View -> Zoom. I have searched on Google and looked on StackOverflow but haven't found an ...

Is there a way to use javascript to ensure that CSS variables stick even when overwritten by onclick events?

I have successfully implemented a method to change CSS variables using advice found here. However, I am running into an issue where the changes do not persist. After clicking on a navigation link, the styles momentarily switch to the new values but quickly ...

Can React JSX and non-JSX components be combined in a single project?

I'm currently faced with a question: If I have a parent component in JSX but need to include an HTML tag like <i class="fa fa-window-maximize" aria-hidden="true"></i>, which is not supported by React JSX (correct me if I'm wrong), can ...

Send form data without reloading the page and connect it to a JavaScript script

I've designed a system that reveals values based on a specific input selection. Below is the main form where users can enter model numbers and press enter: <form> <input type="text" name="ModNum" id="ModelNumber" pattern="^PIV13RT[23]?$" ...

The appearance of a scrollbar and displacement of elements is attributed to the presence of the <

I encountered a problem while working on my project where the layout was functioning perfectly until I introduced hr elements. This action caused a shift in everything and led to the appearance of a vertical scroll bar as compensation. However, the presenc ...

Tips for designing a unique mosaic using flex technology

I am attempting to design a unique mosaic layout using flexbox that resembles the image provided: https://i.sstatic.net/jrHvb.jpg Each box should have a width equivalent to one-third of the parent container, except for box 4 which needs to be double the ...

Utilizing the React.js Bootstrap grid system

I've been diving into React, but I'm facing an issue with the bootstrap grid/reactstrap. Instead of getting horizontal columns as expected when using the grid system, I seem to be stuck with a vertical layout. Film.js import React from "react"; ...

Designing a dropdown menu in HTML that includes labels or helpful descriptive text to indicate different sections

I am interested in creating an HTML dropdown list that looks like this: Category1 Value1 Value2 Category2 Value3 Value4 Category3 Value5 Value6 and so on.. The labels Category1 to Category3 are meant to create a segmentation wi ...

How to Modify Button Backgrounds in Angular 8 after Click Events?

Within my Angular 8 Component, I have implemented a row of 4 buttons using the ant design (antd) library in HTML. My Objective: I aim to modify the background-color of a button when it is clicked. The previously clicked button should revert to its origin ...