.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan
Asad Ali
Post New Web Links

Centering an img in a div both horizontally and vertically

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net
 

I realize this is simply an HTML question, but I'm having a difficult figuring out the CSS stuff to center an <img /> tag within a <div> tag.

<div style="width: 180px; height: 180px; padding: 10px; margin-top: auto; margin-bottom: auto;">
  <img src="file" alt="" style="width: 160px; height: 80px;" />
</div>

It centers horizontally just fine, but I cannot get it to center vertically within the div.

Can anyone point out what I'm missing???




View Complete Post


More Related Resource Links

Align spans vertically and horizontally inside a div

  

Hi,

This question is not really about ASP.Net, but since almost all ASP.Net developers know css, I am sure someone will have answer. I have the following html and inline css:

<div id="container" style="height: 34px; width: 100%; border:1px solid #333">
<span id="largeText" style="font-size: 22px">Large text</span>
<span id="smallText" style="font-size: 12px">Small text</span>
</div>

I want to
(1) Vertically align both largeText and smallText in container div
(2) Horizontally largeText will be attached to the left border of container div  and smallText will be attached to the right.

Please help


Breaking news crawing horizontally web part in MOSS site

  

Hi,

I would like to know which approach would be the best to show breaking news which will craws horizontally in MOSS site


center two buttons horizontally in form in C#

  
I have two buttons that are side by side. I want to center them such that they are equal distance from the left and right sides of the form. I want to do this at design time. This was easy to do in VB6. Not sure how to do this in C#.  If this isn't easily done at design time, how do I do this at runtime?      

How to scroll the DataGrid (horizontally) when user drags a column header far left or right?

  
We're working with the WPF DataGrid and I have a question about  dragging column headers: The grid lets the user rearrange the columns, by dragging the column header left or right.  So far, so good. But, sometimes we have many columns, and only the first few columns are visible; so there is a horizontal scrollbar.  In such case, if the user drags a column header to the right edge of the DataGrid window, I want the DataGrid to scroll, automatically, one column at a time.  Is there an easy way to do that? (To be clear: yes, the user can already scroll horizontally by interacting with the horizontal scrollbar, but that isn't what I'm asking about.  I'm asking if the "drag a column header left or right" gesture can cause the DataGrid to scroll left or right.) I guess I could handle various low-level events, but it seems like it shouldn't be necessary -- DataGrid has so much functionality built-in, that I'm guessing it already has the ability to scroll when the user drags the column header to the edge.  So, is there either (a) a property that I can set, to tell the DataGrid to scroll when the user drags a column header to the edge of the window;  or (b) a code example showing how to achieve this effect myself?  Thanks!

Image stretch inside a grid stops working horizontally once columns are added to grid.

  
I have a simple setup of a window. Window contains a grid, inside the grid there is an image. I want the image to always stretch across the entire cell. I've set it's Stretch property to Fill and it works fine, as long there is only one column in the parent grid. As the window is resized, the image stretches correctly. As soon as I add another column, the image stops stretching horizontally. Vertially it works just like before, horizontally it now appears with a fixed width corresponding to the width of the picture used as the source. Does not matter which column it's positioned in, and I've tried encapsulating it into another grid but behaviour does not change. It behaves the same in both Visual studio 2010 designer and at runtime. In addition when I tried to encapsulate it in a second grid, this seond grid also now has altered behavior - instead of sizing itself to it's container (both height and width are not set) as it's parent grid does, it now sizes itself to its contents - the image. But only horizontally. What is going wrong here, is this a bug or am I missing something, and any advice on how I can get the image to fill one of the cells of a grid with more then one column?

How can I change the split view to horizontally again?

  
Hi guys. My split view in visual studio 2008 changed to vertically. How can I change the split view to horizontally again?

Vertical centering for popup

  
I have a hyperlink control that opens a popup window. I need for the popup to be placed to the left of the hyperlink and to have the hyperlink be at the vertical center of the popup, like this:   ======= |    pop    | |     up     |  hyperlink | window  | =======   I can get the popup over to the left of the hyperlink just fine, but I can't get the middle of the popup to align with the hyperlink. I tried offsetting by half the height of the popup, but it didn't work unless I manually specified the height of the popup, which I can't really do due to the dynamic nature of the content. Any ideas?

allign gridview horizontally..

  
 hi, i m new to asp.net , in my application i have to display two records on a single page but not one below other but second record should be at right hand side of first one means i have to allign my grid horizontally not vertically....  if any one has any solution or any article i will be very thankful to him.. thanks in advance. ankur. 

How to stop Sharepoint Top Link Bar Scrolling when you scroll down vertically

  
I have a lot of TAB on my main sharepoint page, and when I scroll down vertically, this Top Link Bar go up and disappear from the screen, what I would like to do is this top link bar still remain the same all the time and only some others contents scroll up and down using vertical scroll bar. Could any one help me , how to do this. Thanks David

SSRS how to expand table horizontally in SSRS

  
I am trying to make a report in SSRS. My requirement is to expend table dynamically instead of vertically..is this possbile in ssrs.

