Vertical alignment of text within a center位置

My current project involves creating a website layout similar to this:

I am facing difficulty in centering the text within the box like this:

This is my progress so far:

@font-face {
    font-family: 'Trend Sans 004'; /*a name to be used later*/
    src: url('fonts/Trend Sans W00 Four.ttf'); /*URL to font*/
}

... more CSS code here ...
<!DOCTYPE html> 

<!DOCTYPE html>
<html lang="en">
<head>

  <!-- Basic Page Needs
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta charset="utf-8">
  <title>Cupid's Cafe & Bakery</title>
 
   ... more HTML code here ...
  
  </head>
<body>

 ... more HTML code here ...

  <hr width="100%">
  
  </div>

<!-- End Document
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>

I am aiming to ensure that the text is perfectly centered within the box. Also, I want to maintain consistent spacing between the header, paragraphs, and HR even when resizing the window.

Answer №1

Here is my suggestion:

1) Enclose your aa within two containers :

<div id="aa-outer-container">
  <div id="aa-inner-container>
    <div id="aa">
      <h5>The Bakery</h5></br>
      <p>Looking for a cozy spot to enjoy a good book or get some work done? The Bakery is the perfect hideaway offering delicious lunch options and expertly brewed beverages.</p>
      <hr align="left" >
    </div>
  </div>
</div>

2) Include the following CSS :

#boxRowTxt {
    position : relative;
}

#aa-outer-container {
    width: 100%;
    height: 100%;
    position : absolute;
    display: table;
}

#aa-inner-container {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

#aa {
    text-align: left;
    display: inline-block;
}

#aa h5 {
    margin-bottom: 1rem;
}

#aa p {
    margin-bottom: 1.5rem;
}

This solution should resolve your issue!

For a demonstration, check out this Fiddle too!

Answer №2

Check out this helpful solution: here

@font-face {
    font-family: 'Trend Sans 004'; /*to be used later*/
    src: url('fonts/Trend Sans W00 Four.ttf'); /*Font URL*/
}


@font-face {
    font-family: 'Utopia Regular'; /*to be used later*/
    src: url('fonts/utopia-regular.ttf'); /*Font URL*/
}

@font-face {
    font-family: 'Trend Sans 001'; /*to be used later*/
    src: url('fonts/Trend Sans W00 One.ttf'); /*Font URL*/
} 

/* Skeleton V2.0.4
* © 2014, Dave Gamache 
*/ 
 
/* Grid */
.container {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box; 
}
.column,
.columns {
  width: 100%;
  float: left;
  box-sizing: border-box; }

@media (min-width: 400px) {
  .container { width: 85%; padding: 0; }
}

@media (min-width: 550px) {
  .container { width: 80%; }
  .column,
  .columns { margin-left: 4%; }
  .column:first-child,
  .columns:first-child { margin-left: 0; }
  /* Styles for various column widths and offsets... */
}

/* Base Styles */
html { font-size: 62.5%; }
body { background-color:#C8D7DC; }
/* Typography styles - h1 to h6, paragraphs */
h1, h2, h3, h4, h5, h6 { font-weight: 300; }
p { margin-top: 0; }

/* Buttons & Forms styling */
.button,
button,
input[type="submit"],
...
  
<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
  <title>Unique Title Here</title>
  <meta name="description" content="Brief Description">
  <meta name="author" content="">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  
  <link rel="stylesheet" href="normalize.css">
  <link rel="stylesheet" href="styles.css">
  

  <link rel="icon" type="image/png" href="images/favicon.png">

</head>
<body>

  <div class="container">
  
  <div class="row">
  <div class="twelve columns" id="header">
  Page Header
  </div>
  </div>
  
  <div class="row">
  <div class="twelve columns" id="content">
  Main Content Goes Here
  </div>
  </div>
  
  
  <div class="row" id="footer"><div class="twelve columns">Footer Section</div></div>
  
  </div>


</body>
</html>

Answer №3

If you're looking to increase the space in your #boxRowTxt, one option is to use padding-top and padding-bottom. I have made some adjustments for you by commenting out a few lines and adding new ones. Make sure to set both values to the same number to maintain the center alignment of the content.

#boxRowTxt {
font-family:'Utopia Regular';
box-shadow:0px 0px 0px 3px #806239 inset;
width: 48%;
color:#163764;
position:static;
/*height: 0;*/
/*padding-bottom: 48%;*/
    /*Keep the padding on top and bottom the same*/
    padding-bottom: 4%;
    padding-top: 4%;

font-size:1.7vw;   
}

Answer №4

If you need to cater to different browsers, using flexbox is a fantastic solution!

<div id="aa">
  <h5>The Cafe</h5>
  <p>Escape to our cozy cafe which offers a peaceful environment to unwind, work, or simply enjoy a good book. Don't forget to sample our mouthwatering lunch items and expertly crafted hot beverages.</p>
  <hr align="left">
