I am currently working on a TODO App. This TODO app shows tasks horizontally for the user. In a normal case we have the task which has to be done, with a click on it the user can mark it as done.
However, I now wanted to add the option to assign a due date to it.
What I want to achieve is:
Have the todo text shown in the div box
If a date is given, add the date to the right side of the box
My current code is as following:
.box-task .task-text {
display: flex;
-webkit-box-flex: 1;
-webkit-flex: 1 0 0;
flex: 1 0 0;
font-weight: 400;
font-size: 15px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-left: 8px;
margin-top: 7px;
}
.box-task .task-date {
font-size: 13px;
margin-top: 9px;
color: rgb(50, 138, 214);
display: flex;
-webkit-box-flex: 1;
-webkit-flex: 1 0 0;
flex: 1 0 0;
padding-left: 5px;
padding-right: 5px;
}
My HTML code is (in mix with Laravel blade), I hope you get the idea of what I want to achieve
<div class="col-md-12 col-task-text" style="height:35px;">
<div class="task-checkbox-checked" data-id="1"></div>
<span class="task-text">Test</span>
<span class="task-date">23-05-1995</span>
</div>
</div>
How can I achieve it that the date is always shown on the right side with its own width and the text does get smaller/bigger based on if the date was added?
From everything available so far in your question, I assume the following:
you're trying to display a list of tasks
each task should be displayed on a single row, with a title on left and date on the right side
if the title doesn't fit available space, it should be cut with ellipsis effect.
you're using Bootstrap v3.
If the above is true, this is what you're looking for:
.box-task .task-text {
display: block;
flex: 1 1 auto;
font-weight: 400;
font-size: 15px;
white-space: nowrap;
overflow-x: hidden;
text-overflow: ellipsis;
overflow: hidden;
margin-left: 8px;
margin-top: 7px;
}
.box-task .task-date {
font-size: 13px;
margin-top: 9px;
color: rgb(50, 138, 214);
display: flex;
flex: 0 0 auto;
padding-left: 5px;
padding-right: 5px;
}
.col-task-text {
display: flex;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row box-task">
<div class="col-md-12 col-task-text" style="height:35px;">
<div class="task-checkbox-checked" data-id="1"></div>
<span class="task-text">Test</span>
<span class="task-date">23-05-1995</span>
</div>
<div class="col-md-12 col-task-text" style="height:35px;">
<div class="task-checkbox-checked" data-id="2"></div>
<span class="task-text">Test</span>
<span class="task-date">23-05-1995</span>
</div>
<div class="col-md-12 col-task-text" style="height:35px;">
<div class="task-checkbox-checked" data-id="3"></div>
<span class="task-text">Test with a lot more text, lorem ipsum dolor sit amet. Test with a lot more text, lorem ipsum dolor sit amet.</span>
<span class="task-date">23-05-1995</span>
</div>
</div>
</div>
There were quite a few details I needed to fix, but the most important ones were:
you need display:inline-block (or block) for text-overflow:ellipsis to work
the display:flex needs to be on the parent, not on the children for flex:{grow} {shrink} {basis}; shorthand to work.
If you're going to use flexbox you need to read CSS documentation*** available on each of its properties. The most important part is to understand which props go on parent and which on children and how they all work together.
*** Candidate Recommendation (oficial spec). You might find this resource useful.
The rest are details.
If the above is not what you're looking for, please update your question with all the info I had to assume and, if I can help, I'll update my answer. If not, I'll delete it.
Related
I have a text composed by "< p >" and "< ul >< li >", inside a box.
There's no problem with the lists, but the words in the paragraphs are splitting in half when they reach the padding of the box.
my text
<style>
#media (min-width: 768px)
<style>
.col-md-12 {
flex: 0 0 100%;
max-width: 100%;
}
.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
.alert-warning {
color: #856404;
background-color: #fff3cd;
border-color: #ffeeba;
}
.garrigues_RemindersAML__Exvyp {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
color: #0c5460;
border-color: #ffeeba;
text-align: justify;
}
</style>
<div class="row" style="margin-top: 15px;">
<div class="alert alert-warning garrigues_RemindersAML__Exvyp col-md-12">
<p style="font-size: 17px;margin-left:0px;">Reminder </p>
<p> A priori, it is not necessary to request any document from this type of clients. The following documents must be obtained from public sources of information, and included in the AML questionnaire:</p>
<ul>
<li>Documentation proving that it is one of the clients considered low risk.</li>
<li>Documentation accrediting the activity (for example, annual accounts or screenshot of the website).</li>
</ul>
<p> If the customer is a subsidiary or branch of a financial entity or of listed companies whose securities are admitted to trading in a market regulated in the EU or Equivalent Third Countries, it must be justified that they belong (directly or indirectly in more than 50% to the financial or listed entity).</p>
<p> This client has LOW RISK and, therefore, applies SIMPLIFIED MEASURES OF DILIGENCE DUE.</p>
</div>
</div>
I've tried everything to prevent them to break, but there's just 2 results: they break, or the paragraph overflows outside the box.
I've tried all the options with white-space, word-break, overflow-wrap, overflow, display, width, margin, height... And the result is always the same: they break or they overflow.
Is there a way to prevent them from breaking, placing them in the next line, instead of overflowing them?
Thank you in advance.
Edit: each paragraph comes from a database, and then is renderized by a component in a React web application, the code is not as simple as it seems.
The text can't break between the words because there are only s (which is for 'non breaking space') used. Use normal space characters.
p {
background: teal;
width: 150px;
margin: 1em;
}
<p>This text has a long_long_word to test the issue</p>
<p>This text has a long_long_word to test the issue</p>
Have you tried "word-wrap: break-word;"?
I have tried this and its working.
I want to centrally align h tags and p tags but I can't seem to separate the sections nicely. Here is the preview of what happens
What I would like is to have space between the three "boxes" of information and make everything central. I tried to add padding in between the .top-row class but it seems to always stick together.
HTML:
<section>
<div class="container">
<h1>TOPICS COVERED</h1>
<p id=intro-p>There are six essential parts to building a CPU, let's
go through them briefly</p>
<div class="top-row">
<div class="box1">
<h3>BINAY & LOGIC</h3>
<p>Before all, one needs to be comfortable with lab material & binary logic</p>
</div>
<div class="box2">
<h3>Timing Signal Generator</h3>
<p>The timing signal generator for the computer is a clock with a cycle that
repeats. It allows the computer the amount of time needed to permorm operations.</p>
</div>
<div class="box3">
<h3>Bus, Arithmetic Unit & Program Counter</h3>
<p>In order to efficiently spread data throughout the breadboard, the data can be spread in a bus.
he program counter of a computer holds the location of an execution to be executed.</p>
</div>
</div>
<div class="bottom-row">
</div>
</div>
</section>
CSS:
#topics{
padding: 25px;
background-color: #f5f6fa;
}
#topics h1{
font-size: 30px;
font-weight: 400px;
letter-spacing: 2.5px;
text-align: center;
color: #282828;
}
#intro-p {
text-align: center;
color: #282828;
font-size: 20px;
letter-spacing: 2.5px;
}
.top-row{
display: flex;
}
.top-row h3{
padding-left: 0px;
text-transform: uppercase;
}
.top-row p{
text-align: justify;
color: #282828;
font-size: 14px;
letter-spacing: 0.5px;
}
The top row will only pad the container as a whole. What you want to do is pad the top row's children. You can do that by selecting them and adding padding. Further, since you are using flexbox, you can add flex to them to choose how they shrink, grow and their base size. Something like this would work for you. The text-align center will only center the heading as the paragraph tags have justify on them. If you want them centered, then remove that. Also, the flex-basis, third number on flex, could also be set to auto or unset if you don't want them to be equal. Find more on flexbox here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.top-row > div {
padding: 20px;
text-align: center;
flex: 1 1 33%;
}
I'm taking the Free Code Camp course thing and the first project is to create a tribute page to whoever. Mine is on J Dilla, my favorite hip hop producer. God rest his soul. Anyways I'm trying to use a bootstrap thumbnail around a picture of him, with the text/caption also inside the thumbnail. My problem is that it messes up the centering and aligns the thumbnail to the left and I have no idea how to fix it. Here's the relevant code:
<style>
.cool-text {
font-family: Lobster;
font-size: 20px;
}
.image-centering {
display: block;
margin-left: auto;
margin-right: auto;
}
.vertical-centering {
margin-top: auto;
margin-bottom: auto;
}
.gray-background {
background-color: lightgray;
margin: 20px 100px 20px 100px;
border-radius: 5px;
}
.white-background {
background-color: white;
margin: 10px 560px 10px 10px;
}
</style>
<div class="gray-background">
<br>
<h1 class="cool-text text-center">J Dilla</h1>
<h2 class="text-center"><i>The one and only</i></h2>
<br>
<div class="span8 offset2">
<div class="img-thumbnail thumbnails">
<img class="image-centering" src="http://media.lessthan3.com/wp-content/uploads/2014/02/j-dilla-lessthan3.jpg" alt="The man himself."</img>
<p class="text-center">Dilla working on something ill, I presume</p>
</div>
</div>
<br>
</div>
</div>
Also if there's anything glaringly terrible about my code, I'd love some input on how to reformat it. This is my first time asking a question on stack overflow so forgive me if this is the wrong way to do so.
This question already has answers here:
A space between inline-block list items [duplicate]
(8 answers)
Closed 8 years ago.
I'm trying to generate a web page with a diagram that shows how a word is broken down into bit fields. The way I want it to appear is for each field to appear as a row of boxes (one bit per box), and for the fields to be separated by some space. There will be a label below each field. This is what I've tried:
<HTML>
<HEAD>
<TITLE>Title</TITLE>
<STYLE type="text/css">
.left-bit { border-style: solid dotted solid solid; border-width: thin;
padding-left: 0.05in; padding-right: 0.05in;
margin-left: 0; margin-right: 0;
letter-spacing: 0; word-spacing: 0 }
.middle-bit { border-style: solid dotted solid none; border-width: thin;
padding-left: 0.05in; padding-right: 0.05in;
margin-left: 0; margin-right: 0;
letter-spacing: 0; word-spacing: 0 }
.right-bit { border-style: solid solid solid none; border-width: thin;
padding-left: 0.05in; padding-right: 0.05in;
margin-left: 0; margin-right: 0;
letter-spacing: 0; word-spacing: 0 }
.single-bit { border-style: solid; border-width: thin;
padding-left: 0.05in; padding-right: 0.05in;
margin-left: 0; margin-right: 0;
letter-spacing: 0; word-spacing: 0 }
.bit-field-label { font-size: smaller; font-weight: bold }
</STYLE>
</HEAD>
<BODY>
<DIV style="text-align: center">
<DIV style="text-align: center; vertical-align: top; display: inline-block">
<CODE>
<SPAN class="single-bit">a</SPAN>
</CODE><BR>
<SPAN style="display: inline-block" class="bit-field-label">field A</SPAN>
</DIV>
<SPAN style="padding-right: 0.1in"></SPAN>
<DIV style="text-align: center; vertical-align: top; display: inline-block">
<CODE>
<SPAN class="left-bit">b</SPAN>
<SPAN class="middle-bit">b</SPAN>
<SPAN class="right-bit">b</SPAN>
</CODE><BR>
<SPAN class="bit-field-label">field B</SPAN>
</DIV>
<SPAN style="padding-right: 0.1in"></SPAN>
<DIV style="text-align: center; vertical-align: top; display: inline-block">
<CODE>
<SPAN class="left-bit">c</SPAN>
<SPAN class="middle-bit">c</SPAN>
<SPAN class="middle-bit">c</SPAN>
<SPAN class="middle-bit">j</SPAN>
<SPAN class="right-bit">c</SPAN>
</CODE><BR>
<SPAN class="bit-field-label">field C</SPAN>
</DIV>
</DIV>
</BODY>
</HTML>
Basically, I've tried using borders to set up a box for each bit; each bit field and the label below it are supposed to be in their own "box", with the row of bits and label centered within the box, then there's to be a gap of a fixed size between each box horizontally, and then the whole thing is centered.
The result is almost correct except that I can't get the bits in each field to run up against each other. Here's a screenshot. As you can see, I tried getting rid of the space between bits by setting the margins, letter-spacing, and word-spacing to 0, to no avail. I also tried putting each group into another DIV like this:
<DIV style="display: inline-block">
<SPAN class="left-bit">b</SPAN>
<SPAN class="middle-bit">b</SPAN>
<SPAN class="right-bit">b</SPAN>
</DIV>
which had no effect.
Any ideas on what controls this space between the boxes, and how to override whatever it does? (I'm open to other approaches, and I might have to try some kind of <TABLE>, but I'd appreciate an explanation of what's going on even if I have to change my approach.)
I'm using Chrome 37.0. I haven't tried this on other browsers (except an earlier version of IE which apparently doesn't recognize inline-block at all.)
you could have your HTML cleaner but the problem is the display:inline-block create gaps, so you need to remove unnecessary spaces between your HTML tags or reset font-size to 0.
check it here :
Fighting the Space Between Inline Block Elements
There is more solutions on the link above.
Plus you can use display:block; float:left instead.
combining elements like so will remove the space
<span style="display:inline-block;">Hello</span><span style="display:inline-block;">World</span>
it's a hassle I know but it works somehow. you want to put those styles in an external style sheet, not inline like I have them here.
At the top of a page I've got two divs, one floated to the left and one to the right. I can place text with a border between them, however, I now need to stack two such areas of text between them.
Here's a Fiddle illustrating my problem: http://jsfiddle.net/TcRxp/
I need the orange box under the green box, with each center aligned with the other. The "legend" (floated to the right) used to be at the same level but is shifted down now.
I tried adding another table to the mix but that didn't help.
Excuse the markup - it's not real slick, I know. A few people have touched this over time and none of us are gurus at this.
And yes, I have lobbied for a designer to be added to the team but it hasn't happened yet.
Thanks,
Paul
UPDATE: Incorporating #Jeremy B's suggestion
Does it have to be via CSS changes? When dealing with scenarios like this, you need to be careful of the order in which the HTML elements are defined.
Look at the modification here: http://jsfiddle.net/TcRxp/8/
I was able to acheive what you needed by changing the order of the three DIVs and using the CSS suggesion from #Jeremy B
Essentially, the logic for the layout is
Draw the float-right content
Draw the float-left content
Draw the content in the middle (as it will now render to the right of the float-left content.
First make your top span a block element to stack them:
<span class="color status active bold" style="display:block">Status:</span>
then float the middle div left as well:
add float:left to #headmiddle in your css
It's always going to be difficult to get the desired results when you're combining CSS and tables-for-layout.
I would suggest simplifying your HTML:
<div id="headleft">a little search form here</div>
<div id="headmiddle">
<div class="active"><strong>Status:</strong> Active</div>
<div class="search">Search results displayed</div>
</div>
<div id="headright">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
and your CSS:
div { padding: 2px; }
strong { font-weight: bold; }
#headleft { float: left; font-size: 0.8em; }
#headmiddle { float: left; font-size: 0.8em; }
#headmiddle div { border: 1px solid #000; margin-bottom: 3px; }
.search { background: orange; }
.active { background: #8ed200; }
#headright { float: right; font-size: 0.8em; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
The result is semantically correct HTML, easier to read and therefore easier to modify in the future. Supporting fiddle.
If you need to do it with CSS, see my changes: Fiddle
I added the following:
#headmiddle span.status { display: block }
This will cause your spans to "stack".
I got it by putting together many different sources. Alex Coles' solution was closest right off the bat but the middle wasn't centered. It was much cleaner than my mess too. I started with the code from this post:
<style type="text/css">
.leftit {
float: left;
}
.rightit {
float: right;
}
.centerit {
width: 30%;
margin-right: auto;
margin-left: auto;
text-align: center;
}
.centerpage {
width: 80%;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<body>
<div class="centerpage">
<div class="leftit">Hello Left</div>
<div class="rightit">Hello Right</div>
<div class="centerit">Hello Middle</div>
</div>
(fiddle for above)
I took the elements Alex cleaned up which got me even closer to my goal, but the center color blocks were way too wide. From this question I learned about "max-width", which ended up being the final piece I needed...or so I thought.
Edit: max-width doesn't work in IE7 quirks mode (which I have to support) so from this page I learned how to tweak my css to work in IE7 quirks mode, IE8, and FF.
The final code (fiddle):
.leftit {
float: left;
font-size: 0.8em;
}
.rightit {
float: right;
font-size: 0.8em;
}
.centerit {
width:220px;
margin-right: auto;
margin-left: auto;
font-size: 0.8em;
}
#headmiddle div {
border: 1px solid #000;
margin-bottom: 3px;
}
.centerpage {
margin-right: auto;
margin-left: auto;
text-align: center;
}
strong { font-weight: bold; }
.search { background: orange; }
.active { background: #8ed200; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
<div class="centerpage">
<div class="leftit">a little search form here</div>
<div class="rightit">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
<div class="centerit" id="headmiddle">
<div class="active"><strong>Status:</strong>
Active</div>
<div class="search">Search results displayed</div>
</div>
</div>
Thanks to all the great answers - I learned a lot from this question.
Paul