Tips for adjusting inner margins on ion-card elements in Ionic 4

Currently, I am attempting to create a card that contains text with specific spacing from the border.

  • My first attempt involved setting padding for the card, but I found that the top and bottom spacing was too large.

  • In my second attempt, I decided not to use padding at all, but this resulted in the removal of spacing on the right and left sides as well.

  • In a third approach, I resorted to a workaround by shifting the start of the text 16px from the left using the following CSS:

    .lefts {    
      position: relative; 
      left: 16px; 
    }
    

    However, this solution did not address the issue of the right margin, and it felt like an inadequate fix.

https://i.sstatic.net/QoXQ7.png

What's the goal? I aim to achieve a card layout with top and bottom margins similar to the second case (Desde Sevilla) but with equal spacing on the right and left like the first case (Desde Malaga)

Refer to the following HTML:

<ion-card padding>    
<ion-text class="bold" color="primary"><p>DESDE MALAGA</p></ion-text>
<ion-text color="dark"><p>It takes 4 hours by <a href='http://www.tgcomes.es/horarios_3.htm'>Bus</a> or 2.5 hours by car (frequent route on <a href='https://m.blablacar.es/ride-sharing/malaga/cadiz/'>Blablacar</a>)</p></ion-text>    
</ion-card>

<ion-card>    
  <ion-text class="bold" color="primary"><p>DESDE SEVILLA</p></ion-text>
  <ion-text color="dark"><p>The journey takes 1h45 by <a href='http://www.tgcomes.es/horarios_13.htm'>Bus</a> or 1h40 by <a href='http://www.renfe.com/'>Train abcd efgh ijkl</a></p></ion-text>    
</ion-card>


<ion-card>    
  <ion-text class="bold.left" color="primary"><p>DESDE JEREZ</p></ion-text>
  <ion-text class="lefts" color="dark"><p>This is the smallest airport, if you're traveling from outside Spain, you'll need to connect through Madrid or Barcelona. It takes 30 minutes by car from Jerez or 1 hour by <a href='http://www.aena.mobi/m/en/jerez-airport/train.html'>Public Transport.</a>
  We may be able to pick you up ourselves or have a family member do so.</p></ion-text>    
</ion-card>

I've also included this CSS, although I don't believe it is crucial:

ion-card {
    border-top: 3px solid #d15b5b;
    border-bottom: 3px solid #d15b5b;
    border-left: 3px solid #d15b5b;
    border-right: 3px solid #d15b5b    
}

Answer №1

