how to align absolute child's vertical position to parent div - html

I'm trying to make the child divs (option-info) stay just below the parent div but also give them 100% width.
Now the children are centered and have 100% but aren't positioned relative to the parent div. Is there a way to give the child div absolute width but relative positioning vertically in CSS and HTML? Thanks in advance!
Here's the HTML:
<div id="container">
<div class="option-container">
<div class="header">hardware</div>
<div class="option-info">test</div>
</div>
<div class="option-container">
<div class="header">design</div>
<div class="option-info">test</div>
</div>
<div class="option-container">
<div class="header">software</div>
<div class="option-info">test</div>
</div>
<div class="option-container">
<div class="header">gaming</div>
<div class="option-info">test</div>
</div>
</div>
Here's the CSS:
.header {
display: inline-block;
position: relative;
background-color: rgb(81, 154, 226);
font-size: 2.3em;
height: 100px;
color: white;
font-family: 'saira', arial;
text-shadow: 2px 2px #2280dd;
width: 250px;
text-align: center;
text-transform: uppercase;
margin: auto;
top: 70px;
-webkit-box-shadow: 0px 12px 60px -17px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 12px 60px -17px rgba(0,0,0,0.75);
box-shadow: 0px 12px 60px -17px rgba(0,0,0,0.75);
z-index: 1;
line-height: 100px;
}
#container {
text-align: center;
width: 100%;
}
.option-container {
display: inline-block;
width: 250px;
margin: 22px 22px 100px 22px;
}
.option-info {
display: inline-block;
position: absolute;
width: 100%;
font-family: 'roboto', arial;
font-size: 1.3em;
text-align: center;
right: 0;
left: 0;
}

Would something like this work for you? I took the option-info element out of the HTML and used the :after pseudo to insert the text in the desired (if I understood correctly) location.
.header {
display: inline-block;
position: relative;
background-color: rgb(81, 154, 226);
font-size: 2.3em;
height: 100px;
color: white;
font-family: 'saira', arial;
text-shadow: 2px 2px #2280dd;
width: 250px;
text-align: center;
text-transform: uppercase;
margin: auto;
top: 70px;
-webkit-box-shadow: 0px 12px 60px -17px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 12px 60px -17px rgba(0,0,0,0.75);
box-shadow: 0px 12px 60px -17px rgba(0,0,0,0.75);
z-index: 1;
line-height: 100px;
}
#container {
text-align: center;
width: 100%;
}
.option-container {
display: inline-block;
width: 250px;
margin: 22px 22px 100px 22px;
position: relative;
}
.option-container:after {
width: 100%;
position: absolute;
padding: 10px 0;
content: 'test';
bottom: -120px;
left: 0;
z-index: 9999;
font-family: 'roboto', arial;
font-size: 1.3em;
text-align: center;
}
<div id="container">
<div class="option-container">
<div class="header">hardware</div>
</div>
<div class="option-container">
<div class="header">design</div>
</div>
<div class="option-container">
<div class="header">software</div>
</div>
<div class="option-container">
<div class="header">gaming</div>
</div>
</div>

So I tried restructuring the HTML and this is what I came up with, and this is exactly what I was looking for!
<div class="option-container">
<div class="header">hardware</div>
<div class="info-container">
<div class="option-info">test</div>
</div>
</div>
<div class="option-container">
<div class="header">design</div>
<div class="info-container">
<div class="option-info">test</div>
</div>
</div>
<div class="option-container">
<div class="header">software</div>
<div class="info-container">
<div class="option-info">test</div>
</div>
</div>
<div class="option-container">
<div class="header">gaming</div>
<div class="info-container">
<div class="option-info">test</div>
</div>
</div>
And I just changed two things with the CSS:
.info-container {
position: absolute;
width: 100%;
right: 0;
left: 0;
height: 100%;
}
.option-info {
display: inline-block;
position: relative;
width: 100%;
font-family: 'roboto', arial;
font-size: 1.3em;
text-align: center;
color: black;
color: rgba(0, 0, 0, 0.9);
margin: auto;
top: 100px;
}
EDIT: I appreciate the answers, but it seems I fixed my own problem.

Related

why does my image mix with my navigation bar

