In CSS, use the p tag to make sure content fills the available space when the browser is resized beyond a certain point

Before I begin, I must clarify that I do not specialize in front-end development and my expertise in UI/UX is limited.

With that said, here is my query: I have a div containing p tags. I wish for this div to have a width: 700px when the browser window is at its maximum size. However, applying this property directly to the CSS of the div results in the text remaining static even when resizing the window. My goal is to have the text expand up to a certain point when the window is maximized and then shrink upon resizing, all without affecting a separate side-bar div.

To illustrate further, let me provide an example:

Maximized Browser Window:

Minimized Browser Window:

HTML

 <!-- HOME -->
  <div id="home" class="content">
   <h2>Home</h2>
   <p>AAAAAAAAAAAAAAAAAAA</p>
   <p>BBBBBBBBBBBBBBBBBBBB</p>
  </div>

CSS

.content {
    padding-bottom: 30px;
    position: absolute;
    left: 280px;
    right: 40px;
    top: 0px;
}
.content h2 {
    font-size: 110px;
    color: #fff;
    color: rgba(255,255,255,0.9);
    padding: 10px 0 20px 0;
    margin-top: 50px; 
}
.content p {
    color: black;
    font-size: 16px;
    line-height: 24px;
    display: inline-block;
}

Answer №1

In your scenario, Media Queries are not necessary. However, they would come in handy for more complex situations (such as different breakpoints).

All you need to do is apply max-width: 700px and that's it.

In general, your paragraph will never exceed 700px in width.
For very narrow widths, the paragraph will expand to fill the entire width like any block element, but it will still be under 700px so Media Queries are not needed!

Check out this example on JSFiddle to see it in action: http://jsfiddle.net/LQbgJ/ (I used 200px instead of 700)
This should work with IE7 and newer versions.

Answer №2

If you're looking to customize your website's layout based on different screen sizes, then Media Queries are the way to go. Check out the recommendations from W3C for more information.

The syntax for using Media Queries is quite simple. Here's a basic example:

@media screen and (min/max-width: ){ 
  //do something

}

These specific points in your CSS are known as 'breakpoints', allowing you to adjust the styling when the browser reaches certain width thresholds. This means you can apply different styles to elements like p and div.

@media screen and (min/max-width: ){ 

      div {
          width: 200px;
       }

       p {
          font-size: 20px;
       }
    }

For further guidance on implementing Media Queries, take a look at Smashing Magazine's tutorial here.

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

Dealing with a syntax error in JavaScript (Codecademy)

I have been working my way through the JavaScript course on Codeacademy and for the most part, I've been able to figure things out on my own. However, I've hit a roadblock with my code and can't seem to get it right. Here is the code I&apos ...

Converting HTML to PDF on iOS devices

I've encountered a challenge with a large HTML file that contains dynamically changing data. My goal is to convert this HTML document into a PDF format and send it as an email attachment. Can anyone offer advice on how I can accomplish this task? ...

Create a dynamic and interactive website using a combination of jQuery and AngularJS

I recently came across an interesting tidbit on the FAQs of Angular stating that "Angular can use jQuery if it's present in your app when the application is being bootstrapped". This got me thinking, is it considered a best practice to include both j ...

Is there a way to store image URLs in a fashionable manner?

Hey there! I've been working on creating a HTML page that showcases multiple images. Everything is running smoothly on my localhost, but when I try to access it online, the images take forever to load. Any suggestions on how I can cache image URLs in ...

Is there a way to update the background image of a div element through a JavaScript file within a react component?

After spending hours on this issue, I am still stuck and have exhausted all my ideas and research. In my project, I have three buttons that are supposed to change the background image of my site. The background image is linked to the default "App" div elem ...

Displaying <p> content upon selection of a radio button

As a beginner in JS + HTML, I am looking to create 4 radio buttons with different names like this: o PS4 o Xbox o Nintendo DS When one of these is clicked/checked, I want to display the price which will be located in a "p" tag next to them, like so: o P ...

