Aligning <div> in vertically center [duplicate] - html

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Vertically centering a div inside another div [duplicate]
(24 answers)
Best way to center a <div> on a page vertically and horizontally? [duplicate]
(30 answers)
vertical align middle in <div>
(11 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 4 years ago.
I cannot align #container and its content in the center vertically. I thought adding further <div> tags would be a problematic and I cannot control them.
I want the text and #container to be aligned in the center of .content vertically without adding any extra space.
#container {
display: grid;
padding: 20px;
grid-template-areas: 'sideone sideone sidetwo sidetwo sidethree sidethree';
grid-gap: 20px;
text-align: center;
}
.content {
display: table;
margin: 15px;
height: 500px;
width: 100%;
transition-duration: 0.15s;
border: 2px solid #3B3B3B;
}
<div class="content">
<div id="container">
<div style="grid-area: sideone;">
<p>あ - ა</p>
<p>い - ი</p>
<p>う - უ</p>
<p>え - ე</p>
<p>お - ო</p>
</div>
<div style="grid-area: sidetwo">
<p>か - კა</p>
<p>さ - სა</p>
<p>た - ტა</p>
<p>な - მა</p>
<p>は - ჰა</p>
</div>
<div style="grid-area: sidethree">
<p>き - კი</p>
<p>し - ში</p>
<p>ち - ჩი</p>
<p>に - ნი</p>
<p>み - მი</p>
</div>
</div>
</div>

add margin:0px auto; into .content and it should align it to the center of the container.
it should loook something like this:
.content {
display: table;
margin: 15px;
height: 500px;
width: 100%;
transition-duration: 0.15s;
border: 2px solid #3B3B3B;
margin:0px auto;
}

Related