</div>

Include the following in the #aa CSS rule (consider changing it to a class)

#aa {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}

Answer №5

To center the text in the #aa div, simply add text-align:center; to it. If you only want to apply this style to one of the #aa boxes instead of both, consider wrapping another div around the specific box you want to target and applying the style there.

@font-face {
    font-family: 'Trend Sans 004'; /*a name to be used later*/
    src: url('fonts/Trend Sans W00 Four.ttf'); /*URL to font*/
}


@font-face {
    font-family: 'Utopia Regular'; /*a name to be used later*/
    src: url('fonts/utopia-regular.ttf'); /*URL to font*/
}

@font-face {
    font-family: 'Trend Sans 001'; /*a name to be used later*/
    src: url('fonts/Trend Sans W00 One.ttf'); /*URL to font*/
}


/*
* Skeleton V2.0.4
* Copyright 2014, Dave Gamache
* www.getskeleton.com
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* 12/29/2014
*/


/* Table of contents
––––––––––––––––––––––––––––––––––––––––––––––––––
- Grid
- Base Styles
- Typography
- Links
- Buttons
- Forms
- Lists
- Code
- Tables
- Spacing
- Utilities
- Clearing
- Media Queries
*/


/* Grid
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.container {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box; }
.column,
.columns {
  width: 100%;
  float: left;
  box-sizing: border-box; }

/* For devices larger than 400px */
@media (min-width: 400px) {
  .container {
    width: 85%;
    padding: 0; }
}

/* For devices larger than 550px */
@media (min-width: 550px) {
  .container {
    width: 80%; }
  .column,
  .columns {
    margin-left: 4%; }
  .column:first-child,
  .columns:first-child {
    margin-left: 0;
    }

  .one.column,
  .one.columns                    { width: 4.66666666667%; }
  .two.columns                    { width: 13.3333333333%; }
  .three.columns                  { width: 22%;            }
  .four.columns                   { width: 30.6666666667%; }
  .five.columns                   { width: 39.3333333333%; }
  .six.columns                    { width: 48%;            }
  .seven.columns                  { width: 56.6666666667%; }
  .eight.columns                  { width: 65.3333333333%; }
  .nine.columns                   { width: 74.0%;          }
  .ten.columns                    { width: 82.6666666667%; }
  .eleven.columns                 { width: 91.3333333333%; }
  .twelve.columns                 { width: 100%; margin-left: 0; }

  .one-third.column               { width: 30.6666666667%; }
  .two-thirds.column              { width: 65.3333333333%; }

  .one-half.column                { width: 48%; }

  /* Offsets */
  .offset-by-one.column,
  .offset-by-one.columns          { margin-left: 8.66666666667%; }
  .offset-by-two.column,
  .offset-by-two.columns          { margin-left: 17.3333333333%; }
  .offset-by-three.column,
  .offset-by-three.columns        { margin-left: 26%;            }
  .offset-by-four.column,
  .offset-by-four.columns         { margin-left: 34.6666666667%; }
  .offset-by-five.column,
  .offset-by-five.columns         { margin-left: 43.3333333333%; }
  .offset-by-six.column,
  .offset-by-six.columns          { margin-left: 52%;            }
  .offset-by-seven.column,
  .offset-by-seven.columns        { margin-left: 60.6666666667%; }
  .offset-by-eight.column,
  .offset-by-eight.columns        { margin-left: 69.3333333333%; }
  .offset-by-nine.column,
  .offset-by-nine.columns         { margin-left: 78.0%;          }
  .offset-by-ten.column,
  .offset-by-ten.columns          { margin-left: 86.6666666667%; }
  .offset-by-eleven.column,
  .offset-by-eleven.columns       { margin-left: 95.3333333333%; }

  .offset-by-one-third.column,
  .offset-by-one-third.columns    { margin-left: 34.6666666667%; }
  .offset-by-two-thirds.column,
  .offset-by-two-thirds.columns   { margin-left: 69.3333333333%; }

  .offset-by-one-half.column,
  .offset-by-one-half.columns     { margin-left: 52%; }

}


