Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

Design a web page that contains two paragraphs (p1, p2) with 12pt font size. The font…

  1. User

    Design a web page that contains two paragraphs (p1, p2) with 12pt font size. The font size increases by 1pt each time the user clicks on paragraph p1. The font size goes back to 12pt when the user clicks on the p2 paragraph.

  2. Assistant

    Here is a simple solution using HTML, CSS, and JavaScript:

    HTML:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Change Font Size</title>
        <style>
            p {
                font-size: 12pt;
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <p id="paragraph1">This is paragraph 1.</p>
        <p id="paragraph2">This is paragraph 2.</p>
    
        <script src="script.js"></script>
    </body>
    </html>
    

    CSS:

    p.clicked {
        font-size: 13pt;
    }
    

    JavaScript (script.js):

    let paragraph1 = document.getElementById('paragraph1');
    let paragraph2 = document.getElementById('paragraph2');
    
    paragraph1.addEventListener('click', function() {
        paragraph1.classList.toggle('clicked');
        paragraph2.classList.remove('clicked');
    });
    
    paragraph2.addEventListener('click', function() {
        paragraph2.classList.toggle('clicked');
        paragraph1.classList.remove('clicked');
    });
    

    This code creates a web page with two paragraphs, where the font size of paragraph 1 increases by 1pt and goes back to 12pt when paragraph 2 is clicked. The p.clicked class is used to change the font size of the paragraphs when the user clicks on them. The JavaScript code adds event listeners to the paragraphs, and when clicked, it adds or removes the clicked class to the paragraph, triggering the font size change through the CSS rule.