How to fit in small box title and subtitle use css - html

I work with dynamicaly created boxes, and i have issues that text are not fiting inside box.
EX:
My code:
HTML:
<div class="box" id="box98" style="width: 110px; height: 43px;">
<div class="machine-icon" id="machine98" style="background-color: green;">
<img src="https://via.placeholder.com/150/">
</div>
<div class="title-box">SOME WERY BIG DATA 1345135131421124</div>
<div class="desc-box">SUB DATAqfqwfqwf</div>
</div>
CSS:
.box {
background-color: #ccc;
margin: 10px;
border-radius: 10px;
text-align: center;
font-size: 10px;
}
.machine-icon {
vertical-align: middle;
float: left;
width: 40px;
height: 40px;
background-color: #808080;
border-radius: 20px;
margin: 2px;
}
.machine-icon > img {
margin-top: 25%;
width: 20px;
height: 20px;
}
.title-box {
color: #000;
font-size: 10px;
overflow: hidden;
font-weight: 600;
}
.desc-box {
color: #000;
}
So my idea was to not showing all text, just end, for example:
I try to use display: flex and justify-content: end; idea was, to add for title and sub title z-index: 1 and for image z-index: 2, and for box overflow: hidden;
But it's not working for me.

This could be done this way using white-space: nowrap; and direction: rtl;
.box {
background-color: #ccc;
margin: 10px;
border-radius: 10px;
text-align: center;
font-size: 10px;
}
.machine-icon {
vertical-align: middle;
float: left;
width: 40px;
height: 40px;
background-color: #808080;
border-radius: 20px;
margin: 2px;
}
.machine-icon>img {
margin-top: 25%;
width: 20px;
height: 20px;
}
.title-box {
color: #000;
font-size: 10px;
overflow: hidden;
font-weight: 600;
direction: rtl;
white-space: nowrap;
}
.desc-box {
color: #000;
}
<div class="box" id="box98" style="width: 110px; height: 43px;">
<div class="machine-icon" id="machine98" style="background-color: green;">
<img src="https://via.placeholder.com/150/">
</div>
<div class="title-box">SOME WERY BIG DATA 1345135131421124</div>
<div class="desc-box">SUB DATAqfqwfqwf</div>
</div>

Remove Height from your in the .box element.
the height should be Auto:
<div class="box" id="box98" style="width: 110px; **height: auto;**">
<div class="machine-icon" id="machine98" style="background-color: green;">
<img src="https://via.placeholder.com/150/">
</div>
<div class="title-box">SOME WERY BIG DATA 1345135131421124</div>
<div class="desc-box">SUB DATAqfqwfqwf</div>
</div>

Related

CSS Create Responsive Side by Side div design

I am trying to create a website where I have divs side by side in a list (separated by a vertical line). I am referencing this design
I am having trouble making the design responsive: I tried using % but when resizing the browser, the divs containing my text content move down and awkwardly collide/crash into each other (and don't stay separated by the vertical line). I am wondering if anyone knows how to keep the divs separated and responsive when resizing
#experience {
border: 1px solid red;
padding-top: 0px;
margin-top: 0px;
min-height: 1000px;
}
.center_text {
border: 1px solid black;
padding-top: 1%;
text-align: center;
color: #001418;
font-weight: 600;
font-family: 'Josefin Sans', sans-serif;
font-size: 2em;
}
.vline {
height: 740px;
width: 1px;
border: none;
border-right: solid 1px black;
z-index: 10;
}
.circle2 {
border: 50px solid black;
width: 1px;
border: none;
border-right: solid 1px black;
z-index: 10;
}
#exp1 {
border: 1px solid blue;
font-family: 'Josefin Sans', sans-serif;
color: #182153;
margin-top: -43%;
height: 150px;
}
.circle:before {
content: ' \25CF';
font-size: 20px;
margin-left: 49.69%;
}
.exp_text {
display: flex;
flex-grow: 1;
flex-wrap: wrap;
margin: 0 auto;
border: 1px solid red;
margin-top: -2%;
min-height: 110px;
}
.left_exp {
border: 1px solid green;
text-align: right;
margin-left: 25%;
}
.right_exp {
margin-top: -5.8%;
border: 1px solid green;
width: min-content;
margin-left: 60%;
}
.date {
font-size: 1.3em;
font-weight: 600;
}
.company {
font-size: 1.3em;
font-weight: 600;
}
.role {
font-size: 1em;
min-width: 250px;
}
.job_descr {
font-size: 1em;
min-width: 250px;
}
<div id="experience">
<h3 class="center_text"> Experience</h3>
<div>
<hr class="vline" />
<div id="exp1">
<span class="circle"></span>
<div class="exp_text">
<div class="left_exp">
<div class="date">
<p>2022 </p>
</div>
<div class="role">
<p>Software Engineering Intern</p>
</div>
</div>
<div class="right_exp">
<div class="company">
<p>Company Name</p>
</div>
<div class="job_descr">
<p>Description.................</p>
</div>
</div>
</div>
</div>
</div>
</div>
The solution was to use flexbox.
#experience_content {
margin: 0 auto;
min-height: 100vh;
width: min-content;
}
.row {
display: flex;
}
.column {
color: black;
flex:33.3%;
padding: 20px;
}
and
<div id="experience">
<div id="experience_content">
<div class="row">
<div class="column">
</div>
</div>
</div>
</div>

