centering

Why centering with margin 0 auto works with display:block but does not work with display:inline-block ?

梦想与她 提交于 2019-11-27 05:12:19
Just a quick question that was bugging my mind : Why centering with margin:0 auto does work fine with display:block but does not center a div when display is set to display:inline-block Thanks for answers My understanding is as follows (though I am happy to be corrected). Inline elements do not have a width property, and so the "auto" cannot be calculated. Block elements have a width property, so the width of the "auto" can be calculated. Inline-block elements have an outside which acts inline, but an inside which acts like a block. As such, the width set acts more like the width of a word in

Vertically centering text within an inline-block

前提是你 提交于 2019-11-27 02:05:30
问题 I'm trying to create some buttons for a website using styled hyperlinks. I have managed to get the button looking how I want, bar one slight issue. I can't get the text ('Link' in the source code below) to vertically center. Unfortunately there may be more than one line of text as demonstrated with the second button so I can't use line-height to vertically center it. My initial solution was to use display: table-cell; rather than inline-block , and that sorts the issue in Chrome, Firefox and

How can I center Graphics.drawString() in Java?

混江龙づ霸主 提交于 2019-11-27 02:03:47
问题 I'm currently working on the menu system for my Java game, and I wonder how I can center the text from Graphics.drawString() , so that if I want to draw a text whose center point is at X: 50 and Y: 50 , and the text is 30 pixels wide and 10 pixels tall, the text will start at X: 35 and Y: 45 . Can I determine the width of the text before I draw it? Then it would be easy maths. EDIT: I also wonder if I can get the height of the text, so that I can center it vertically too. Any help is

Positioning an element inside the Canvas by its center (instead of the top left corner) using only XAML in WPF

蹲街弑〆低调 提交于 2019-11-27 01:54:15
问题 The common question about positioning an element inside a Canvas is "How to position the center of element (instead of the top left corner)". WPF: Resizing a circle, keeping the center point instead of TopLeft? WPF Center Ellipse at X, Y WPF element positioning on a Canvas Several solutions are presented, but they all have drawbacks. The easiest solution is to accommodate the element size during while setting the Canvas.Left and Canvas.Top properties programmatically. This works, but only

Horizontally centering/evenly distributed <li> inside of <ul> inside a <div>

心不动则不痛 提交于 2019-11-27 01:03:53
问题 Have a Navbar <div> , inside is a <ul> and each <li> contains a <a> with a link (this is for a navigation bar) I looked on google and this site and i couldnt find exactly what i was looking for. What i want is to be able to keep my current style (using <li> with <a> 's inside) and i want the <li> to be evenly distributed and centered (this part comes naturally if they are evenly distributed...) inside the <ul> (which is inside the navbar <div> ). Anyways if that doesnt make sense let me know,

Center Navbar in Twitter Bootstrap 2.0

时间秒杀一切 提交于 2019-11-27 00:55:44
问题 Suppose we have the following markup for navigation bar using Twitter Bootstrap 2.0. <div class="navbar navbar-fixed-top"> <div class="navbar-inner pull-center"> <ul class="nav"> <li class="active"><a href="#">HOME</a></li> <li><a href="#contact">CONTACT</a></li> </ul> </div> </div> What is the best way to center .nav inside navbar-inner ? I only came up with adding my own CSS styles: @media (min-width: 980px) { .pull-center { text-align: center; } .pull-center > .nav { float:none; display

Attributed Text Center Alignment

醉酒当歌 提交于 2019-11-27 00:49:35
问题 I have tried everything but cannot seem to center this text. Can someone please tell me where the error is. NSMutableParagraphStyle *paragraphStyle = NSMutableParagraphStyle.new; paragraphStyle.alignment = NSTextAlignmentCenter; label.attributedText = [[NSAttributedString alloc] initWithString:cell.EventTitle.text attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSParagraphStyleAttributeName:paragraphStyle,NSBaselineOffsetAttributeName : @0,NSFontAttributeName : [UIFont

Twitter Bootstrap: Center Text on Progress Bar

安稳与你 提交于 2019-11-27 00:05:41
问题 I've been using Twitter's bootstrap and I would like the text on the progress bar to be centered on the on bar regardless of value. The below link is what I have now. I would like all text to be aligned with the bottom most bar. Screenshot: I've tried my best with pure CSS and I'm trying to avoid using JS if possible but I'm willing to accept it if it's the cleanest way to do it. <div class="progress"> <div class="bar" style="width: 86%">517/600</div> </div> 回答1: Bootstrap 4.0.0 with utility

Vertically center rotated text with CSS

我们两清 提交于 2019-11-26 23:59:54
问题 I have the following HTML: <div class="outer"> <div class="inner rotate">Centered?</div> </div> div.outer is a narrow vertical strip. div.inner is rotated 90 degrees. I would like the text "Centered?" to appear centered in its container div. I do not know the size of either div in advance. This comes close: http://jsfiddle.net/CCMyf/2/. You can see from the jsfiddle that the text is vertically centered before the transform: rotate(-90deg) style is applied, but is somewhat offset after. This

How do I keep a label centered in WinForms?

扶醉桌前 提交于 2019-11-26 23:58:45
问题 In WinForms I am using a Label to display different messages like success, failure, etc. I'd like to center that label in the center form. I want a solution that will keep it centered whether there's just one word or a whole sentence in the label. 回答1: Set Label 's AutoSize property to False , TextAlign property to MiddleCenter and Dock property to Fill . 回答2: You will achive it with setting property Anchor: None. 回答3: Some minor additional content for setting programmatically: Label