Place the h1 text inside of a div tag for organization

Here is an example of HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Company Home Page with Flexbox</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>

    <header>
        <div class="about">
            <h4><span>A work selection by </span><a class="sobre" href="">sfgndfyj</a></h4>
        </div>
    </header>

    <main>
        
        <article class="uno">
                <h1>
                    <span id="ppal" class="title_part" style="display: block; font-size: 12vw";>stills & moving image</span>

                    <span id="sec" class="title_part" style="display: block; font-size: 11vw";>TECHNICAL PRODUCTION</span>
                </h1>
        </article>

        <article class="dos">

        </article>

    </main>

</body>
</html>

The CSS for the above HTML is as follows:

html {
  box-sizing: border-box;
  font-size: 16px;

}
body {
    max-width: 1500px;
    margin: 0 auto;

}

/* -------------------------------------- fonts */

@font-face {
    font-family: 'Alternate Gothic';
    src: url('Alternate Gothic W01 No 3.ttf') format('truetype');
}

@font-face {
    font-family: 'Times Roman';
    src: url('OPTITimes-Roman.otf') format('opentype');
}

.sobre {
    color: black;
}

.sobre:hover {
    transition: background-color .1s ease-out,color .1s ease-out;
    position: relative;
    overflow: hidden;
    text-decoration: underline;
    background-color: black;
    color: white;
}

h1 {
    font-family: 'Alternate Gothic';
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: clamp(.5rem, 10vw, 1rem);
    
    }

h4 {
    font-weight: lighter;
    letter-spacing: .1rem;

}

#ppal {
    word-spacing: 90%;
}

.title_part {
    display: inline;
    position: relative;

}

/* --------------------------------- spacing */

.about {
    text-align: center;    
    margin: 0 5vw;
}

header {
    border-width: 0 0 1px 0;
    border-style: solid;
    border-color: #000;
    margin: 0 2.5rem;

}

.dos {
    border-width: 1px 0 0 0;
    border-style: solid;
    border-color: #000;
    margin: 0 2.5rem;
    
}    

I have been struggling to contain the h1 within its parent element properly. Despite setting a maximum width on the body, the text inside h1 overflows when the window is resized beyond 1600px. I have tried various methods like max-width and overflow but haven't been successful in keeping the h1 within the defined constraints.

If anyone has any insights or suggestions on how to solve this issue, I would greatly appreciate it.

Thank you!

Answer №1

By removing the white-space: nowrap; property, your span element will no longer prevent line breaks within the parent container. This adjustment should allow your code to function as intended.

To see a working example, check out the Fiddle below:

html {
    box-sizing: border-box;
    font-size: 16px;
}
// Other CSS styles...
.title_part {
    margin: 0 auto;
    /* white-space: nowrap; */ // Remove this line
}
<header>
    <div class="about">
    <h4><span>A work selection by </span><a href="">mfowmyoxsnk</a></h4>
    </div>
</header>

<main>
    <article class="uno">
    <div class="fulltitle">
        <h1>
        <span class="title_part" style="display: block; font-size: 12vw" ;
            >stills & moving image</span
        >

        <span class="title_part" style="display: block; font-size: 11vw" ;
            >TECHNICAL PRODUCTION</span
        >
        </h1>
    </div>
    </article>

    <article class="dos"></article>
</main>

Answer №2

To ensure your title returns to the line, you should use a wrap like this

white-space: wrap;

Answer №3

As mentioned by others, the key is to eliminate the "white-space." This will cause the text to wrap into two lines. To avoid this behavior, adjusting the font-size to be smaller is necessary.

Furthermore, removing the margin from ".uno" is important to ensure that the h1 element stays within the div. Currently, the margin pushes it outside the div regardless of the child's size, even if the text is responsive.

In addition to your query, instead of enclosing two spans in a single "h1" tag, consider replacing one with an "h2" or another subheader element depending on the desired size. If you are seeking to alter the positioning of elements (center, left, right) without using margins, I suggest exploring flexbox.

.uno {
    border-width: 0 0 1px 0;
    border-style: solid;
    border-color: #000;
    max-width: 1600px;
    position: relative;
}

.title_part {
    margin: 0 auto;
}

<div class="fulltitle">
    <h1 class="title_part" style="display: block; font-size: 5vw;";>stills & moving image</h1>
    <h2 class="title_part" style="display: block; font-size: 3vw; text-align: center; ">TECHNICAL PRODUCTION</h2>
</div>

I apologize for the formatting issues; I am still working on how to properly post answers on platforms like Stack Overflow.

Answer №4

My discovery is that:

(index.html)

  • The font-size within the span element grows endlessly due to its relationship with viewport units (vw).

(style.css)

  • Using clamp in the CSS code allows me to control the responsiveness of the font-size based on specific limits I set for the final design layout.

I will share my findings once everything is finalized and ready to be posted.

Answer №5

Here is the solution I have accepted for resolving the issue with h1.

After changing the units in index.html / .uno / span and making some adjustments to the css as shown below, the text no longer jumps to a new line.

I found that removing white-space was unnecessary.

If you have any suggestions for further improvement, feel free to share.

