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

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

Related

Inline images alignment/spacing in HTML/CSS [duplicate]

This question already has answers here:
Center one and right/left align other flexbox element
(11 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 1 year ago.
I have the following HTML/CSS code which results in two images Logo.jpeg and Banner1.jpg to be on the same line, one after the other.
I would like to put space between the two, resulting Banner1.jpg to be centered, while Logo.jpeg should stay aligned to the left.
Tried several solutions like margin-left/margin-right, padding, align and others with no avail.
HTML
.logo h1 {
font-size: 40px;
margin: 20px 0;font-weight: 400;
display: inline-block;
}
.logo h2 {
font-size: 40px;
margin: 20px 0;font-weight: 400;
display: inline-block;
}
<div class="site-branding-area">
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="logo">
<h1><img src="img/Logo.jpeg" height="725" width="200"></h1>
<h2><img src="img/Banner1.jpg" height="150" width="350"></h1>
</div>
</div>
Can anyone help me understand how to fix it so to have Logo.jpeg align to the left and Banner1.jpg centered?
Thanks, take the chance to wish you a good day, Michele
You could make the .logo container a CSS Flexbox so both the images are aligned in a row. Then use justify-content to define how the browser should distribute space between the flex items along the main-axis (ie x-direction). Next, you can center the second image by selecting the .logo h2 container which holds the nested <img> and applying auto left and right margins to evenly center it on the page.
Now the sidebar image is aligned to the left of the viewport and the banner image is centered. Try this out.
.logo h1 {
font-size: 40px;
margin: 20px 0;font-weight: 400;
display: inline-block;
}
.logo h2 {
font-size: 40px;
margin: 20px auto;
font-weight: 400;
display: inline-block;
}
.logo {
display: flex;
align-items: center;
justify-content: space-between;
}
img {
max-width: 100%;
}
<div class="site-branding-area">
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="logo">
<h1><img src="https://horizon-media.s3-eu-west-1.amazonaws.com/s3fs-public/field/image/whale-wave.jpg" height="725" width="200"></h1>
<h2><img src="https://images.squarespace-cdn.com/content/v1/52e1b262e4b06ef060506756/1568644386677-SJGPE3UI0QRLVFE2GK8G/ke17ZwdGBToddI8pDm48kGwqNa-TSATgABi909OK27Z7gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z5QPOohDIaIeljMHgDF5CVlOqpeNLcJ80NK65_fV7S1UQSxQa_pE67Ig1CszvlZo11NCLvqIlshiNC_JCcjnOmqOV4zqrbdg_2AqIEjj1Z3Fg/Hero.jpg?format=1500w" height="150" width="350"></h1>
</div>
</div>
you may add this css with your css and test
.logo {
display: flex;
justify-content: space-around;
}

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>

what is the best way to flex align two items right and one left [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 3 years ago.
This image given below is the result I am looking for.
So i have the html as follows
<div class="container">
<div class="content1">1</div>
<div class="content2">2</div>
<div class="content3">3</div>
</div>
here container is set to display: flex
I wanted to align the divs as follows.
I can give justify-content: space-between
but how to align the centre div closer to 3 with 10px distance from it
I have several containers which is aligned row by row. so, in the end, it should look like this as image shown below
I have given margin-left to div 2 but it doesn't order correctly with different div having different width
You can add another div around the 2 on the right, and then use margin to create space around all of the div's
.container{
display:flex;
justify-content: space-between;
background: grey;
width: 400px;
height: 400px;
}
.content1,
.content2,
.content3{
background: green;
width: 50px;
height: 50px;
margin: 10px;
}
.align{
display:flex;
}
<div class="container">
<div class="content1">1</div>
<div class="align">
<div class="content2">2</div>
<div class="content3">3</div>
<div>
</div>

Aligning <div> in vertically center [duplicate]

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;
}

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>