custom-card {border: 3px solid #d15b5b;padding: 10px 15px;}

Answer №2

For optimal usage, it is recommended to utilize the ion-card component in its intended form, incorporating all (or some) of its child components:

<ion-card>
  <ion-card-header>
    <ion-card-subtitle>Card Subtitle</ion-card-subtitle>
    <ion-card-title>Card Title</ion-card-title>
  </ion-card-header>

  <ion-card-content>
    Keep close to Nature's heart... and break clear away, once in awhile,
    and climb a mountain or spend a week in the woods. Wash your spirit clean.
  </ion-card-content>
</ion-card>

The padding within this section is supplied by <ion-card-content> and can be customized through local, overriding CSS.

UPDATE: Include link to Ionic's API documentation

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

Chrome fails to read font family correctly

I created a jsfiddle that demonstrates an interesting behavior with setting and reading the font-family using jQuery. When I set the font-family to "Arial . . ." it reads back okay, enclosed in a single set of double quotes. However, when I set the font-fa ...

Guide to creating a versatile navigation bar using Bootstrap and HTML

I am looking to create a navigation menu that can be easily reused across multiple pages on my bootstrap/html website. Instead of duplicating code, I want to implement a solution for creating a reusable navigation menu in bootstrap/html. How can this be ...

Display properties of a JSON object using VUEJS

How can I efficiently read JSON data in my VueJS code? Here is the code snippet: <template> {{data}} </template> <script> import axios from 'axios'; export default { data() { return { data: null }; }, mou ...

What is the functionality of CSS radio tabs?

Can anyone provide a breakdown of how the final section of this code operates? Specifically: [type=radio]:checked { } [type=radio]:checked ~ .content { z-index: 1; } I am brand new to CSS and wanted to experiment with creating interactive CSS tabs, whi ...

Avoiding caching on HTML pages rendered by the SharePoint content editor web part

Is there a way to prevent caching on a HTML file displayed in a SharePoint library using a content editor web part? I attempted the following methods in the HTML file, but they were unsuccessful: <meta http-equiv="Cache-Control" content="no-cache" /&g ...

If the image is not found, add a count instead of showing a new one each time

I have implemented a function to retrieve the two-letter country code: $ipaddress = $_SERVER['REMOTE_ADDR']; function ip_details($ip) { $json = file_get_contents("http://ipinfo.io/{$ip}"); $details = json_decode($json); return $detai ...

Validating Angular Forms within a NgFor loop

Consider the scenario where there is a form implemented as shown below: <form #form="ngForm"> <div *ngFor="let action of member_plan.actions"> <div class="container"> <h4 class="text-sm-center black mb-3">{{ ...

Toggle the input box by clicking the button

How do I show or hide the input box (blue square) when I click the search button (red square)? Link Image I attempted to create the transition in CSS and also experimented with JavaScript, but the JavaScript part confused me. Here is what I tried: $(" ...

Embedding PHP code within inline styles

Is it possible to incorporate a variable inside my progress bar? I want the progress to change based on the status of each project ($projek), but inserting the variable directly into the style attribute doesn't seem to be working. Here's the code ...

Rendering the HTML5 canvas within a console environment

I am looking to create images of humans on the console using nodejs. In order to achieve images of higher quality, I require a library or module that can facilitate drawing images in the console. Some options available include imaging and console-png. How ...

Arranging components in a horizontal layout on Jquery mobile

I'm completely new to Jquery mobile and I'm having trouble getting these elements aligned. Here's my code, but I need the two icons to line up horizontally with the caption "Heading". <h3>Heading</h3> <img src="../re ...

Filling out a Form in Advance

I'm having trouble populating a form in a new window using JQuery. The new window opens as expected, but I can't get the form to populate successfully. $( "body" ).delegate( ".propose", "click",function() { var url = './prop_form.php& ...

Django is looking for a primary key that I do not possess

Encountering an issue: invalid literal for int() with base 10: 'ljrh' This error occurs when attempting to add a new entry in a model: day = itemize(value, getday(strip(key))) add = Reoccurring(request.user.username, strip(day.Day), strip(day. ...

Is there a way to stop these symbols (♈♉♊♋♌♍♎♏♐♑♒♓) from being substituted with emojis?

I am currently working on a project involving the simulation of the Prague Astronomical Clock (). My goal is to display the glyphs representing signs of the zodiac, which are in the Unicode range U+263C-2653 along with other astronomical symbols. My prefe ...

Manipulating an SVG file with JavaScript

Within the HTML code, there is a photo already added as an SVG file. I am interested in learning how to enable the user to select between two options - either a cross or a zero. Upon clicking on the designated area, the chosen figure should appear (resembl ...

Is it feasible to animate a JQuery slider?

Is there a way to animate the slider using jQuery? I want to be able to press a button and have the inner part of the slider move slower (e.g. 300ms) without reacting to mouse clicks and slides. Here is the code: http://jsfiddle.net/gm4tG/5/ HTML: <d ...

What could be the reason for Chrome breaking up this straightforward bootstrap header into two lines?

Why is it that the code below displays correctly in one line in both FF and IE, but Chrome for some reason is showing it on two lines as if both span and button elements had "display:block;"? Even though the button has a computed display of "inline-block," ...

Tips for rotating a canvas object without changing its position

I am currently in the process of developing a JavaScript game centered around a character positioned on top of the world. Although the earth element is already part of the game, I am encountering an issue with its rotation causing it to shift position as w ...

Bootstrap modal within a nested clickable div

Utilizing the bootstrap MODAL plugin with nested divs, I have a requirement where clicking on the inside div should display the EDIT form, and clicking on the container div should show the ADD NEW form. Here is the code snippet: <div id="container" sty ...

How to Position an Input Text Beside an Icon Image Using JqueryMobile

Just starting out with jquery mobile and css! Check out my jsfiddle.net/mapsv3/kWJRw/1/, when I use an icon on the left side, the input text gets cut off and I can't see the end of it. ...