Words are extending beyond the boundaries of the box

Is there a way to create a 128px by 192x box with a title and text inside it, where the text can scroll if it's too long but the title remains fixed? The issue I'm facing is that the text is exceeding the boundaries of the box.

If you have any solutions or suggestions on how to fix this problem, please let me know!

JSFiddle: http://jsfiddle.net/qr8aK/

html:

<body>
<h1>JavaScript sample</h1>

<div id="square"></div>

<div class="card-front">
  <div class="card-title">Hello Friends</div>
  <img class="card-image" src="grizzly.jpg">
  <div class="card-text">
  (text content)
  </div>
</div>    
</body>

css:

.card-front {
  width: 128px;
  height: 192px;
  background-color: green;
  border: 2px inset gray;
}

.card-title {
  width: 90%;
  height: 1em;
  background-color: white;
  border: 0px;
  text-align: center;
  margin-top: 4px;
  margin-left: auto;
  margin-right: auto;
}

.card-text {
  width : 90%;
  height: auto;
  display: block;
  margin-top: 4px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 4px;
  overflow: auto;
  background-color: white;
}

I am new to HTML and CSS, so any feedback or advice would be greatly appreciated. Thank you!

Answer №1

.card-text {
  width : 90%;
  height: 150px;//the specified height
  display: block;
  margin-top: 4px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 4px;
  overflow: auto;
  background-color: white;

}

VIEW DEMO

Answer №2

check out the CSS overflow property

.card-front {
  width: 128px;
  height: 192px;
  background-color: green;
  border: 2px inset gray;
  overflow-y:scroll;
}

Jsfiddle


Updated

.card-text {
  width : 90%;
  overflow-y:scroll;

  display: block;
  margin-top: 4px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 4px;
 height:150px;

 background-color: white;
 }

Jsfiddle

Answer №3

When styling the card-text, be sure to specify the height and include overflow property.

.card-text {
width: 90%;
height: 155px;
display: block;
margin-top: 4px;
margin-left: auto;
margin-right: auto;
margin-bottom: 4px;
background-color: white;
overflow: scroll;
}

Answer №4

attempt

overflow:auto;

implementing this code will provide a scroll bar when the content exceeds the designated area.

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

Keeping track of the toggle state using a cookie

While searching for a way to retain the toggle state, I stumbled upon js-cookie on GitHub. The documentation provides instructions on creating, reading, and deleting a cookie. However, an example would have been really helpful in enhancing my understanding ...

Establish a timeout period for ajax requests using jQuery

$.ajax({ url: "test.html", error: function(){ //do something }, success: function(){ //do something } }); At times, the success function performs well, but sometimes it does not. How can I add a timeout to this ajax re ...

Is it possible to insert clickable links within the content of a Twilio text message?

Currently, I am utilizing Twilio and Express to send programmable SMSs to the users of my web application. I'm curious if it's possible to include hyperlinks within the body of these text messages. Is there a method to achieve this? I have attem ...

Tips for inserting a rotated image using CSS

I've created the following code snippet. However, there is a new requirement stating that the image needs to be rotated by 180 degrees. How can I make this happen? #cell { background-image: url("../images/logo.PNG"); background-attachment: fixed; b ...

Combine CSS files in a specific sequence

In my project, I have multiple CSS files being generated in the css/ folder using libsass. Additionally, I already have a normalize.css file placed in the same directory to ensure consistent styling across different browsers. As part of my build process, w ...

Enhancing Buttons with Stylish CSS Coloration

Looking for a way to style a list of buttons with the same shape and size but different colors? The buttons have unique IDs and all belong to the same class. Take a look at the code snippet below: --html snippet <ul id="query_type"> <li class= ...

Creating a dynamic React Bootstrap NavDropdown that opens on hover

I'm struggling to make a dropdown menu bar in React Bootstrap display the options when hovering over it. Despite my extensive search, all the solutions I found seem outdated and ineffective. Please reach out if you can help me solve this issue. Below ...

Steps to expand, collapse, and append new lines to a div by clicking a button:

I have a set of divs and I'm looking to implement a feature that allows users to dynamically add more div elements to the form when they click on the Expand/Collapse button, similar to the image provided. I've attempted the code below, but it do ...

Creating an image on an HTML canvas using RGB values

Looking for assistance on displaying an image using HTML Canvas with three 12x12 arrays containing R, G, and B values. I've seen Canvas demos showing how to draw lines, but nothing on using RGB arrays to create an image. Any tips or guidance would be ...

What steps can be taken to ensure the CSS/HTML image aspect ratio remains consistent on various monitors?

My square-shaped image (1:1 aspect ratio) is displaying differently across various devices when I use the codes below. While some show it as a perfect square, others display it as a rectangle. Is there a solution to maintain the original aspect ratio consi ...

Using jQuery to update the CSS background of a selected element among multiple elements sharing the same class

I am currently developing a basic jQuery script that will enable the background color of the clicked element to change. Below is the code I have so far: <dt> <input id="p_method_banktransfer" value="banktransfer" type="radio" name="payment[metho ...

Tips for displaying the product title of an item in the Woocommerce shopping cart

Is there a way for me to display the title of the product in my Woocommerce store's cart on the checkout page? My store only allows one product in the cart at a time, and I want to customize the checkout page to show the product title. I've tri ...

Guide to looping through a map arraylist in JavaScript

Here is a sample map arraylist. How can I access this arraylist using JavaScript from within pure HTML? And how can I iterate over this list? <%@page import="org.json.simple.JSONObject"%> <%@page import="org.json.simple.JSONArray"%> <% JSON ...

Flickity Unable to Apply CSS Styles

Seems like a straightforward problem, it reminds me of this issue discussed on Stack Overflow but in relation to Vue instead of Angular. I am facing an issue where the CSS styling I'm trying to apply to my Flickity carousel is not being rendered corre ...

Adding new rows between existing rows in an HTML table using Jquery syntax

How can jQuery be used to insert rows between existing rows in an HTML table? <Table id="TEST"> <tr>1</tr> <tr>2</tr> </table> I need to include a new row <tr>xx</tr> between the rows with values ...

Inheritance of currentColor in SVG URLs

Seeking the same solution as mentioned in How can an SVG image inherit colors from the HTML document?, specifically when applied to an svg image used as content on a :before pseudo-element. (The intended outcome is for both checkmarks to adopt the red col ...

A study of Cycle2 and Firefox's Image Blinking

Currently troubleshooting my jQuery Cycle2 slideshow issue on Windows 7 and FireFox. The problem only occurs in this specific scenario, where images load partially before fully displaying one second later. For a visual of the issue, check out this video: h ...

Close the fullscreen modal automatically when clicking anywhere inside

Hey there, I'm facing an issue with a button that I want to trigger a full-screen section containing some inputs. I attempted to use Bootstrap's full-screen modal for this purpose, but encountered some challenges. When I clicked anywhere on the ...

How can we prevent the restoration of size effects in jQuery UI versions 1.9 and above?

After implementing jQuery UI 1.9 or newer, I noticed that the size effect returns to its original state. Below is a snippet of my code: http://jsfiddle.net/mQCxY/ $(function () { $('.circle').click(function () { $(this).effect("size ...

Using jQuery and JSON data to dynamically populate a second dropdown menu with filtered options

I am working on a form with two drop-down menus and a text box. The first drop-down contains static values, while the second drop-down is populated dynamically from a JSON array. My goal is to filter the options in the second drop-down based on the selecti ...