My Problem
I'm working on website which has comments that look like Facebook's comments. The text and user's name in the comments can be edited dynamically.
I can't figure out how to break a long text correctly after the user's name.
What I've Tried
Using 'word-break: break-all' on my wrapper div.
Examples
What i'm trying to achieve:
What i get:
My Code (Simplified)
html:
<div class="comment_wrapper">
<div class="name"></div>
<div class="text_wrapper">
<div class="space_holder"></div>
<div class="text"></div>
</div>
</div>
relevant css:
.text_wrapper{
word-break: break-all;
}
.space_holder{
width: /*Equals to name's width + 10px. Changes dynamically with
javascript when the name is edited. */
}
Help much appreciated!
EDITED: SOLUTION
This worked for me:
html:
<div class="comment_wrapper">
<div class="name"></div>
<div class="text_wrapper">
<div class="space_holder"></div>
<div class="text"></div>
</div>
</div>
relevant css:
.text_wrapper{
word-break: break-all;
}
.space_holder{
width: /*Equals to name's width + 10px. Changes dynamically with
javascript when the name is edited. */
float: left;
}
.text{
display: inline;
}
If you add a float: left; to .space_holder you can wrap the floated name.
.text_wrapper {
word-break: break-all;
}
.space_holder {
width: 75px;
float: left;
}
<div class="comment_wrapper">
<div class="name"></div>
<div class="text_wrapper">
<div class="space_holder">John Doe</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</div>
</div>
</div>
Related
.empty-space{
width: 30%;
float: left;
}
.download-information{
width: 70%;
float: left;
}
.download-thumbnail img {
height: 30px;
width: 30px;
float: left;
}
.download-profile{
float: left;
}
<div class="download-content">
<div class="download-information">
<div class="empty-space"></div>
<div class="information">
<div class="download-thumbnail"><img src="https://media.istockphoto.com/photos/cloud-computing-picture-id1087885966" alt="Sample image"></div>
<div class="download-profile">
<b><div class="img-title">Demo title</div></b>
<div class="img-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-content">
<div class="download-icon"><i class="fas fa-download"></i></div>
<div class="link-to-download">Download</div>
<div class="download-link-information">
<span>(
<span class="download-filesize">3,2 MB,</span>
<span class="download-filestype">PDF</span>
)
</span>
</div>
</div>
<div class="empty-space"></div>
</div>
</div>
I have the following mockup which I am now trying to model.
I have thought of the following HTML framework and associated CSS:
<div class="download-content">
<div class="download-information">
<div class="empty-space"></div>
<div class="information">
<div class="download-thumbnail"></div>
<div class="download-profile">
<b><div class="img-title"></div></b>
<div class="img-description"></div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-content">
<div class="download-icon"><i class="fas fa-download"></i></div>
<div class="link-to-download"></div>
<div class="download-link-information">
<span>(
<span class="download-filesize">,</span>
<span class="download-filestype"></span>
)
</span>
</div>
</div>
<div class="empty-space"></div>
</div>
</div>
.empty-space{
width: 30%;
float: left;
}
.download-information{
width: 70%;
float: left;
}
.download-thumbnail {
height: 30px;
width: 30px;
float: left;
}
.download-profile{
float: left;
}
Unfortunately it doesn't work and frontend is not my strength at all and unfortunately I don't know anyone who can help me here how to do it. Can someone here help me how it should look or how I would have to style the CSS?
Add 1:
Is my idea of the HTML DOM wrong or is it possible to implement this so that the image can also be displayed correctly
Add 2:
Add snippet to my post. I don't get it. It's only a privat project but don't get the frontend styling.
I would not use all these floats, but to stay as close to what you did as possible, here's what you can do:
Move .download-profile into the .information div.
Create an additional wrapper div around .thumbnail and the div which follows after it (which contains the image title and description). (To only have two child elements in .download-profile which will be placed beside each other)
Apply display: flex to .download-profile
.empty-space {
width: 30%;
float: left;
}
.download-information {
width: 70%;
float: left;
}
.download-thumbnail img {
height: 30px;
width: 30px;
float: left;
margin: 0 10px 6px 0;
}
.download-profile {
float: left;
display: flex;
}
<div class="download-content">
<div class="download-information">
<div class="empty-space"></div>
<div class="information">
<div class="download-profile">
<div class="download-thumbnail"><img src="https://media.istockphoto.com/photos/cloud-computing-picture-id1087885966" alt="Sample image"></div>
<div>
<b><div class="img-title">Demo title</div></b>
<div class="img-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div>
</div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-content">
<div class="download-icon"><i class="fas fa-download"></i></div>
<div class="link-to-download">Download</div>
<div class="download-link-information">
<span>(
<span class="download-filesize">3,2 MB,</span>
<span class="download-filestype">PDF</span> )
</span>
</div>
</div>
<div class="empty-space"></div>
</div>
</div>
It looks as though the CSS grid property will help here as it will work out how much space to leave between items tso you don't need to worry about floats or having empty space divs.
Here's a snippet to get you started. Obviously you'll want to look at the exact proportions you want for each part. You may also want to have a media query so that narrow devices use the full width of the screen for example.
You could also review your HTML structure as, with thinking of it in grid terms, it might be possible to simplify it.
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
}
.download-content {
display: grid;
grid-template-columns: 2fr 1fr;
width: 70%;
margin: 0 auto 0 auto;
}
.information{
width: 70%;
display: grid;
grid-template-columns: 1fr 6fr;
}
.download-thumbnail img {
width: 100%;
height: auto;
}
.download-link-info div {
display: inline-block;
}
</style>
</head>
<body>
<div class="download-content">
<div class="download-information">
<div class="information">
<div class="download-thumbnail"><img src="https://media.istockphoto.com/photos/cloud-computing-picture-id1087885966" alt="Sample image"></div>
<div class="download-profile">
<b><div class="img-title">Demo title</div></b>
<div class="img-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-info">
<div class="download-icon"><i class="fa fa-download" aria-hidden="true"></i></div>
<div class="link-to-download">Download</div>
<div class="download-link-information">
<span>(
<span class="download-filesize">3,2 MB,</span>
<span class="download-filestype">PDF</span>
)
</span>
</div>
</div>
</div>
</div>
</body>
I need an example html/css which gives the following result
23:59 icon Some text which can wrap
like this
icon Some text which can wrap
like this
So there are 2 lines. The first line leads with a time. The 2nd line is indented the same width so that the icons align. The icons are a little bigger then the text just to make things tricky. To the right of each icon is some text which can wrap aligned with itself.
Would really appreciate some ideas how to do this.
I am also looking for a suggestion how to connect the 2 icons with a vertical line so that if the icons were circles then the whole thing would appear as a vertical barbell. But this is maybe too much bother
Keep things in their respected div and float them where you'd like.
.wrapper {
float: left;
}
div {
padding-right: 5px;
}
span {
float: right;
padding-left: 15px;
width: 180px;
}
<div class="wrapper">
<div>
23:59
</div>
</div>
<div class="wrapper">
<div>
icon
<span>Some text which can wrap like this</span>
</div>
<div class="wrapper">
icon
<span>Some text which can wrap like this</span>
</div>
</div>
If I understand you right, I think everything should work with Flex-Box.
Maybe you look at css-ticks to get some inspiration.
This should work:
.flex-row {
display: flex;
flex-wrap: nowrap;
align-items: center;
}
i {
font-size: 2rem
}
div {
padding: 6px
}
<link href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" rel="stylesheet"/>
<div class="flex-row">
<div>12:30</div>
<div>
<i class="fas fa-check"></i>
</div>
<div>Lorem ipsum dolor set amet..</div>
</div>
<div class="flex-row">
<div>12:30</div>
<div>
<i class="fas fa-times"></i>
</div>
<div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam..</div>
</div>
you can use table to easily achieve that layout.
To connect two icons by vertical line I would use pseudo selector.
/* Selects pseudo element :before on every second icon */
.icon:nth-child(even)::before {
content: '';
display: block;
width: 1px;
height: 20px;
background: #000;
position: relative;
top: -20px;
}
It will need some tweaks, but you've got the idea.
unaligned images and text
I have attempted to input suggestions from previous questions but it just seems I have been able to successfully find the correct way to align these images with their text underneath.
<section id="boxes">
<div class="container">
<div class="box">
<img src="./images/dayporter2.jpeg">
<h3>DAYPORT</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box">
<h3>FLOOR CARE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="box">
<img src="./images/janitor2.jpeg">
</div>
</section>
/* boxes */
#boxes{
margin-top: 20px;
}
#boxes .box{
float: left;
text-align: center;
width: 30%;
padding: 10px;
}
#boxes .box img{
width: 90px;
}`
You seem to have an unnecessary div tag.
remove the div tag after your 'floorcare1.jpeg' img, here:
<img src="./images/floorcare1.jpeg">
<div class="box"> //remove this
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box"> <!-- The probleme is here -->
<h3>FLOOR CARE</h3>
Because the .box element which is direct below the image is float left, it will force the image to be float left, because their sibling .box take 30% of the parent and there are remaining 70% width of their .box parent element. You must remove the .box element and every thing will work like you expecting.
Another problem you must close all you open markup
<section>
<div class="container">
<div class="box">
<!-- First box -->
</div>
<div class="box">
<!-- Second box -->
</div>
<div class="box">
<!-- Third box -->
</div>
</div>
</section>
On bootstrap 3,I can't make the layout how I want to and I can't see why.
My HTML :
<div class="container">
<div id="row1" class="row">
<div class="col-lg-4 col-lg-push-8 col-md-4 col-md-push-8 col-sm-push-8 col-sm-4">
<div class="round"></div>
</div>
<div class="col-lg-8 col-lg-pull-4 col-md-8 col-md-pull-4 col-sm-8 col-sm-pull-4 intro-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</p>
</div>
</div>
<div id="row2" class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="round"></div>
</div>
<div class="col-lg-8 col-md-8 col-sm-8 intro-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</p>
</div>
</div>
</div>
My CSS :
#row1 {
opacity:0.3;
background-color: red;
}
#row2 {
opacity:0.3;
background-color: yellow;
}
.intro-text {
text-align:center;
}
.round {
background:#bfd70e;
border-radius:50%;
width:160px;
height:160px;
border:2px solid #679403;
margin:0 auto;
}
#media(min-width:767px) {
.intro-text {
margin-top:60px;
}
#row2 {
margin-top:-15px;
}
}
I want to keep the same structure as the first JS fiddle but gain some space by making the row 2 over the first one. So I tried a margin-top but it break all the structure, I don't know why.
This is JS fiddle without :
#row2 {
margin-top:-15px;
}
JS fiddle
This is JS fiddle with
#row2 {
margin-top:-15px;
}
JS fiddle
How do I fix that ?
Change your:
margin-top: -15px;
to:
margin-top: 15px;
Otherwise you're pulling it down.
https://jsfiddle.net/584wcaa5/1/
It's because the elements are positioned statically, therefore colliding with the elements above it.
If you give your second row position:absolute it should stop it colliding with the elements as the position is set regardless of what other elements are doing.
https://jsfiddle.net/584wcaa5/2/
I am having the following structure of the web page.
Part 1: Header, fixed height
Part 2: Content, variable height
Part 3: Footer, fixed height
And I want the following to be true:
1) If the content is smaller than screen_height - header_height - footer_height : The footer should stick to bottom of page, giving the content all the screen space between header and footer.
2) If the content is larger than screen_height - header_height - footer_height : the page will scroll and the footer will be on the bottom of the page. (This case is already achievable, it's how all normal pages look)
To achieve first, I did the following
HTML:
<div class="page-content" style="display: table;height: 100%;width: 100%;">
<div class="header-section" style="display: table-row;height: 10px;">
Content here
</div>
<div id="content-section" style="display: table-row;height: auto;">
Content here
</div>
<div id="footer-section" style="display: table-row;height: 230px;">
Content here
</div>
</div>
With this, the header row is spanning not 10px height but more. I want to confine the header row to just 10px height. Is this achievable with this table structure? And what about cross-browser compatibility?
Thanks.
To reduce header height, add line-height:10px also.
You can add Javascript to apply height .
Please check the fiddle - https://jsfiddle.net/afelixj/c8vq3Lbu/5/
Tables try their very best to display everything in them. So since the text "content here" is higher than 10px, the top row will expand to show it all.
Possible solutions are
Take the header out of the table and put it above. Ordinary blocks handle height in a more straightforward way.
html, body {
margin: 0;
height: 100%
}
<header class="header-section" style="height:10px; overflow:hidden">
Content here
</header>
<div class="page-content" style="display:table; height:calc(100% - 10px); width:100%;">
<div id="content-section" style="display:table-row; height:auto;">
Content here
</div>
<div id="footer-section" style="display:table-row; height:230px;">
Content here
</div>
</div>
Put an extra div in the table cell in the header that you give the height. If a div in a table cell is 10px high, the cell won't have to expand, even if there is content overflowing.
html, body {
margin: 0;
height: 100%
}
<div class="page-content" style="display:table; height:100%; width:100%;">
<div class="header-section" style="display:table-row; height:10px; ">
<div style="display:table-cell;">
<div style="height:10px; overflow:hidden">
Content here
</div>
</div>
</div>
<div id="content-section" style="display:table-row; height:auto;">
Content here
</div>
<div id="footer-section" style="display:table-row; height:230px;">
Content here
</div>
</div>
Or, if the problem is that the content is actually 10px high, but you have a few pixels extra below it in the cell, it's probably that the content is inline and leaves room for a descender. In that case, the solution is to give the content display:block or vertical-align:top styles.
html, body {
margin: 0;
height: 100%
}
<div class="page-content" style="display:table; height:100%; width:100%;">
<div class="header-section" style="display:table-row; height:10px; ">
<div style="display:table-cell;">
<img src="http://lorempixel.com/300/10" alt="" style="display:block"/>
</div>
</div>
<div id="content-section" style="display:table-row; height:auto;">
Content here
</div>
<div id="footer-section" style="display:table-row; height:230px;">
Content here
</div>
</div>
As for cross-browser compatibility, it's usually best to emulate a full table (with nested divs being table, table-row and table cell) because older browsers may have problems with content being put directly inside a table row.
You do not need a table layout for achieving this.
Just do a calc for the min-height on your main content div. That's it. Use the viewport relative unit to get the height of the viewport (screen) and subtract the fixed heights of your header and footer.
All you need is this:
.header { height: 1.5em; } /* Fixed height, any unit */
.footer { height: 200px; } /* Fixed height, any unit */
.main { min-height: calc(100vh - 1.5em - 200px); } /* Calculated min-height */
Fiddle: http://jsfiddle.net/abhitalks/jpunjng4/2/
Snippet:
(go full screen to see the effect)
* { box-sizing: border-box; padding: 0; margin: 0; }
.header { height: 1.5em; background-color: #eef; border-bottom: 1px solid #999; }
.footer { height: 200px; background-color: #efe; border-top: 1px solid #999; }
.header, .footer { overflow: hidden; padding: 4px; }
.main {
min-height: calc(100vh - 1.5em - 200px); padding: 4px;
background-color: #eee;
}
<div class="header">
Header
</div>
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="footer">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>