What is the best way to center a paragraph vertically around a particular word?

Within this div, I have a paragraph. I am trying to position a specific word within the paragraph to be centered vertically, but my attempts using a span have been unsuccessful. Is there an easy way to achieve this?

div {
  width: 300px;
  height: 250px;
  border: 1px solid #ccc;
  position: relative;
}

span {
  font-weight: bold;
  display: inline-block;
  vertical-align: middle;

}
<div>
  <p>blah blah blah blah blah blah blah blah blah blah <span>blah</span> blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah</p>
</div>

Answer №1

If you want to center a specific word vertically within a paragraph that is inside a div, you can utilize CSS transformations. Here is a demonstration of how you can accomplish this:

div {
width: 350px;
height: 200px;
border: 2px solid #999;
position: relative;
display: flex;
justify-content: center;
align-items: center;

}

 span {
font-weight: bold;
display: inline-block;
position: relative;
transform: translateY(0%);

}

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

Expanding the navigation bar causes it to reach the second row after being translated

I am currently working on a website that will be dynamically displayed in both English and Spanish. One issue I have encountered is that the longer words in Spanish are causing the navigation bar to spill onto a second row. For more details, please visit: ...

Using jQuery, set a restriction on the total number of options in three dropdown menus to

I am currently facing a challenge with 3 dropdowns, each containing 8 options. My aim is to restrict the total selection across all three dropdowns to 8. For instance, if I choose 7 in the first dropdown, I should only be able to pick 1 in the next two. Si ...

Utilizing CSS and JQUERY for Styling Border radius

Is there a way in jQuery to select specific parts and apply a "border radius"? I've been struggling to use a jQuery selector to achieve this. Is there another method using CSS? I don't want to manually add a "CLASS" to the HTML code to solve th ...

Modifying<strong>superscript</strong> design

Is there a way to change the style of <sup> elements using CSS without removing them from the HTML code? I want to make them look like regular text. Basically, I want the result of <div>Some <sup>random</sup> text.<div> to ...

Position a grid item in the center

Can someone help me with centering my container's item? I am struggling to align the third item to the center using display: grid. Previously, I attempted to use flexbox but found it to be less effective for a responsive layout. .projetos { f ...

Are there any "Undefined" tabs hiding in your RMarkdown tabsets?

After knitting my RMarkdown document to an HTML file, I noticed that the tabs appeared as shown below: https://i.sstatic.net/x1p70.png However, when I save and share the document with my audience, I encounter an issue where these tabs are labeled as "und ...

Error: The function m.easing[this.easing] is not defined

I have been working on creating anchor link scrolling and tooltip display using bootstrap, but I am encountering an issue. $(window).scroll(function(){ if ($(window).scrollTop() >= 100) { $('#header').addClass('fixed'); ...

Unable to modify div style using a JS function

I am attempting to show different divs based on the button clicked, with all starting with a display style of "none" except for one default div called "atualizacoes". After clicking a button, all divs should be set to display="none", and then the specific ...

"Vertical Line Encoding: A Strategy for Improved Data

Can someone help me with a coding issue I'm facing on my website? I am trying to create three vertical lines to separate images in columns, but every time I exit the editor and preview the site, the position of the lines changes. I'm new to HTML ...

switching tabs on a webpage

My PHP page has a menu tab with tabs labeled as Dash and Project. The Dash tab contains a table displaying data. The scenario is that when I click on a row in the table within the Dash tab, it should navigate to the Project tab, where a simple form is disp ...

"An issue with preventing default behavior when clicking on a jQuery element

I need some assistance preventing a JQuery onclick function from scrolling the page to the top. I have tried using preventDefault() without success. You can find the code on this website: Below is the code snippet that I am currently using: $( document ...

Vue multi-page application encounters compilation errors when attempting to include CSS within the <style> elements

Within my MPA app, I have integrated vue.js as a vital component. Below is a simple test setup: the relevant sections of my template .... <div id='app-basket-checkout'> <h1>Expecting Something Special</h1> </div> ... ...

How to make a drop-down select list remain open even after selecting an option

In my current project, I have a dropdown box that holds a list of files which can be deleted. The user needs to select the file they want to delete from the dropdown each time and then the process repeats for every file. I would like to implement a feature ...

The inner division appears to have a larger bottom margin than expected

Can anyone explain why the .slot or .card classes in this code have a larger margin at the bottom compared to the top? Appreciate any help, Link to JsFiddle: http://jsfiddle.net/Tighttempo/LgeAf/ <div id="hand"> <div class="card" id="card1" ...

What's the best way to make sure my table fits perfectly within its container's width?

I've encountered an issue with a table: If you want to see how the table was created, check it out on jsFiddle I attempted to modify the CSS like this : table{ width:100%; } td span { float:right; width:20%; text-align:center ...

Using data attributes to store HTML content within Reactjs components

I am struggling to understand how one can utilize HTML within a data attribute in React's jsx. For example: data-bs-template='<div class="tooltip d-none d-md-block" role="tooltip"><div class="arrow">< ...

Navigating through pages without using Javascript

While working on creating page numbers, I stumbled upon this intriguing CodePen: https://codepen.io/p-ziegler/pen/bmdaaN .b, input[type="radio"] { display: inline-block; width: 16px; height: 16px; vertical-align: middle; } .b { back ...

Is there a disparity in how the mandatory field validator functions in Edge compared to Chrome?

https://i.sstatic.net/qUzDN.pngThere doesn't seem to be any red color https://i.sstatic.net/EqHyW.png How can I ensure consistency? Both elements should either have color or none at all. <form action=""> <input id="email" type="email ...

The background image vanishes in Chrome when scrolling downwards

After setting an image with a resolution of 1980 x 1200 as the background for my web page, I encountered an issue. When scrolling down, around the height of 1200px, the image disappears and is replaced by a white background. This problem only occurs in Chr ...

How can I incorporate a fade opacity effect into my Div scrolling feature?

I successfully implemented code to make div elements stick at the top with a 64px offset when scrolling. Now, I am trying to also make the opacity of these divs fade to 0 as they scroll. I am struggling to figure out how to achieve this effect. Below is ...