logo
down
shadow

How can I avoid hard coding line height while vertically centering element in a div?


How can I avoid hard coding line height while vertically centering element in a div?

Content Index :

How can I avoid hard coding line height while vertically centering element in a div?
Tag : html , By : pacorro2000
Date : December 01 2020, 04:55 PM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Vertically Centering Inline Content Using line-height


Tag : css , By : Carlos Galdino
Date : March 29 2020, 07:55 AM
I wish this help you I'm trying to vertically center some text besides two image links. I've done this dozens of times before but for some reason it isn't working right now.
img{
 vertical-align:middle;
}

Centering border-right vertically with height and line-height doesn't work


Tag : html , By : user130518
Date : March 29 2020, 07:55 AM
wish of those help line-height should be set to ul and reset to normal to li.
For li to follow line-height, they must: not float and be formatted as an inline boxe (either inline-block or inline-table) wich triggers a proper layout.
 ul.lang {
     float: left;
     height: 40px;
     list-style:none;
     background:orange;
     line-height: 40px;
     padding:0 5px
 }
 ul.lang li {
     display:inline-block;/*no float*/
     vertical-align:middle;/* align from baseline/line-height of parent or highest box aside */ 
     line-height:1.2em;/* reset line-height to regular value */
 }
 ul.lang li:first-child {
     padding-right: 6px;
     border-right: 1px solid black;
 }
 ul.lang li:last-child {
     padding-left: 6px;
 }
 ul.lang li a {
     text-decoration: none;
     font-size: 12px;
     color: black;
 }

Line height gap - not centering content vertically


Tag : css , By : Big Ant
Date : March 29 2020, 07:55 AM
I wish did fix the issue. It has to do with the rendered font size. You can set the font size of the container to 20px which will allow for the text baseline to center to the height of your inner block. If you look at this fiddle, you see the difference between a block with the font size and without the font size.
The main reasoning for this is that line-height is a text property, and made to effect textual elements. It can be bent to work in other situations, though.
<div style="height: 60px; width: 200px; line-height: 60px; display: inline-block; border: 1px solid #0f0; box-sizing: border-box; font-size: 20px;">
    <div style="display: inline-block; height: 20px; width: 40px; line-height: 40px; border: 1px solid #f00; box-sizing: border-box;"></div>
</div>

Vertically centering element to it's siblings height


Tag : css , By : Pieter Taelman
Date : March 29 2020, 07:55 AM
help you fix your problem You can use nested flexbox with media queries.
Make each anchor link as flexbox.
.container a {
  display: flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 768px) {
  .container a {
    flex-direction: column;
  }
}
body {
  margin: 0;
}
.parent {
  background-image: url("http://bossfight.co/wp-content/uploads/2016/04/boss-fight-free-high-quality-stock-images-photos-photography-trees-forest-mist.jpg");
  background-size: cover;
  flex-wrap: wrap;
  height: 100vh;
  position: relative;
}
.parent h1 {
  margin-top: 0;
  padding-top: 2em;
  text-align: center;
  font-family: helvetica;
}
.container {
  display: flex;
  align-items: center;
  justify-content: center;
  /* align-content: center; */
  position: absolute;
  bottom: 2em;
  width: 100%;
}
.child {
  padding: 0 5px;
}
.container img {
  /* float: left; */
}
.container a {
  opacity: 0.5;
  display: flex;
  align-items: center;
  justify-content: center;
}
.container a:hover {
  opacity: 1;
}
@media (max-width: 768px) {
  .container a {
    flex-direction: column;
  }
}
<div class="parent">
  <h1>Heading example</h1>
  <div class="container">
    <div class="child">
      <a href="_top">
        <img src="http://placehold.it/90x90" alt="ux-button">
        <img src="http://placehold.it/150x40" alt="ux-button">
      </a>
    </div>
    <div class="child">
      <a href="_top">
        <img src="http://placehold.it/90x90" alt="ux-button">
        <img src="http://placehold.it/150x40" alt="ux-button">
      </a>
    </div>
    <div class="child">
      <a href="_top">
        <img src="http://placehold.it/90x90" alt="ux-button">
        <img src="http://placehold.it/150x40" alt="ux-button">
      </a>
    </div>
  </div>

Centering stacked up absolute element + centering flex column vertically to window height


