How to horizontally center a div-block containing images? [duplicate] - html

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 9 years ago.
I'm trying to horizontally center a div-block containing images (playing cards placed there by Javascript), but somehow it doesn't work (images are still left-aligned). Here's the HTML:
<div id="dealerarea">
<div id="dealercards">
<!--Images by Javascript-->
</div>
</div>
And here's the CSS:
#dealerarea{
position:absolute;
width:100%;
height:96px;
top:15px;
}
#dealercards{
display: block;
margin-left: auto;
margin-right: auto;
}
What i'm doing wrong? Thanks in advance!
Edit: I can't give a fixed "width" to inner div, because it changes every time (depending on the number of card images).

You need to give your #dealercards a width and margin:0 auto ;
#dealercards
{
display: block;
margin:0 auto;width:200px;
}
DEMO HERE

Related

How to place item center [duplicate]

This question already has answers here:
How do I vertically align text in a div?
(34 answers)
How can I horizontally center an element?
(133 answers)
Closed 2 years ago.
I am trying to put a div in the middle of another div, but always left aligns it.
How I do it easily?
<div>
<div>
<p>This I want center</p>
</div>
</div>
The question is answered with the easiest google search, but the most obvious way is to give them CSS classes and then style them with CSS
<div class="parent">
<div class="child">
<p>Centred</p>
</div>
</div>
And in CSS
.parent{
display: grid;
place-items: center;
background-color: red;
}
.child{
background-color: blue;
}
If it's just text you can use:
text-align: center;
If you want to align the div, give to the div you want to center a margin:auto, but make sure to give it a width first, otherwise it will not work. For example:
width: 500px;
margin: auto;

Align element in div [duplicate]

This question already has answers here:
Center one and right/left align other flexbox element
(11 answers)
Center flex items with one at the end of the row [duplicate]
(3 answers)
Closed 3 years ago.
I have a div that contains two divs inside. First div has to be aligned to the left , second div has to be
aligned to the center relatively parent div.Please could you help me .Here is my jsfiddle : https://jsfiddle.net/armakarma/zy3L9a7h/
html
<div class='test'>
<div class='logo'>logo</div>
<div class='title'> title </div>
</div>
css
.test{
display:flex;
border:1px solid black;
}
.title{
margin: 0 auto;
}
.logo{
width:160px;
border:1px solid red;
}

How do I center a DIV with no parent? [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
How do you easily horizontally center a <div> using CSS? [duplicate]
(22 answers)
Best way to center a <div> on a page vertically and horizontally? [duplicate]
(30 answers)
Closed 4 years ago.
I want to center my form in the center of teh horizontal row it is in. I thought this would be as simple as
#control {
text-align: center;
}
The element I want to center is
<div id="control" class="btn">
<div id="btn_container"><img width="100" height="100" src="https://cdn3.iconfinder.com/data/icons/minecraft-icons/512/Stone_Pickaxe.png" alt="Mining pick" /></div>
<span>Start</span>
</div>
However, the element is still not being centered -- https://jsfiddle.net/xwdnvcy5/58/ . I'm not getting something really obvious, but I can't tell what it is.
This one is not very intuitive, but try setting the margin to 0 auto.
#control {
margin: 0 auto;
}
The answer is quite simple actually. You need to set the margin-left/right as auto.. like this:
#control {
margin: 0 auto;
}
Are you try to center the #control div?
Try this
#control {
position:relative;
left: 50%;
transform: translateX(-50%);
}

vertically align text within itself [duplicate]

This question already has answers here:
How do I vertically center text with CSS? [duplicate]
(37 answers)
Closed 6 years ago.
I have an h3 with a height of 100%. Therefore the height is unknown. How can I center the text within itself? For the sake of the example, I have given the parent fixed dimensions but this is not the case. I have tried using vertical align but that doesn't work, I believe I may need to change the display to do that?
I don't want to center the text within its parent, I know various methods to do this. I want to know if it is possible to vertically center it within itself. The text needs to be 100% in both dimensions so that the link fills the parent div.
.unknowndimensions{
height:300px;
width:300px;
}
.unknowndimensions h3{
height:100%;
width:100%;
background:#f7f700;
text-align:center;
}
<div class="unknowndimensions">
<h3>Title</h3>
</div>
Using table method,
.unknowndimensions{
height:300px;
width:300px;
}
.unknowndimensions a{
display:table;
width:100%;
height:100%;
}
.unknowndimensions h3{
display:table-cell;
vertical-align:middle;
background:#f7f700;
text-align:center;
}
<div class="unknowndimensions">
<h3>Title</h3>
</div>

How do i place an image in the centre of a page horizontally? [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 7 years ago.
Currently I have everything on the left hand side of the page. But I would like to begin changing it to the middle (just horizontally). But as i'm a beginner, each time i try it doesn't turn out right. Could someone with more experience help?
html:
<div class="iphonecontainer">
<img class="iphone" src="untitled.jpg" align="left">
</div>
css:
.iphonecontainer
{
width:100%;
float:left;
margin-top:6.5%;
}
.iphone {
display:block;
width: 400px;
margin: 0;
padding: 0;
}
Thanks for taking the time to help, have a good day!
Change
margin: 0;
To
Margin: 0px auto;
Update. Sorry yes remove the align: left.
.iphonecontainer
{
width:100%;
text-align:center;
margin:6.5% auto;
}