2 divs in 1 line

How to make this div starts after the picture.
It starts from the beginning of the container.
I have added /float: left;/ in profile image.
enter image description here
HTML and CSS Code:
.profile{
border: 1px solid #ddd;
padding: 22px;
min-height: 150px;
}
.profile img{
max-width: 150px;
width: 100%;
float: left;
}
.profile #details{
margin-left: 50px;
}
<section class="profile">
<img src="https://www.sonypark360.net/wp-content/uploads/2017/08/profile-pictures.png" alt="profile">
<div id="details">
<h1>Name</h1>
<h2>Age</h2>
<h3>City, Country</h3>
</div>
</section>
This code should work for you
.my-profiles {
border: 1px solid #b2cbe3;
padding: 22px;
font-family: arial;
display: inline-block;
}
.my-profiles img{
max-width: 100px;
width: 100%;
border-radius: 50%;
float: left;
}
.my-profiles .details {
overflow-x: hidden;
padding-top: 10px;
padding-left: 8px;
display: inline-block;
}
.my-profiles .details * {
margin: 0px;
font-size: 22px;
font-weight: 200;
}
<div class="my-profiles">
<img src="https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png">
<div class="details">
<h2>Name</h2>
<h2>Age</h2>
<h2>City, Country</h2>
</div>
</div>

Image and text in contact bar

Okay so the desired outcome of this is to have the images on the left and the text sit to the right of the images, screenshot below:
.contact_bar {
width: 100%;
height: 50px;
background: #2c3e50;
color: #ffffff;
border-bottom: solid 2px #c9c9c9;
}
.contact_bar_container {
width: 1050px;
height: 50px;
position: relative;
margin-left: auto;
margin-right: auto;
}
.contact_bar_text {
width: 100%;
}
.contact_bar_call {
background-image: url(/images/call.png);
height: 32px;
width: 32px;
float: left;
margin-top: 8px;
float: left;
margin-right: 100px;
}
.contact_bar_email {
background-image: url(/images/email.png);
height: 32px;
width: 32px;
float: left;
margin-top: 8px;
}
<div class="contact_bar">
<div class="contact_bar_container">
<div class="contact_bar_call">
<div class="contact_bar_text">
Call here
</div>
</div>
<div class="contact_bar_email">
<div class="contact_bar_text">
Email here
</div>
</div>
</div>
</div>
I want the image to be left of the text and automatically understand when the first line of text (phone number) is finished it will then have the email image with a 5px margin and then the email image and address.
Here a solution using img html tag instead of background-image. I edited a bit your html code.
So you just have use a <img src="###" />tag instead of the <div class="contact_image"></div>
.contact_bar {
width: 100%;
height: 50px;
background: #2c3e50;
color: #ffffff;
border-bottom: solid 2px #c9c9c9;
}
.contact_bar_container {
width: 1050px;
height: 50px;
position: relative;
margin-left: auto;
margin-right: auto;
display: flex;
align-items: center;
}
.contact_bar_content{
display: flex;
align-items: center;
padding: 0 15px;
}
.contact_image{
height: 15px;
width: 15px;
background-color: red;
margin-right: 5px;
}
<div class="contact_bar">
<div class="contact_bar_container">
<div class="contact_bar_content">
<div class="contact_image">
</div>
<div class="contact_bar_text">
Call here
</div>
</div>
<div class="contact_bar_content">
<div class="contact_image">
</div>
<div class="contact_bar_text">
Email here
</div>
</div>
</div>
</div>

Circular divs with vertically aligned text and subtitles