Tag : html , By : Tornike
Date : March 29 2020, 07:55 AM
This might help you Make body display: flex;, and set .welcome-screen to flex-grow: 1;, and your icons on the left will be centered vertically. Then set flex-wrap: wrap; on body and width: 100%; on .intro-section for that section to display underneath .welcome-screen. Then add position: relative to .headline and add top: 50%; left: 50%; transform: translate(-50%,-50%); to your h1 and it will center over the svg.
body, html {
  margin: 0;
  font-family: 'Work Sans', sans-serif;
  box-sizing: border-box;
}
body {
  display: flex;
  flex-wrap: wrap;
}
.welcome-screen {
  background-color: Lightblue;
  background-size: cover;
  height: 90vh;
  margin: 3.5em;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
}
.side-buttons {
  float: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.side-buttons img {
  height: 2em;
  padding: 0.5em 0 0.5em 0.5em;
  display: block;
}
.side-buttons a {
  text-decoration: none;
}
.headline {
  display: block;
  width: 100%;
  position: relative;
}
.headline img {
  width: 50%;
  position: relative;
}
.headline h1 {
  z-index: 99;
  margin: 0;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
}
nav {
  text-align: center;

}
nav a {
  color: white;
  text-decoration: none;
}
nav a:hover {
  color: black;
}
.headline {
  text-align: center;
}

.intro-section {
  height: 300px;
  background-color: grey;
  width: 100%;
}
<body>
<!-- header section -->
  <!-- side buttons -->
  <div class="side-buttons">
    <a href="http://pinterest.com/">
      <img src="http://placehold.it/40x40" alt="pinterest icon">
    </a>
    <a href="http://facebook.com/">
      <img src="http://placehold.it/40x40" alt="facebook icon">
    </a>
    <a href="http://twitter.com/">
      <img src="http://placehold.it/40x40" alt="twitter icon">
    </a>
  </div>
  <!-- end of side buttons -->
  
<section class="welcome-screen">
  <div class="headline">
    <h1>The time is</h1>
    <img src="css/assets/now.svg" alt="now">
  </div>

  <nav>
    <a href="">intro</a>
    <a href="">gallery</a>
    <a href="">services</a>
    <a href="">contact</a>
  </nav>
</section>
<!-- end of header section -->

<section class="intro-section">

</section>

</body>
Related Posts Related QUESTIONS :
  • how to fix link tag in html after changing css
  • How do I add a top padding to the second row?
  • Is it possible to split XML into multiple HTML pages with page navigation?
  • AngularJS: responsive height in bootstrap
  • Hide second line of text with CSS
  • repeating-linear-gradient not working in Edge browser and internet Explorer Browser
  • how to make search and form category merges like amazon on bootstrap
  • Bootstrap: Rearranging rows into columns and changing the order of elements
  • How can I move a label under a text box?
  • How save LinearGradient To database
  • How to reposition an image with a linear gradient using css?
  • HTML audio will not play when page opened by batch file
  • CSS Three Tone Diagonal Background
  • How to use slots inside of template components in HTML
  • Using span tags in meta description & title, for dual languages
  • How to make an icon/span selectable by pressing Tab key?
  • Add dynamic margins using UI Kit
  • Add margin-top to textbox
  • What is the correct semantic HTML markup for a title (book, movie, etc.), according to the spec? Is it an <em> tag
  • How to make an animation in Geoserver or in Leaflet
  • Buttons overlapping when shrinking window
  • Stretch an element to the end of the automatically calculated grid, not just the explicit grid
  • What relation is there between Angular's <ng-content> and ShadowDOM
  • CSS background for div element is not working
  • CSS Marquee: multiple paragraphs overlaps
  • I want to align search bar to extreme right
  • Getting blank white space to the left of content inside pre tags
  • My viewer.html won't load any css and jss files
  • How to apply multiple styles to HTML to only part of a title?
  • Want to make text div transparent on a parallax area
  • Is there a way to make this ID plus descendants CSS rule less specific?
  • Is there a way to drop in a stylesheet to get a Material theme or similar for all form elements on the page?
  • How do I make a sideways L look in html/css?
  • Why won't the color #e67d22e1 display in Safari?
  • How to select specific tag's attribute value with xPath?
  • How to make div rows fill available height
  • How to fix text inside a block that grows
  • svg hexagon halftone pattern
  • How to edit a website's element's background colors using a chromium extention
  • What is the main tag in HTML5 ? How does it differ from body tag?
  • My image is flowing out from my div column. How I can fix it and made the image full-size into div
  • How to draw line in react
  • Why Transition css is not working in child selector css
  • How to modify materialize css select option?
  • How to center some text in a rectangle in CSS?
  • How do I equally space out css grid columns?
  • How to make sure all the parts of a macro are running correctly?
  • How to adjust the zoom of website at different browser at different screen size?
  • Can't set max height on child div properly
  • Why background color is not applying to DIV container?
  • Need to select the first-child
  • No space between attributes in buttons
  • How can I block google from crawling my page, but still let Baidu do it?
  • Rendering html content in matToolTip (Angular)
  • Embedding an iframe when iframe height is variable
  • How to use 'word-break: break-word' with link inside of text?
  • How I can animate circular progress bar from left to right?
  • Angular 6 - How can I hide a div onclick of outside of that div
  • How to fill an inline-block div with a solid color?
  • Form file doesn't align with rest of form
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com