When i scroll on the website the image and nav bar mix together. The image goes through the navigation bar
and it looks like the background of the navigation bar is the image.
i put the position of the nav bar fixed and the z-index 1 and the div of the image position relative and z-index 0
<div class="header-top">
<span class="br">BR</span><span class="arch"> Architects</span>
<div class="meny">
Projects
About
Contact
</div>
</div>
<div id="home">
<div class="image">
<img src="skyscraper.jpg" alt="">
</div>
</div>
</html>
.header-top{
box-shadow: 0px 5px 8px -2px rgba(0,0,0,0.75);
position: fixed;
width: 100%;
top: 0;
left: 0;
padding: 6px 0px;
z-index: 1;
}
.meny{
float: right;
word-spacing: 26px;
padding: 0px 25px 0px 0px;
}
.meny-link{
color: black;
text-decoration: none;
letter-spacing: 3px;
}
.br{
padding: 0px 0px 0px 10px;
font-weight: bold;
}
#home{
position: relative;
top: 23px;
z-index: 0;
}
.image img{
width: 100%;
height: 675px;
}
You can simply add background: white; to .header-top if you don't want it being transparent.
Here's an example:
.header-top{
box-shadow: 0px 5px 8px -2px rgba(0,0,0,0.75);
position: fixed;
width: 100%;
top: 0;
left: 0;
padding: 6px 0px;
z-index: 1;
background: white;
}
.meny{
float: right;
word-spacing: 26px;
padding: 0px 25px 0px 0px;
}
.meny-link{
color: black;
text-decoration: none;
letter-spacing: 3px;
}
.br{
padding: 0px 0px 0px 10px;
font-weight: bold;
}
#home{
position: relative;
top: 23px;
z-index: 0;
}
.image img{
width: 100%;
height: 675px;
}
<div class="header-top">
<span class="br">BR</span><span class="arch"> Architects</span>
<div class="meny">
Projects
About
Contact
</div>
</div>
<div id="home">
<div class="image">
<img src="https://www.tommasocimarelli.com/wp-content/uploads/2020/01/skyscraper-manhattan.jpg" alt="">
</div>
</div>
Try to write a big number into property z-index to navbar like 99

Row of <div> elements will not align to the center [duplicate]