/* Base Styles
...

...
<body>

<!-- Primary Page Layout
...

</body>
</html>

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

Need assistance with CSS layout: How to extend a div to the bottom of the page

I am currently working on a design layout that includes a 'header' section with a logo and links, as well as a content area that should extend to the bottom of the page. However, I am facing some challenges in achieving this. Initially, I enclos ...

Invoke a bounded function within an Angular directive using the ng-click event

I was wondering if it's possible to invoke a bound function within a directive by clicking on a specific part of a div. Currently, I have a div with an inner div that acts as a button for expanding the main div. The larger div has a directive associat ...

Is the absence of http(s) in <link ...> causing any issues?

I recently noticed a peculiar link on the Font Awesome homepage that seems to work without including http or https. <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> This made me wonder, what does // a ...

I am curious about this "normalize.less" that appears in the F12 Developer Console

Trying to track down information on this mysterious "normalize.less" that is appearing in the Chrome 76 developer console has proven to be a challenge for me. In Firefox 69's console, it displays bootstrap.min.css instead, leading me to believe that i ...

Determine the row index by identifying the row id and table id

I need to retrieve the Index number of a row when a hyperlink is clicked, while also passing additional data from this tag. <a href="javascript:void(0);" onclick="EditDoctorRow(' + RowCountDoctorVisit + ');"> <i class="fa fa-edit"&g ...

Tips for optimizing the placement of div elements for top advertisements on Amazon's website

I'm looking to overlay some divs on top of Amazon.com ads, similar to the image above. This is part of a personal project where I need to position these divs precisely over the ads. To achieve this effect, I've been using getBoundingClientRect t ...

Clicking the button to send the form using JavaScript

Currently, I am dealing with a shopping cart plugin that relies on a basic form on the product page to send values such as price and product name. However, I am facing an issue where this plugin uses a standard submit button to transmit the values, and I w ...

Retrieve information from a MySQL database and integrate it into a different application

This php script is used to generate a table with a "book" button next to each row. The goal is to extract the values of "phase" and "site" from the specific row where the "book" button is clicked, and transfer them to another form (in "restricted.php") fo ...

Is it possible to display a thumbnail image in a separate full-sized window by using CSS or JavaScript?

I am currently utilizing a program called WebWorks 2020.1 that automatically creates <img> tags from my FrameMaker source input when published to DHTML. Unfortunately, I do not have the ability to directly modify the HTML <img> or <a> tag ...

How to center a span using Twitter Bootstrap

As a newcomer to Twitter Bootstrap, I'm wondering how I can center a span within a parent row. Currently, I am working with Twitter Bootstrap Version 2.3 instead of 3.1. In version 3.1, there is a center-block feature that I cannot utilize in 2.3. Th ...

Creating a table in VueJs and populating it with values retrieved from an MSSQL database in a .NET Core web application

I am developing a table within a .NET Core Web Application that includes multiple rows and columns filled with data retrieved from a MSSQL server through a WEB API Given the need for numerous rows and columns, I am considering using a for loop inside my & ...

How to create a CSS animation that gradually darkens a background image during a

Currently in the process of constructing a page with an intriguing background image: body { background:url(images/bg.png) center center no-repeat fixed; -webkit-background-size:cover; -moz-background-size:cover; -o-background-size:cover; ...

it will still function properly regardless of the width being set to zero

Is anyone able to explain the strange phenomenon I am experiencing with this code snippet? In this particular example, I have set the width of selector h3 to 0. However, when viewing it in IE 9 using F12 development tools, I can see that the width is indee ...

Executing a YUI function via HTMLJSGlobal called is feasible

Recently, I stumbled upon the Dial example on the official YUI website and was thoroughly impressed. I managed to get the function working perfectly in a JS file, but now I am facing issues trying to call it within the HTML page with specific parameters su ...

A Step-by-Step Guide on Adding Content After the Bootstrap Slider Using Absolute Position

Check out my project here: I'm currently working on a bootstrap carousel that has absolute positioning and a z-index of -1. However, I'm facing an issue where I can't figure out how to place a div right after the carousel. I've tried s ...

Unusual images emerge following certain elements in this unique gallery

Looking for some advice on my image gallery created using an ordered list. The issue I'm facing is that the images are not all the same size, causing the 4th and 7th images to disrupt the layout. I have come up with a solution by using: ...

Is it possible to determine which child element is currently in view within a scrollable parent div?

In an attempt to replicate a "current page" feature using divs, similar to a PDF reader. document.addEventListener("DOMContentLoaded", function(event) { var container = document.getElementById("container"); container.onscroll = function() { let ...

What strategies work well for guiding individuals to different destinations based on their user roles, such as administrators and regular users?

In my CMS environment, I am facing a challenge with redirecting users who are not administrators or do not own the document they're trying to edit. The following code snippet is what I have implemented, but it seems that my administrators cannot acces ...

Facing a minor HTML syntax error while attempting to configure metatags in Ruby on Rails

I'm attempting to incorporate social tags into my site, such as Tweet count, Facebook recommendations, and their respective numbers. In the app/views/application/_ogmeta.html.erb file, I have only included one line: <meta property="og:title" cont ...

How to prevent CSS styles from being overridden by SASS in a stylesheet

When working with a Sass file, I encountered an issue with the way styles were being output. The original style in the Sass file looked like this: .style{ width: calc(100%); } However, when compiled to its corresponding CSS file, the output was: .style{ ...