Aligning text to the left center

I am looking to center left-aligned text in the yellow box (txtbox). The current look is like this:

and I want it to appear like this:

HTML:

       <div class="content container small">
                    <div class="txtbox">
                        <header style="text-align:left;">
                            <h2>I AIN'T</h2>
                            <h2>AN ARTIST.<h2>
                            <h2>I'M A</h2>
                            <h2>BEAST!</h2>
                        </header>
                    </div>
                <footer>
                    <a href="#one" class="button style2 down">More</a>
                </footer>
        </div>

CSS:

.container.small {
    /* width: 900px; */
    width:800px;
}
.txtbox{
    width:800px;
    margin:0 auto;
    background-color:yellow;
    text-align:center;
}

Answer №1

.title-container h1{
    margin-left: 30px;
}

Answer №2

.txtbox header {
    display: grid;
    grid-template-columns: 1fr; 
    width: fit-content;
    margin: auto;
    background-color: yellow;
    text-align: left;
    align-items: center;
}

This CSS code creates a box for your text with a yellow background color. The text is aligned to the left within the box and the box adjusts its size according to the text content. It also centers the box on the page, making it visually appealing regardless of the content length. Ensure to remove the inline style "text-align:left;" from the header element to avoid unnecessary duplication.

Answer №3

Remove the inline styling from your

<header style="text-align:left;">

as it is overriding the styles in the CSS file. Simply keep

<header>

Answer №4

It took me a moment to grasp the concept of "centered left-aligned" text.

If my understanding is correct, you are looking for the text to be aligned to the left vertically, but centered horizontally on the page.

If that is indeed what you are aiming for, you can achieve it by centering your inner header tag with the following CSS properties: width: 132px; margin: 0 auto;

Feel free to check out this demonstration on JSFiddle: http://jsfiddle.net/u4sj7/

Answer №5

header h2 { position: absolute; left : 50% /* half of the blue box */; }

Answer №6

                <div class="txtbox">
                  <div class="centerblock">
                    <header style="text-align:left;">
                        <h2>I AM NOT</h2>
                        <h2>AN ARTIST.<h2>
                        <h2>I AM A</h2>
                        <h2>BEAST!</h2>
                    </header>
                  </div>
                </div>

CSS:

.centerblock {
    display:inline-block;
    margin:auto;
}

Answer №7

HTML:

<div class="content container small">
    <div class="txtbox">
        <header>
             <h2>I'm not</h2>
             <h2>just an artist.</h2>
             <h2>I am a</h2>
             <h2>creative beast!</h2>
        </header>
    </div>
    <footer> <a href="#one" class="button style2 down">Read More</a>

    </footer>
</div>

Add this to CSS:

.txtbox header {
    display: block;
    margin: 0 auto;
}

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

Controlling Formatting in ASP.NET

Feeling puzzled by a seemingly simple question with no clear solution in sight. We're attempting to transition an interface to an ASP.NET control that currently appears like this: <link rel=""stylesheet"" type=""text/css"" href=""/Layout/CaptchaLa ...

Craft a backdrop with subtle hints of italics

I am looking to create a unique background for my webpage using HTML and CSS. I want to have repeated italic shades in various shades of blue, red, and white, similar to rectangular shapes. For inspiration, take a look at the design on this website: If n ...

Sharing information between different components in React can be done using props, context, or a

When attempting to edit by clicking, the parent information is taken instead of creating a new VI. I was able to achieve this with angular dialog but I am unsure how to do it with components. This is done using dialog: <div class="dropdown-menu-item" ...

Hover over an element to trigger the background fading effect on the parent div

I'm looking to create a hover effect on an element within a fullscreen div. When I hover over the element, I want a background image to fade in on the div with the class ".section." While I can easily display the background image, I am unsure of how t ...

How to Extract Information from a Table Enclosed in a Div Using HTML Parsing?