How to center a element into a div into another div [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Center one and right/left align other flexbox element
(11 answers)
Closed 10 months ago.
.header_main_page_portal {
background-color: white;
height: 80px;
width: 100%;
}
.image_login_portal {
width: 500px;
}
.image_login_portal img {
margin: auto;
display: block;
}
.title_main_page {
justify-content: center;
display: flex;
margin: 0 auto;
width: 100%;
}
<div class="header_main_page_portal">
<div class="image_login_portal">
<img src="http://127.0.0.1:8000/storage/diba/images/logo-portal.png" class="logo-nav_portal_main_page" alt="logo-client">
</div>
<div class="title_main_page">
<h6>PÀGINA PRINCIPAL</h6>
</div>
</div>
I have a div that acts as a header, occupying 100% of the width of the screen.
Inside this div, I have another one with the logo on the left side.
Next to this I have another div with an h6 centered inside this last div.
My problem is that the title div starts when the photo ends, so the h6 doesn't appear centered on the screen. Although it is inside the div.
<div class="header_main_page_portal">
<div class="image_login_portal">
<img src="XXXX" class="logo-nav_portal_main_page" alt="logo-client">
</div>
<div class="title_main_page">
<h6>MAIN PAGE</h6>
</div>
</div>
Thanks!! :D

Div side by side with variable size, but always filling 100% [duplicate]

This question already has answers here:
How to make a div fill a remaining horizontal space?
(26 answers)
Fill the remaining height or width in a flex container
(2 answers)
Closed 2 years ago.
I have two divs that I want to put side by side in a container. The problem I am having is that the left div has a veriable size depending on the content and the right div should use all available space.
<style>
div.left {
display: inline-block;
outline-width: 0;
background-color: yellow;
padding-right: 5px;
}
div.right{
display: inline-block;
max-width: 100%;
outline-width: 0;
background-color: green;
}
.container{
background:black;
width:450px;
}
</style>
<div class="container">
<div class="left">
LEFT
</div>
<div class="right">
RIGHT
</div>
</div>
I tried with flex, table-cell, ... - almost everything. What am I missing?
display: flex would do the job if you also assign flex:1 to the .right div, so it will take all the remaining space:
div.left {
background: peachpuff;
padding: 10px;
}
div.right{
flex: 1;
background-color: yellowgreen;
padding: 10px;
}
.container{
background:black;
display: flex;
width:450px;
}
<div class="container">
<div class="left">
Variable content here
</div>
<div class="right">
remaining space
</div>
</div>

Margin auto is not centering [duplicate]

This question already has answers here:
How do I center floated elements?
(12 answers)
How can I horizontally center an element?
(133 answers)
How can I vertically center a div element for all browsers using CSS?
(48 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
I'm just wondering why margin auto isn't working? my parent div margin auto works but my inner margin auto is not in center.
.rankings_page{
width: 750px;
background-color: #f5f5f5;
margin: auto;
height: 800px;
}
.tab-group {
margin: auto;
}
.toggle_btn{
background-color: blue;
float: left;
width: 30%;
text-align: center;
cursor:pointer;
}
<div className="rankings_page">
<div className="tabgroup">
<div className="toggle_btn">
Country
</div>
<div className="toggle_btn">
City
</div>
</div>
</div>
</div>
Thanks!
The margin: auto trick only works if you want to horizontally center your elements. It will not work to vertically center your elements, because of how CSS deals with vertical margins differently.
You should use CSS flexbox instead: it is specifically made to allow layouts like this possible:
display: flex;
align-items: center;
justify-content: center;
Also, you need to update the tabgroup selector, because there is no - in the class in your markup. See proof-of-concept example:
.rankings_page {
width: 750px;
background-color: #f5f5f5;
height: 800px;
display: flex;
align-items: center;
justify-content: center;
}
.tabgroup {
display: flex;
}
.toggle_btn {
background-color: blue;
cursor: pointer;
}
<div class="rankings_page">
<div class="tabgroup">
<div class="toggle_btn">
Country
</div>
<div class="toggle_btn">
City
</div>
</div>
</div>

How to vertically align inline element and inline-block element [duplicate]

This question already has answers here:
Vertically align text next to an image?
(26 answers)
How can I vertically align elements in a div?
(28 answers)
Why can't the <p> tag contain a <div> tag inside it?
(6 answers)
Closed 3 years ago.
Say I have the following code
p {
display: inline;
}
div {
display: inline-block;
width: 100px;
height: 50px;
background: black;
}
<p>
Some text
<div>
</div>
</p>
What is created is this
Here the inline and inline-block elements are not vertically centered.
How would I make it look like this :
I have used flex css and also add one new div
I hope this will help you.
p {
display: inline;
margin: 0;
}
.inner-div {
display: inline-block;
width: 100px;
height: 50px;
background: black;
}
.outer-div{
display: flex;
align-items: center;
display: -webkit-flex;
-webkit-align-items: center;
}
<div class="outer-div">
<p>Some text</p>
<div class="inner-div"></div>
</div>
just add float left to tag
p{
display: inline;
float:left;
}
This will align both element properly

How to align element in div, Horizontally and Vertically with Flex [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Closed 5 years ago.
How do I center a div inside another div? What about an image? I want it centered vertically and horizontally. I want to be modern and use flex - I don't care about old IE support.
.outside {
background: orange;
width: 400px;
height: 300px;
}
.inside {
width: 80%;
background: yellow;
}
<div class='outside'>
<div class='inside'>
This is the inside div that I would like to center in the outer one
</div>
</div>
---------------------------------------------------------------------------
<div class='outside'>
<img src="http://placehold.it/350x150">
</div>
Vertically centering in CSS is always trickier than it should be. Here is a simple solution that uses Flex. Flex does not work in all browsers!
A width is required in order to center horizontally.
I know there are lots of similar questions, but I believe this method is quick and simple.
.outside {
background: orange;
width: 400px;
height: 300px;
/* This is the magic*/
display: flex;
justify-content: center; /* This centers horizontally */
align-items: center; /* This centers vertically */
}
.inside {
width: 80%; /* Without a width, horizontally aligning "doesn't work"*/
background: yellow;
}
<div class='outside'>
<div class='inside'>
This is the inside div that I would like to center in the outer one
</div>
</div>
---------------------------------------------------------------------------
<div class='outside'>
<img src="http://placehold.it/350x150">
</div>