I feel like this is really obvious but I couldn't seem to find any answers on here.
I'm trying to make 5 circular divs, inline, with a letter in the middle representing a grade. I then want the subject title below the grade (but still inside the circle).
Here's what I've written so far:
HTML:
<div class="subject">A</div>
<div class="subject">B</div>
<div class="subject">C</div>
<div class="subject">D</div>
<div class="subject">E</div>
CSS:
.subject {
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;
Also, I couldn't seem to horizontally center the circles using:
margin: 0 auto;
or
margin-left: auto;
margin-right: auto;
.subject {
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;
}
<div class="subject">A</div>
<div class="subject">B</div>
<div class="subject">C</div>
<div class="subject">D</div>
<div class="subject">E</div>
Any advice is appreciated, thanks!
Wrap the div's in a container and add text-align: center to it.
Use pseudo element :after to insert the subtitle. Check below example
.container {
text-align: center;
}
.subject {
border-radius: 100%;
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;
position: relative;
}
.subject:after {
display: inline-block;
position: absolute;
font-size: 16px;
content: attr(data-sub);
left: 50%;
transform: translateX(-50%);
top: 30%;
}
<div class="container">
<div class="subject" data-sub="Maths">A</div>
<div class="subject" data-sub="French">B</div>
<div class="subject" data-sub="Biology">C</div>
<div class="subject" data-sub="German">D</div>
<div class="subject" data-sub="Chemistry">E</div>
</div>
You can do follows, i created another div and added text-align:center property.Now these group of circles are horizontally centered.
.subject {
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;}
.circle{
text-align:center;
}
<div class="circle">
<div class="subject">A</div>
<div class="subject">B</div>
<div class="subject">C</div>
<div class="subject">D</div>
<div class="subject">E</div></div>

CSS table cell alignment and ellipsis not working

I have some HTML code that is not hidden and cut off using the CSS ellipsis.
I have tried many things to fix this issue, but nothing works for me (and it is killing me I cannot fix such a simple issue). I have read all the SO posts about the CSS ellipsis.
Here is a visual representation of what I have:
As shown the 11/2001 (2 annees, 10 mois) is dropped to the next line and the ellipsis does not take effect.
I am trying to keep the 11/2001 (2 annees, 10 mois) next to the prompt Date d'achevement and to be cut off (hidden) with the ellipsis if the value is too long, as it is in this case.
Here is my HTML
<div id="live_preview" class="livePreview_resumeWrapper1">
<div class="resumeStyleWrapper25">
<div class="resumeStyleOptimisedContainer25">
<div class="resumeStyleStandardHeadings25">Emploi Détails d'histoire</div>
</div>
<div class="resumeStyleWrapper25">
<div class="resumeStyleStandardTableRow25">
<div class="resumeStyleStandardContainer25">
<div class="resumeStyleStandardTableRow25">
<div class="resumeStyleStandardLabels25">employeur</div>
<div class="resumeStyleStandardLabelContent25">french</div>
</div>
<div class="resumeStyleStandardTableRow25">
<div class="resumeStyleStandardLabels25">Date de demarrage</div>
<div class="resumeStyleStandardLabels25">
<div class="resumeStyleDateStartContent25">01/2009</div>
<div class="resumeStyleFinishDateLabel25">Date d'achevement</div>
<div class="resumeStyleDateFinishContent25">
<div class="ellipsis">11/2011 (2 annees, 10 mois)</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here is my CSS
.livePreview_resumeWrapper1 {
border: 1px solid #000;
box-shadow: 10px 10px 5px 0px #888888;
direction: ltr;
padding: 20px;
width: 93%;
}
.resumeStyleWrapper25 {
border-spacing: 0px 0px;
display: table;
font-family: verdana;
font-size: 12px;
width: 100%;
}
.resumeStyleOptimisedContainer25 {
/* THIS CLASS ALTERNATES BETWEEN A ROW AND A NON-ROW DEPENDING ON THE STYLE REQUIREMENTS */
background-color: #000;
display: table-cell;
font-weight: bold;
min-width: 149px;
padding: 2px;
text-transform: uppercase;
vertical-align: top;
width: 18%;
}
.resumeStyleStandardHeadings25 {
background-color: #000;
color: #fff;
display: table-cell;
font-weight: bold;
min-width: 149px;
padding: 2px;
text-transform: uppercase;
vertical-align: top;
width: 18%;
}
.resumeStyleStandardContainer25 {
padding-left: 5px;
width: 100%;
}
.resumeStyleStandardTableRow25 {
display: table-row;
}
.resumeStyleStandardLabels25 {
direction: ltr;
display: table-cell;
font-weight: bold;
height: 100%;
min-height: 25px;
overflow: hidden;
padding: 2px;
padding-right: 10px;
text-align: right;
vertical-align: top;
white-space: nowrap;
}
.resumeStyleDateStartContent25 {
direction: ltr;
display: table-cell;
float: left;
padding: 2px;
text-align: left;
vertical-align: top;
width: 20%;
}
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.resumeStyleFinishDateLabel25 {
background-color: #fff;
color: #000;
direction: ltr;
display: table-cell;
float: left;
font-weight: bold;
padding: 2px;
padding-right: 10px;
text-align: left;
vertical-align: top;
}
.resumeStyleDateFinishContent25 {
direction: ltr;
display: table-cell;
float: left;
padding: 2px;
text-align: left;
vertical-align: top;
}
Can anyone point out what I am doing incorrectly?
EDIT
I have updated the HTML & CSS as requested in the comments.
There is a problem of the CSS table structure, you have some table cells stay directly under the element that is also set to table cell, which is invalid. You can wrapped the inner table cell elements into a container and set it as display:table, which would fix the issue.
It's this part:
<div class="table">
<div class="resumeStyleStandardLabelContent25">
<div class="ellipsis">01/2009 Date d'achevement</div>
</div>
<div class="resumeStyleStandardLabelContent25">
<div class="ellipsis">11/2011 (2 annees, 10 mois)</div>
</div>
</div>
In general the correct CSS table layout is like this, but row isn't needed if there is only one row.
<div style="display:table">
<div style="display:table-row">
<div style="display:table-cell">
...
When you use CSS text-overflow:ellipsis in table, it needs to work with fixed table layout, and has width value set, either fixed or percentage are both fine.
It's like this:
.table {
display: table;
width: 100%;
table-layout: fixed;
}
Lastly:
Remove all the float properties from the table cells, they don't work together.
Here is the updated code snippet:
body {width: 500px;} /*for demo only*/
.livePreview_resumeWrapper1 {
border: 1px solid #000;
box-shadow: 10px 10px 5px 0px #888888;
direction: ltr;
padding: 20px;
width: 93%;
}
.resumeStyleWrapper25 {
border-spacing: 0px 0px;
display: table;
font-family: verdana;
font-size: 12px;
width: 100%;
}
.resumeStyleOptimisedContainer25 {
/* THIS CLASS ALTERNATES BETWEEN A ROW AND A NON-ROW DEPENDING ON THE STYLE REQUIREMENTS */
background-color: #000;
display: table-cell;
font-weight: bold;
min-width: 149px;
padding: 2px;
text-transform: uppercase;
vertical-align: top;
width: 18%;
}
.resumeStyleStandardHeadings25 {
background-color: #000;
color: #fff;
display: table-cell;
font-weight: bold;
min-width: 149px;
padding: 2px;
text-transform: uppercase;
vertical-align: top;
width: 18%;
}
.resumeStyleStandardContainer25 {
padding-left: 5px;
width: 100%;
}
.resumeStyleStandardTableRow25 {
display: table-row;
}
.resumeStyleStandardLabels25 {
direction: ltr;
display: table-cell;
font-weight: bold;
height: 100%;
min-height: 25px;
overflow: hidden;
padding: 2px;
padding-right: 10px;
text-align: right;
vertical-align: top;
white-space: nowrap;
}
.resumeStyleDateStartContent25 {
direction: ltr;
display: table-cell;
/* float: left; */
padding: 2px;
text-align: left;
vertical-align: top;
width: 20%;
}
.table {
display: table;
width: 100%;
table-layout: fixed;
}
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.resumeStyleFinishDateLabel25 {
background-color: #fff;
color: #000;
direction: ltr;
display: table-cell;
/* float: left; */
font-weight: bold;
padding: 2px;
padding-right: 10px;
text-align: left;
vertical-align: top;
}
.resumeStyleDateFinishContent25 {
direction: ltr;
display: table-cell;
/* float: left; */
padding: 2px;
text-align: left;
vertical-align: top;
}
<div id="live_preview" class="livePreview_resumeWrapper1">
<div class="resumeStyleWrapper25">
<div class="resumeStyleOptimisedContainer25">
<div class="resumeStyleStandardHeadings25">Emploi Détails d'histoire</div>
</div>
<div class="resumeStyleWrapper25">
<div class="resumeStyleStandardTableRow25">
<div class="resumeStyleStandardContainer25">
<div class="resumeStyleStandardTableRow25">
<div class="resumeStyleStandardLabels25">employeur</div>
<div class="resumeStyleStandardLabelContent25">french</div>
</div>
<div class="resumeStyleStandardTableRow25">
<div class="resumeStyleStandardLabels25">Date de demarrage</div>
<div class="resumeStyleStandardLabelContent25">
<div class="table">
<div class="resumeStyleStandardLabelContent25">
<div class="ellipsis">01/2009 Date d'achevement</div>
</div>
<div class="resumeStyleStandardLabelContent25">
<div class="ellipsis">11/2011 (2 annees, 10 mois)</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Or, view the JsFiddle demo, so you can resize the frame easily to check:
Working Demo Here