Utilizing htmx for interactive elements throughout the website

When I make an htmx-request on my page, a loading spinner is displayed like this: <div class="col-4 px-4dot5 py-3 bg-secondary-light"> <label for="stellenangebotLink" class="form-label fs-5">Link</label> ...

Creating a Form Input Field Based on a Selection List

I'm in the process of developing a small app to boost my productivity at work. Currently, I have some html/js code that includes a ul with a search filter. When I select an option, it opens a new tab with relevant text. Ideally, I want the outcome to ...

Implementing a click event to convert text to input in Angular 5

I'm struggling with setting values instead of just getting them. I want to switch from using divs to input fields and update the values when in "editMode". <div class="geim__sets"> <div *ngFor="let set of game.sets" class="geim__set"> ...

Tips for arranging elements in a customized manner using Bootstrap

Is it possible to reorder columns between desktop and mobile in Bootstrap 5 like the example shown in this image? https://i.sstatic.net/I74PF.jpg I have explored using the order classes and experimented with position: absolute, but I haven't been ab ...

Arrange two internal divs on top of one another with the option to maintain the float

While searching for a solution to my issue, I noticed that most responses involved removing the float property. However, since I am new to CSS, I would like to explore using float and see if it's the best approach. Here is the fiddle I've been w ...

different ways to dynamically increase CSS ID in PHP

Is there a way to dynamically increment my CSS ID using PHP? foreach ($query_cat->result() as $row_cat) { $row_cat_id = $row_cat->id; echo '<div class="product-wrapper">'; echo '<div id="product-header' . $r ...

Testimonials paired with captivating visuals

I am interested in featuring a rotating selection of testimonials on my homepage. I would like to display only one testimonial at a time, with the content randomized upon each page refresh. My vision is for each testimonial to include a quote, the author& ...

How can I create a table using a loop and an onclick function for each <td>?

I have written code to create a table in PHP using a loop. I want to add an onclick function to each cell so that when a particular cell is clicked, the background color changes. However, I am encountering an error. Am I doing something wrong? <head& ...

Is it possible to use Google to search for specific HTML elements, or is there another method to identify elements without needing to provide the URL?

Can Google be used to search for specific elements? Is there a way to identify elements without needing the URL? An extensive search to locate elements. Example: I am trying to find websites that contain this particular class: .main-category-box.catego ...

I'm attempting to convert an HTML table to a pandas dataframe, but I'm running into an issue where I'm receiving the error message: TypeError: Cannot read object of type 'WebElement'

Trying to save an html table into a pandas dataframe is giving me trouble. I keep getting the error TypeError: Cannot read object of type 'WebElement'. driver.get('web_url') driver.maximize_window() driver.find_element_by_x ...

Is it possible for me to convert the contents of a <div> into a rasterized image when printing?

I have been using jquery.printElement.js to print a custom calendar table that I created. The functionality inside a div is mostly working as expected, but I am facing some challenges with the CSS. Despite passing along all necessary .css files, my cells a ...

Tips for customizing the blinking cursor in a textarea

I am experimenting with creating a unique effect on my website. I have incorporated a textarea with transparent text overlaying a pre element that displays the typed text dynamically using JavaScript. This creates an illusion of the user typing in real-tim ...

Using CSS3 easing on Mobile Safari can help create smooth transitions

Can anyone advise on how to recreate the easing/friction for touch events in Mobile Safari? I am trying to achieve a similar bounce-back effect when dragging contents past the top or bottom of a scroller. I experimented with the cubic-bezier easing functi ...

choose a selection hopscotch

Is there a way to prevent the input field from jumping out of alignment when an option is selected in these q-select inputs? I want to fix this issue so that the field remains in line with the horizontal alignment. https://codepen.io/kiggs1881/pen/RwENYEX ...