I'm new to HTML parsing and scraping, looking for some guidance. I want to specify the URL of a page (http://www.epgpweb.com/guild/us/Caelestrasz/Crimson/) to grab data from. Specifically, I'm interested in extracting the table with class=listing ...

The backend is serving HTML content, but the frontend is not initiating any redirects

After hitting an API endpoint and examining the network call responses, I identified that the HTML response returned with a status code of 302. Despite this, I am perplexed as I do not witness the expected redirect on the user interface. The intended redir ...

What could be causing my website to lose its responsiveness after linking a domain?

Recently, I created a basic website for an event in my town using AWS Amplify from Amazon. Initially, the website was hosted without a custom domain and had a random URL. It worked well on both web and mobile platforms. However, after connecting a custom d ...

Tips for enabling only a single div to expand when the "read more" button is clicked

I'm having trouble with my blog-style page where I want only one "read more" link to expand while collapsing the others. I've tried various jQuery methods and HTML structures, but haven't been able to achieve the desired result. Can someone ...

Problem with Scroll Listener on Image in Angular 4: Window Scroll Functioning Properly

Hello, I am a newcomer who is currently working on creating a small application that allows users to zoom in on an image using the mouse scroll. <img (window:scroll)="onScroll($event) .....></img> The code above works well, however, it detec ...

Looking to add the Ajax response data into a dropdown selection?

Looking to add select options dynamically, but unsure how to retrieve response values. I am able to fetch all the values in the response, but I struggle with appending them correctly in the select option. I believe the syntax is incorrect. success: funct ...

disable border-collapse styling in ASP.NET DataList

Currently, I am new to the world of ASP.NET and I am facing a challenge in styling a DataList. Lately, I have developed a fondness for rounded corners on borders, and I am attempting to incorporate this effect into all my pages by implementing it across al ...

Clicking the button will remove any previously applied CSS style using jQuery

Is there a way to remove the background color that was applied to a previously clicked button when clicking on another button? The current code successfully changes the background color of the clicked button upon hover, but it doesn't reset or remove ...

Div with sidebar that sticks

I am currently working on setting up a website with a sticky sidebar. If you would like to see the page, click this link: On a specific subpage of the site, I am attempting to make an image Validator sticky, but unfortunately, it's not functioning a ...

What are the reasons for not utilizing JSS to load Roboto font in material-ui library?

Why does Material-UI rely on the "typeface-roboto" CSS module to load the Roboto font, even though they typically use JSS for styling components? Does this mix of JSS and CSS contradict their usual approach? ...

Extracting Data from Imgur Videos: Measuring their Duration

Hey there! Lately, I've been faced with the challenge of extracting specific information from videos hosted on the imgur website. Specifically, I'm interested in retrieving the video length indicated in the attached image. Despite my best efforts ...

Issue with ng-pattern validation not functioning correctly on textarea in AngularJS

Attempting to validate a textarea that, if valid, will enable a specific button. Utilizing ngPattern for validation but encountering issues with implementation. Referencing the example code below: <div ng-app="test"> <form name="theForm" ng-contr ...

Placing one element beside another element

I am facing an issue with my layout where I have a list taking up 100% of the height and next to it, I am attempting to place an image box. Here is the fiddle link for reference: https://jsfiddle.net/wrdvkgyj/ Even after setting my image container to inl ...

Capture Video on iOS devices using the MediaRecorder API and display it using HTML5 Video Player

Issue: I am facing an issue where I cannot record video or get a video stream from the camera on iOS through my Angular web application built using ng build. Investigation: In my investigation, I explored various websites that discuss Apple iOS features ...

Identification numbers remain constant

I've been working on a custom CMS blog, specifically designing a page for admin access. My goal is to incorporate pagination into the layout. Currently, the page displays the most recent six posts with IDs ranging from 1 to 6 on the initial view. How ...

showing information on webpage 2 received via query parameters from webpage 1

Hello, I am trying to input text into a textarea and then send the data through a query string to another webpage. My goal is to display the data on the second webpage. I have written the following code, but it doesn't seem to be working. I've ch ...