This question already has answers here:
How do I center floated elements?
(12 answers)
Closed last year.
I've read a hundred posts about how to center a row of divs, but I can't seem to get this to work. I want these elements to align to the center of their container, while maintaining a gap between each of them. No matter what I seem to do, they hug the left.
Do I need to change the CSS on the container element, or the individual div items themselves?
Help!
.news_section {
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
.news_container {
border: 1px red solid;
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.news_item { position: relative; float: left; font-family: graphik-light; font-size: 1.1em; margin: 25px 25px 25px 0px; width: 220px; height: 400px; cursor: pointer; transition: all 0.2s ease-out;
-webkit-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
-moz-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
box-shadow: 0px 3px 10px 1px rgba(204, 204, 204, 1);
}
.news_item:hover { background: #efefef; transform: scale(1.04); transition: all 0.2s ease-in; cursor: pointer; }
.news_img {
width: 100%;
height: 100%;
object-fit: contain;
}
.news_header { font-family: 'Oswald', sans-serif; font-size: 22px; line-height: 1.4em; text-align: left; margin-top: 18px; margin-left: 14px; margin-right: 14px; }
.news_outlet { font-size: 13px; text-align: left; margin-top: 7px; margin-left: 14px; color: #c1c1c1; font-family: graphik-regular; text-transform: uppercase; }
.news_subtext { font-size: 14px; text-align: left; margin-top: 20px; margin-left: 14px; margin-right: 14px; color: #4d5051; font-family: graphik-regular; }
.news_more { position: absolute; bottom: 10px; font-size: 16px; margin-left: 14px; color: #000; font-family: 'Oswald', sans-serif; }
<section class="news_section">
<div class="news_container">
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
</div>
</section>
On the news_item ... Change that
float: left;
to
display: inline-block;
.news_section {
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
.news_container {
border: 1px red solid;
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.news_item { position: relative; display: inline-block; font-family: graphik-light; font-size: 1.1em; margin: 25px 25px 25px 0px; width: 220px; height: 400px; cursor: pointer; transition: all 0.2s ease-out;
-webkit-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
-moz-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
box-shadow: 0px 3px 10px 1px rgba(204, 204, 204, 1);
}
.news_item:hover { background: #efefef; transform: scale(1.04); transition: all 0.2s ease-in; cursor: pointer; }
.news_img {
width: 100%;
height: 100%;
object-fit: contain;
}
.news_header { font-family: 'Oswald', sans-serif; font-size: 22px; line-height: 1.4em; text-align: left; margin-top: 18px; margin-left: 14px; margin-right: 14px; }
.news_outlet { font-size: 13px; text-align: left; margin-top: 7px; margin-left: 14px; color: #c1c1c1; font-family: graphik-regular; text-transform: uppercase; }
.news_subtext { font-size: 14px; text-align: left; margin-top: 20px; margin-left: 14px; margin-right: 14px; color: #4d5051; font-family: graphik-regular; }
.news_more { position: absolute; bottom: 10px; font-size: 16px; margin-left: 14px; color: #000; font-family: 'Oswald', sans-serif; }
<section class="news_section">
<div class="news_container">
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
</div>
</section>
Better still, take a look at flex-box: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
If you want to align all items to the center, you need to use Flexbox. Basically, you gotta add this code to align everything of your container in center:
CSS:
.container: {
display: flex; /* flexbox */
justify-content: center; /* horizontal center */
align-items: center; /* vertical center */
}
This is an excelent article about Flexbox, made by W3School:
W3School - CSS Flexbox

How can I add spacing between these progress bar titles?

THIS IS A RESPONSIVE DESIGN, MAKE SURE TO TURN ON TOGGLE DEVICE TOOLBAR ON YOUR BROWSER
I am trying to make a progress bar. First I want to increase the height of the transparent black background. I can't find a way to do that. I am confused. And secondly, I want to add spacing and align the 2nd and 3rd text properly.
/* progress bar */
.center {
height: 300px;
width: 100%;
position: absolute;
left: 50%;
margin-top: 140px;
transform: translate(-50%, -50%);
padding: 20px;
background-color: rgba(0, 0, 0, 0.678);
box-shadow: 0 2px 60px rgba(0, 0, 0, .5);
border-radius: 10px;
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 20px 0;
}
/* skillbar languages */
.skillbar-html p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-html p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skillbar-css p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-css p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skill_percentage{
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<div class="skillbar-html">
<p>HTML</p>
<p>90%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;"></div>
</div>
<div class="skillbar-css">
<p>CSS</p>
<p>70%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;"></div>
</div>
<div class="skillbar-javascript">
<p>JavaScript</p>
<p>50%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;"></div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</section>
</section>
You can take advantage of the <br> element in your HTML.
Line break and tab elements can be used when you need a little more control over how the browser renders the text. The <BR> element is used to force a line break.
-W3.org
/* progress bar */
.center {
height: 300px;
width: 100%;
position: absolute;
left: 50%;
margin-top: 140px;
transform: translate(-50%, -50%);
padding: 20px;
background-color: rgba(0, 0, 0, 0.678);
box-shadow: 0 2px 60px rgba(0, 0, 0, .5);
border-radius: 10px;
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 20px 0;
}
/* skillbar languages */
.skillbar-html p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-html p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skillbar-css p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-css p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skill_percentage{
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<br>
<div class="skillbar-html">
<p>HTML</p>
<p>90%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;"></div>
</div>
<br>
<div class="skillbar-css">
<p>CSS</p>
<p>70%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;"></div>
</div>
<br>
<div class="skillbar-javascript">
<p>JavaScript</p>
<p>50%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;"></div>
</div>
</div>
</div>
</div>
</div>
</section>
The Height: - I noticed a fixed height of 300px, and that you were centering the parent div by using margins and translations in your CSS. I went ahead and removed those margins and translations, also removed your absolute positioning. You can adjust your fixed height of 300px to expand the grey background. For this example, I made it 100 view height.
/* progress bar */
.center {
height: 100vh;
width: 100%;
padding: 20px;
position: relative;
background-color: rgba(0, 0, 0, 0.678);
box-shadow: 0 2px 60px rgba(0, 0, 0, .5);
border-radius: 10px;
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 20px 0;
}
/* skillbar languages */
.skillbar-html p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-html p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skillbar-css p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-css p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skill_percentage{
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<br>
<div class="skillbar-html">
<p>HTML</p>
<p>90%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;"></div>
</div>
<br>
<div class="skillbar-css">
<p>CSS</p>
<p>70%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;"></div>
</div>
<br>
<div class="skillbar-javascript">
<p>JavaScript</p>
<p>50%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;"></div>
</div>
</div>
</div>
</div>
</div>
</section>
If I understood properly, what you want to increase the height is for that black bar containing your actual progress bar, right? If that's the case, I think this should work:
.skill-percentage {
height: x (here you place how much height you want);
}
That should give you the height that you want.
And, in order to add the spacing, you can take advantage of CSS padding or margin, depending on what you exactly need.
I'll give you a small snippet here so you can see exactly what I mean. Note that I modified a bit your HTML to fit what you wanted to do, but this may not be necessary on your original file.
/* progress bar */
* {
margin: 0;
padding: 0;
}
.center {
height: 500px;
width: 100%;
background-color: rgba(0, 0, 0, 0.678);
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 0;
}
/* skillbar languages */
.text-container {
display: flex;
width: 100%;
justify-content: space-between;
}
.text-container p {
padding: 0 40px; /* this is the one that changes the position of your text. Be carefull, you don't want this to change the position too much, just a bit, if you need to change the full position, better try something like grid, or modifying the flex */
}
.skillbar-html {
display: flex;
flex-direction: column;
justify-content: center;
}
.skillbar-html p {
margin: 10px;
}
.skillbar-html > div {
margin: 10px;
}
.skillbar-css {
display: flex;
flex-direction: column;
justify-content: center;
}
.skillbar-css p {
margin: 10px;
}
.skillbar-css > div {
margin: 10px;
}
.skillbar-javascript {
display: flex;
flex-direction: column;
justify-content: center;
}
.skillbar-javascript p {
margin: 10px;
}
.skillbar-javascript > div {
margin: 10px;
}
.skill_percentage{
height: 20px; /* this is the one that changes your height, now it's changing nothing, but you can modify the height by changing this value */
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<div class="skillbar-html">
<div class="text-container">
<p>HTML</p>
<p>90%</p>
</div>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;">
</div>
</div>
</div>
<div class="skillbar-css">
<div class="text-container">
<p>CSS</p>
<p>70%</p>
</div>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;">
</div>
</div>
</div>
<div class="skillbar-javascript">
<div class="text-container">
<p>JavaScript</p>
<p>50%</p>
</div>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;">
</div>
</div>
</div>
</div>
</section>

Issue in fixing Name tag near image

<ul class="child ">
<div style="text-align:right;"> <li class="nameBar">{{patientInfo.data.fname}} {{patientInfo.data.lname}}</li></div>
<li class="age">{{patientInfo.data.age}}|{{ patientInfo.data.gender}}</li>
<img class="breadcrumb-image" src="assets/images/user/user6.jpg" alt="...">
<li class='uhid'>UHID: {{patientInfo.data.uhid}}</li>
<li class="address">{{patientInfo.data.city}}</li>
</ul>
CSS:
.nameBar{
color:#00bcd4;
font-weight:bold;
margin: -7px 0px 0px -100px;
position: absolute;
font-size: 12px;
text-transform: capitalize;
}
.uhid{
margin:-39px 0px 0px 58px;
color:#00bcd4;
font-weight:bold;
font-size: 12px;
}
.age{
margin: 15px 0px 0px -35px;
font-size: 10px;
position: absolute;
}
.address{
margin: 4px 0px 0px 59px;
font-size: 10px;
}
.child {
position: fixed;
top: 72px;
left: 50px;
padding: 1em;
margin: 0px 0px 0px 571px;
}
.li{
border-width: 1px;
text-align:center;
float:left;
}
Always I need to start the name from right side of the image I tried with margin-right:calc(50% -(somePx)) not able to fix that name lable near the image as right side Uhid and place can any help me out in this thanks
it's not a good idea to use too much margins and absolute positioning.
take a look at this and change it to your needs.
.child {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 1em;
display: flex;
justify-content: center;
}
.child>img {
width: 40px;
height: 40px;
margin: 0 5px;
}
.nameBar {
text-transform: capitalize;
}
.bold {
color: #00bcd4;
font-weight: bold;
font-size: 12px;
}
.small {
font-size: 10px;
}
.left,
.right {
line-height: 20px;
padding-top: 5px;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
<div class="child">
<div class="right">
<div class="nameBar bold">John Doe</div>
<div class="age small">26 Male</div>
</div>
<img src="https://picsum.photos/40" alt="...">
<div class="left">
<div class='uhid bold'>UHID: 1234</div>
<div class="address small">Paris</div>
</div>
</div>

How to neatly place the ranking to the left of a picture in CSS

Currently, my HTML looks like
However, I want to make it look similar to where the picture and ranking don't overlap.
This is my CSS and HTML for the element.
.star-list {
display: flex;
align-items: center;
padding: 5px;
width: 680px;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0px 10px 20px -6px #1abc9c;
background-color: #fff;
border-radius: 10px;
height: 155px;
margin-top: 20px;
margin-left: 10px;
margin-bottom: 10px;
font-size: 5vw;
}
.star-list>img {
height: 140px;
border-radius: 10px;
}
.star-list>.media-content {
width: 1000px;
display: flex;
justify-content: center;
font-weight: 600;
font: black;
font-size: 5vw;
}
<div class="card_body">
<div>
<div class="card word_shadow2">
<div class="card-header">
RANKING
</div>
<div class="card-body" id="star-box">
<div class="star-list">
1
<img src="https://api.buzzanglemusic.com/images/artists/771" alt="Placeholder image" />
<span class="media-content">
Eagles
</span>
</div>
</div>
</div>
</div>
</div>
I would like the ranking to not overlap with the picture. Thanks.
.star-list {
display: flex;
align-items: center;
padding: 5px;
width: 680px;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0px 10px 20px -6px #1abc9c;
background-color: #fff;
border-radius: 10px;
height: 155px;
margin-top: 20px;
margin-left: 10px;
margin-bottom: 10px;
font-size: 5vw;
}
.star-list p.rank {
padding: 0 50px;
font-weight: 700;
}
.star-list>img {
height: 140px;
border-radius: 10px;
}
.star-list>.media-content {
width: 1000px;
display: flex;
justify-content: center;
font-weight: 600;
font: black;
font-size: 5vw;
}
<div class="card_body">
<div>
<div class="card word_shadow2">
<div class="card-header">
RANKING
</div>
<div class="card-body" id="star-box">
<div class="star-list">
<p class="rank">1</p>
<img
src="https://api.buzzanglemusic.com/images/artists/771"
alt="Placeholder image"
/>
<span class="media-content">
Eagles
</span>
</div>
</div>
</div>
</div>
</div>
I just enclosed the ranking number in a p tag and then gave it an id and then set the left and right margins to 40px.
.star-list {
display: flex;
align-items: center;
padding: 5px;
width: 680px;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0px 10px 20px -6px #1abc9c;
background-color: #fff;
border-radius: 10px;
height: 155px;
margin-top: 20px;
margin-left: 10px;
margin-bottom: 10px;
font-size: 5vw;
}
.star-list > img {
height: 140px;
border-radius: 10px;
}
.star-list > .media-content {
width: 1000px;
display: flex;
justify-content: center;
font-weight: 600;
font: black;
font-size: 5vw;
}
#ranking {
margin-right: 40px;
margin-left: 40px;
}
<div class="card_body">
<div>
<div class="card word_shadow2">
<div class="card-header">
RANKING
</div>
<div class="card-body" id="star-box">
<div class="star-list">
<p id="ranking">1</p>
<img
src="https://api.buzzanglemusic.com/images/artists/771"
alt="Placeholder image"
/>
<span class="media-content">
Eagles
</span>
</div>
</div>
</div>
</div>
</div>
img { /* reasonable defaults site-wide */
display: block;
width: 100%;
height: auto;
}
picture {
display: block; /* inline by default :/ */
}
.parent {
display: flex;
flex-direction: row;
align-items: center;
border: 1px solid red;
padding: 10px;
}
.parent picture {
max-width: 150px; /* let the image parent determine it's size */
margin: 0 10px; /* just to give a little space between text */
}
<div class='parent'>
<h3 class='rank'>10</h3>
<picture>
<img src='https://placehold.it/600x300'>
</picture>
<h2 class='name'>#sheriffderek</h2>
</div>
So, anything within a parent - can be organized with flex - as long as they are direct children! Fun!!!