(index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Company Home Page with Flexbox</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>

...

(style.css)

html {
  box-sizing: border-box;
  font-size: 16px;
}

body {
    max-width: 1500px;
    margin: 0 auto;
}

...

Best

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

Are tabs best displayed as an overlay?

I've been searching high and low for a tutorial on how to create an overlay with tabs similar to the Google Chrome webstore. If anyone knows of a tutorial or a combination of tutorials that can help me achieve this, please let me know! Link Any guida ...

Tips for Deselecting a Table Cell in React

I've been working on a table in React and I'm trying to implement a feature where clicking on a cell colors it, and clicking on another cell uncolors the previous one. So far, I've managed to color cells upon clicking but I'm stuck on h ...

What is the best way to arrange three identical boxes next to each other, all of the same size

Imagine having a container with the following dimensions: .container { width: 960px; margin: 0 auto; height: 500px; } Now, envision wanting to add three boxes in the center aligned horizontally with these specifications: .box1 { background-color ...

Stopping Accordion Title from Moving Vertically in Material-UI

Just finished creating this accordion which will be used as a menu item. However, I've encountered an issue where clicking on the Main title causes the accordion summary to move downward vertically. Any suggestions on how to keep the Main tile fixed ...

Modifying selections within a select box generated dynamically using JQuery

Looking for help on how to delegate to a static DOM element in my current situation. I need to create a dynamic select box .userDrop when .addNew is clicked, and then have the user select an option from #secDrop, triggering a change event that calls the da ...

Ensure that the div is styled with a white background and positioned next to another div with a right margin

I have a white-colored div that needs to be positioned next to another element on a webpage. Additionally, I need a paragraph placed on top of this div for information purposes. Please refer to the following link to see what I am trying to achieve: https:/ ...

What are some ways to implement smooth scrolling when a navigation link is clicked?

I have a total of 3 links in my navigation bar and every time they are clicked, I want the page to smoothly scroll down to their designated section on the webpage. Although I have already set up the anchors, I lack experience in scripting to create the smo ...

What is the best way to display multiple divs in a single location?

I am facing an issue with displaying different text on mouseover for three buttons. I successfully implemented it for one button, but when I added the other two, it stopped working. Here is the code I used for the first button: Using jQuery- document.get ...

Opening the Gmail app from a link using JavaScript

What is the best way to open the Gmail app from a hyperlink? This link opens WhatsApp <a href="https://wa.me/">whatsapp</a> <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a1f190f ...

Transfer the choices from a dropdown list to a different JSP page

In my current JSP code, I have a select element that looks like the following: <select name="withoutAccess" size="5"> <c:foreach var="item" items="${obj.withoutAccess}"> <option>${item}</option> </c:foreach> </sel ...

Modifying Table Cell Background Color in ReactJS: A Guide to Conditionally Updating Cell Color Without Affecting the Entire Row

I am working on changing the background color of a cell based on its value. Currently, I am utilizing the following library: react-data-table-component Procedure: If the value is above 0, then the cell's background color will be red. Otherwise, th ...

Customize the background color of highlighted text using HTML and jQuery

Recently, I modified an existing code to divide plain text into four classes by selecting a portion of the text and coloring it. Afterwards, I extracted the text of each class and stored it in my database. While this code works well, I am looking for a way ...

Fetch data in JSON format from a specified URL

I have been attempting to fetch a JSON from a specific URL. Here is my current code snippet: <script> var co2; $(document).ready(function(){ alert("0"); $.getJSON(url,function(result){ var jsonObject = result; alert(result); ...

Expanding a div to occupy 100% width within a Material UI TableBody

I am struggling to center a CircularProgress component inside a material UI TableBody. I have attempted the following code, but the CircularProgress is not displaying at the center as expected. (Please note that only relevant code has been included) const ...

Issue with Translate3d functionality in fullpage.js not functioning as expected

Currently, I am in the process of constructing a website using fullpage.js with WordPress. Everything is functioning well except for one issue - when attempting to disable the plugin by using destroy() or changing setAutoScrolling to false, the translate3d ...

Struggling to locate desired href links using BeautifulSoup

I'm currently working on compiling a list of hrefs from the Netflix job portal: . Each job posting on this platform comes with an anchor and a specific class: <a class=css-2y5mtm essqqm81>. To ensure accuracy, here is the complete anchor: <a ...

Vertical alignment of text within a center位置

My current project involves creating a website layout similar to this: https://i.sstatic.net/5i1BK.png I am facing difficulty in centering the text within the box like this: https://i.sstatic.net/lCaFQ.png This is my progress so far: @font-face { ...

Universal compatibility for web displays

I've been conducting testing on a website across Chrome, Firefox, and Internet Explorer, utilizing the CSS code snippet below: #foot_links1, #foot_links2, #foot_links3 { position: absolute; margin-top: 55px; margin-top: 14em; color: # ...

Different ways to use jquery to move to the top of an overflow div

$('.lb').click(function() { $('#modal').hide(); var id = $(this).attr('id'); var dir = '/lightbox/' + id + '.php'; $('#lightbox').find('#modal').load(dir, function() { ...

What is the process for registering a click using a class in jQuery and retrieving the ID of the clicked element?

Currently, I am working on developing a webpage where I need to use jQuery to register a click using the items class and then extract the ID of that particular object. For example: HTML: <div class="exampleclass" id="exampleid1"></div> <d ...