What is the best way to align the content of an HTML page in the center using

I'm currently working on a basic webpage and I'm trying to center it using only Bootstrap code (if possible). This is what I have tried so far, but the col-xl-offset-4 doesn't seem to be working.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="jumbotron">
    <div class="row vertical-center-row">
      <div class="col-xl-6 col-xl-offset-4">
        <h1 class="text-primary text-center">Marcell Treville</h1>
        <h3 class="text-center"><em>This is a tribute page for the legendary painter "Marcell Treville"</em></h3>
        <div class="thumbnail">
          <img src="">
          <p>this is some text describing the image</p>
          <h2>Here's a timeline of Dr. Marcell Treville</h2>
          <ul>
            <li><strong>1995</strong> item one</li>
            <li>item one</li>
            <li>item one</li>
            <li>item one</li>
            <li>item one</li>
            <li>item one</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

Greetings! You can achieve center alignment without using offsets by including the "text-center" class within this div:

HTML

<div class="col-xl-6 text-center"> .... </div>

I hope this solution proves beneficial to you!

Answer №2

To achieve a total of 12 columns, it is recommended to offset by 3 units instead of 4. This arrangement would result in 3 'empty' columns followed by a div occupying the next 6 columns, and finally concluding with 3 more 'empty' columns. The current layout seems to be distributed as 4-6-2 columns which can be adjusted to the desired 3-6-3 configuration.

Answer №3

To achieve center alignment in Bootstrap v4, simply use row justify-content-center.

Reference:

https://i.sstatic.net/2zKaI.png

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

<div class="container">
  <div class="jumbotron">
    <div class="row justify-content-center">
      <div class="col-6">
        <h1 class="text-primary text-center">Marcell Treville</h1>
        <h3 class="text-center"><em>This is a tribute page for the legendary painter "Marcell Treville"</em></h3>
        <div class="thumbnail">
          <img src="">
          <p>this is some text describing the image</p>
          <h2>Here's a timeline of Dr. Marcell Treville</h2>
          <ul>
            <li><strong>1995</strong> item one</li>
            <li>item one</li>
            <li>item one</li>
            <li>item one</li>
            <li>item one</li>
            <li>item one</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</div>

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

Is it possible for JavaScript to access and read a local file from a web page hosted locally

I am interested in using html, css, and javascript to develop a user interface for configuring a simulation. This interface will be used to generate a visualization of the simulation and an output parameters file based on multiple input files. It is impor ...

Content extends beyond the navigation bar despite attempts to use word-wrap or word-break

Currently, I am in the process of making my website responsive. This involves ensuring that the navigation bar moves along with the screen when resized. I am working on getting the CSS to wrap to the next line when the browser is resized. * { padding ...

Ways to induce scrolling in an overflow-y container

Is there a way to create an offset scroll within a div that contains a list generated by ngFor? I attempted the following on the div with overflow-y: @ViewChild('list') listRef: ElementRef; Then, upon clicking, I tried implementing this with s ...

Maintaining Proper Header Dimensions

Having some issues with aligning my fixed widget and floating navigation. The fixed widget is not respecting the height of the floating navigation and is appearing at the top when in its fixed position. I'm currently using "Q2W3 Fixed Widget" for the ...

Tips for moving a specific menu item to the right in bootstrap 4

Currently, I am integrating Bootstrap 4 into a Laravel 8 blog platform that I am working on. While the menu items are correctly positioned, I am facing an issue where I need to move the last menu item to the right. Despite trying various options like ml- ...

The font color fails to change when hovering over

I'm experiencing an issue with the styling of my input box. When the user starts typing, a div containing a list of possible clubs is displayed. Currently, I am having trouble with the .clubLink:hover class and its background color. CSS: <style& ...

I am looking to generate div elements using JavaScript to avoid the tedious task of individually creating numerous divs

Instead of manually typing out multiple div tags in the HTML, I would like to dynamically generate them using JavaScript and display them on the page. Below is an attempt at achieving this, but it appears to not be functioning correctly. var arr = {}; f ...

two adjacent DIV elements with matching heights

Currently, I am in the process of developing an internal web page with a wrapper DIV structure based on recommendations from an online tutorial. Within this wrapper, there are different sections including a header, mainnav, content, sidenav, and footer. Th ...

Is using display:table an effective approach for achieving equal height columns?

I am currently working on a responsive design project and I need two columns of equal height. I do not want to rely on JavaScript for this, and I prefer having some whitespace between the columns to enhance readability. I have tried two different layouts; ...

Learn how to design a div with an arrow pointing upwards that contains content. Utilize HTML and CSS to create this unique visual element. Each arrow should have a hover effect that only activates when hovering over

I attempted this previously with just an arrow image, but due to the rectangular shape of the div section, the area without the arrow remains hoverable. Is there a method to customize the div to mirror the image below, ensuring that only the arrow is clic ...

I'm having trouble adjusting the background color in the bootstrap template

------------ I am customizing the bootstrap SB Admin template for my asp.net core Identity project. However, I am facing an issue with changing the background color of the template and the navigation menu color. Even though I can see the color changes when ...

The CSS styles are not being completely applied to the PHP function

My current task involves dealing with multiple folders containing images. When a link is clicked on the previous page, a unique $_GET variable is sent and processed by an if statement, triggering a function to search for and display all pictures within the ...

Struggling with the toggle functionality in the Boostrap Nav Bar?

My bootstrap navbar is not functioning properly when I switch to mobile size and click the expand button. Could this issue be due to using the wrong classes for bootstrap 5 instead of bootstrap 4? <nav class="navpaddingy navbar navbar-expand-lg ...

What is the best way to arrange two images next to each other using HTML and CSS in order to effectively utilize a specified width?

I am trying to display two different images side by side within a DIV element that is exactly 800px wide. The images may have varying widths and heights, with some being wider than tall and others taller than wide. I have attempted to place both images i ...

The chosenValues.filter method hit an unexpected token; a comma was anticipated

I have encountered a syntax error in the following line: queryComponents: prevState.seletedValues.filter((a, i) => (i !== index)); I am attempting to swap out splice with filter. I've attempted modifying brackets, both adding and removing them, b ...

HTML5 number input type formats long numbers differently

In my application, users are required to enter a minimum of 15 digits in a number input field. However, if a user enters a longer number, for example, equal to or greater than 19 digits, and then uses the arrow buttons or keyboard keys, the number is auto ...

Aligning form fields using CSS and Bootstrap 4

I am struggling to center a form on my page. The labels are centered, but the input with the form-control class is not cooperating. Currently, it appears like this... [EDIT: I have identified that the display: block; within form-control is causing the is ...

Only conceal the breadcrumb trail on the 404 error page

I have recently created a custom node for my site's 404 page with the path /node/83 in the site information. However, I am facing an issue where I cannot hide the .breadcrumb element using display:none. I attempted to achieve this through CSS injector ...

Name values not appearing in dropdown list

Looking for some assistance with displaying a list of names in a dropdown menu using Angular. The dropdown is present, but the names from my array are not appearing. I think it might be a simple fix that I'm overlooking. I'm new to Angular, so an ...

Personalized Angular dropdown menu

Recently, I've started delving into angularJS and I'm eager to create dropdowns and tabs using both bootstrap and angular. Although there is a comprehensive angular bootstrap library available, I prefer not to use it in order to gain a deeper und ...