AccordionItem will not resize horizontally to its content

  
The AccordionItem WILL scale vertically to its content, but NOT horizontally.  If you expand down the accordion and then back, it resizes though.  SilverLight does not have this issue, but WPF does...  I see a number of related topics to this, but no solutions that are working for me... plus most the topics are about SilverLight, and this problem has been fixed in SilverLight.  Not sure why it hasn't been fixed in WPF... Here is my template control that will not resize as its content does (btw, the content is a treeview which expands horizontally as sub trees are opened): <Style TargetType="local:AccordionWindow"> <!-- Existing Properties --> <Setter Property="Height" Value="80" /> <Setter Property="HorizontalAlignment" Value="Right" /> <Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="Background" Value="#BBAF1E2D" /> <Setter Property="Foreground" Value="White" /> <Setter Property="BorderBrush" Value="Black" /> <Setter Property="BorderThickness" Value="1,1,0,1" /> <!-- Dependency Properties --> <Setter Property="Header" Value="Toolbar" /> <Setter Property=

AccordionItem will not resize horizontally to its content

  
The AccordionItem WILL scale vertically to its content, but NOT horizontally.  If you expand down the accordion and then back, it resizes though.  SilverLight does not have this issue, but WPF does...  I see a number of related topics to this, but no solutions that are working for me... plus most the topics are about SilverLight, and this problem has been fixed in SilverLight.  Not sure why it hasn't been fixed in WPF... Here is my template control that will not resize as its content does (btw, the content is a treeview which expands horizontally as sub trees are opened): <Style TargetType="local:AccordionWindow"> <!-- Existing Properties --> <Setter Property="Height" Value="80" /> <Setter Property="HorizontalAlignment" Value="Right" /> <Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="Background" Value="#BBAF1E2D" /> <Setter Property="Foreground" Value="White" /> <Setter Property="BorderBrush" Value="Black" /> <Setter Property="BorderThickness" Value="1,1,0,1" /> <!-- Dependency Properties --> <Setter Property="Header" Value="Toolbar" /> <Setter Property="ExpandDirection&

Listview scrolls horizontally to the far right on creation instead of staying at the normal starting

  

I have a listview with a lot of columns, more than 20 anyway.  Because of this, there will always be a horizontal scroll bar visible.  Every column looks like this sample except the bindings are obviously different for each.  No matter what column is the "last", it has the keyboard focus in the TextBox of the Header and forces the listview to scroll all the way to the right.

The default behavior of most listviews is that your at the top left of your collection, leaving the first moves to be either down or right if scrolling is possible.  How do I correct this behavior so that it operates as expected?

 

<ListView.View>
<GridViewColumn >    						
<GridViewColumn.CellTemplate>
  <DataTemplate>
    <TextBox Text="{Binding Path=MyFirstProperty}" HorizontalAlignment="Stretch" Width="138"/>
  </DataTemplate>    						
</GridViewColumn.CellTemplate>
 <StackPanel >
   <TextBlock Text="First Property" VerticalAlignment="Center" />
   <TextBox Width="138" x:Name="tbFirstProp" Text="{Binding FirstProperty, Mode=TwoWay}"/>
   <Button Content="↓" FontFamily="Arial" Command="{Binding UpdateFirstPropertyCommand}" FontSize="14"

Lay out images horizontally

  

Hi

Using Report Builder 3.0 I have a query that can return records along with a number of related images (variable amount).  In a typical layout, the images are about a 1/5 th screen size, and stack up on the right hand side of the screen, as you would expect (using a table).

However doing this creates a large amount of wasted space in the middle/left of the page, meaning the reports are long in length, and wasteful in paper.  The obvious remedy would be to lay the images out horizontally, under each row of text data.  This is where I am struggling - any one any ideas?

 

many thanks


Dynamically Centering a Windows Forms Label Control

  
I'm working on an athletic workout journal application that will include an Interval / Countdown Timer. I plan to build several versions of this application in different technologies (WPF, Web, Phone) but I'm building the first version in Windows Forms. I want the user to be able to dynamically set the size of the "Stopwatch" display font, then resize the form and have the text re-center in the form, taking into consideration the new font size. Stuff like this is easy in HTML, but not so much in Windows Forms. Though I'm still in the early stages I thought I'd share the bit of math that I've come up with and invite any suggestions you might have. Code Snippet using System.Text; using System.Windows.Forms; namespace WorkOutTimer { public partial...(read more)

Centering with WritingMode = Vertical

  

Perhaps I'm missing something, but I've got a few columns that I set the WritingMode property to Vertical so I can fit them better on my report...what I'm not getting is why my centering attempts for those column headers fails.

Steps:
1) Create a report with a column header set to WritingMode = Vertical
2) Set VerticalAlign = Middle  (at this point it LOOKS centered in ReportBuilder 2.x)
3) Save and run the report in a browser.  The header is aligned all the way to the right, not centered.

Am I missing something critical here?


Number2 - (John Nelson)
Microsoft MVP (2009) - System Center Configuration Manager
http://number2blog.com

Centering controls like labels, textboxes

  

Hello Seniors,

 

i have been trying to develop a windows form . i have centered a label on form it runs fine when i open the form but when i try to maximize the form the controls pushed to left of the form . they are not centered. 

 

any help will be appreciated

 

thanks a lot


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend