I am working with the text element that needs to be displayed vertically.
To do so I use the following CSS:
transform: rotate(180deg);
writing-mode: vertical-rl;
However, in Chromium (and other Blink browsers) the width of that element is calculated very weirdly.
To one-time fix that problem there are many ways:
Open DevTools (F12), set fixed width for that element (width: 1px) and disable that option, all goes ok.
Change the window width to a bit smaller.
Play around with the smaller text - delete line breaks (<br>), type in more or less text and etc.
Couldn't recreate the same fixes in JSFiddle. However here it is for you to see what I mean. Try opening it in browser using WebKit and other engine (i.e. Firefox) - there are different results.
https://jsfiddle.net/VoG__/qfkgt7m9/7/
Also I'm using Debian 8, but the problem appears on any OS.
What is the problem? How can I fix this issue using CSS?
.content {
padding: 30px;
background-color: #bbb;
}
.project-info {
display: grid;
grid-gap: 30px;
grid-template-columns: repeat(2, 1fr);
}
.project-info .item {
border: 3px solid #fff;
display: flex;
flex-wrap: nowrap;
}
.project-info .item .heading {
margin-left: -1px;
margin-bottom: -1px;
padding: 10px;
color: #555;
font-size: 20px;
font-family: sans-serif;
background-color: #fff;
text-align: center;
text-transform: uppercase;
transform: rotate(180deg);
writing-mode: vertical-rl;
}
.project-info .item .text {
padding: 20px;
font-family: sans-serif;
}
<div class="content">
<div class="project-info">
<div class="item">
<div class="heading">Item long text</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam molestie malesuada sem, ac elementum justo rhoncus vitae. Morbi nec ex quam. Donec finibus auctor odio, non faucibus ex tristique nec.</div>
</div>
<div class="item">
<div class="heading">Item</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam molestie malesuada sem, ac elementum justo rhoncus vitae. Morbi nec ex quam. Donec finibus auctor odio, non faucibus ex tristique nec.</div>
</div>
</div>
</div>
Update 29.09.2020
The issue seems to be gone in the latest version of Chrome (and like), can't reproduce it in Firefox as well. Would accept the answer providing a screenshot of how it looked in older versions and telling why could that happen and what exactly fixed it.
Found out that this is something to do with linebreaks / wordbreaks ...
So the first (raw) solution is to keep all the heading text in one line.
.project-info .item .heading {
...
white-space: nowrap;
}
However I'm still looking for a proper answer to allow the heading text stack up in multiple lines.
Related
I am making a full section page website like this. Each page is its own <section> tag. Currently my page has 4 sections (presented with different background colors).
My first section has a container div and inside two new divs (one for an image and the other for a description). Now when the window is minimized, the contents of the description spills over and goes over to the second page instead of being contained in the first page. To illustrate:
Please let me know what changes to make. I've been working on this issue for a long time and I have yet to find a resource or solution that works for my code..
My HTML code:
<!-- FIRST PAGE -->
<section>
<div class="content" id="about">
<!-- Picture -->
<div id="aboutImage">
<img src="img/about.jpeg">
</div>
<!-- Description -->
<div id = "aboutInfo">
<h2>Lorem Ipsum.</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br>
Suspendisse malesuada lacus commodo enim varius, <br> non gravida ipsum faucibus.
Vivamus pretium pulvinar <br> elementum. In vehicula ut elit vitae dapibus.
Cras ipsum <br> neque, finibus id mattis vehicula, rhoncus in mauris.
In <br> hendrerit vitae velit vel consequat. Duis eleifend dui vel <br> tempor
maximus. Aliquam rutrum id dolor vel ullamcorper. <br> Nunc cursus sapien
a ex porta dictum.
</p>
</div>
</div>
</section>
<!-- SECOND PAGE-->
<section id="skills"></section>
My CSS:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width: 100%;}
* {box-sizing: border-box;}
html, body {
height:100%;
position: relative;
}
section{
width: 100%;
height:100vh;
}
.content{
display: table-cell;
height: 100vh;
}
/* ABOUT */
#about {
border-bottom: #F1C40F 5px solid;
display: flex;
justify-content: space-evenly;
align-items: center;
}
#aboutImage {
padding: 30px 30px 30px 30px;
}
#aboutInfo {
border-style: dashed;
border-width: 2px;
border-color: black;
font-size: 30px;
text-align: left;
}
#aboutInfo p {
font-size: 15px;
}
/* SECOND PAGE*/
#skills {
background-color: #E3E7D3;
}
/* RESPONSIVE DESIGN */
#media screen and (max-width: 768px){
#about {
flex-direction: column; /* added */
}
}
Please please let me know how to fix this. I've been having so much trouble.
Add
overflow: scroll;
to CSS of #aboutInfo div. What this will do is that whenever there's overflow of content, instead of going to the next page, that div will scroll the content.
Test it here codepen
Additionally, i also added margin-bottom: 20px; to CSS of #aboutInfo div just so you can see that this div doesn't overflows to next page anymore.
I have chat window where I want to put photo and message next to photo. Conversation window must be responsive and message div auto-adjustable to the screen. But I can't find any way to do this, because once message has few lines of text, it drops to the next line.
If I use table, I can't make fixed-width photo TD. If I use DIVS, I can't do auto-width message DIV :)
Here is JSFiddle with an example:
https://jsfiddle.net/s95tdcLw/3/
HTML:
<div class="receiver">
<div class="receiverPhoto"></div>
<div class="receiverMessage">
Lorem ipsum dolor sit
</div>
</div>
<div class="receiver">
<div class="receiverPhoto"></div>
<div class="receiverMessage">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et mauris eget est maximus condimentum nec a turpis.
</div>
</div>
<div class="receiver">
<div class="receiverPhoto"></div>
<div class="receiverMessage">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et mauris eget est maximus condimentum nec a turpis. Nulla nulla est, feugiat vitae posuere et, efficitur ac justo. Suspendisse pulvinar, urna quis vehicula malesuada, lorem lacus luctus odio,
eu mattis nisi turpis vel lectus.
</div>
</div>
CSS:
.receiver {
clear: both;
padding-top: 1rem;
}
.receiverPhoto {
float: left;
width: 40px;
height: 40px;
background: blue;
border-radius: 20px;
}
.receiverMessage {
float: left;
width: auto;
background: rgb(230, 230, 230);
border-radius: 10px;
margin-left: 0.5rem;
padding: 10px;
}
Leave the float settings, use these instead:
.receiver {
position: relative;
}
.receiverPhoto {
position: absolute;
left: 0;
}
.receiverMessage {
margin-left: 45px;
}
jsFiddle
Your .receiverMessage element should not float and it should reserve left-margin space for the .receiverPhoto element.
.receiverMessage {
/* should not float */
width: auto;
background: rgb(230, 230, 230);
border-radius: 10px;
margin-left: 50px; /* reserve space of .receiverPhoto width */
padding: 10px;
}
See the forked Fiddle: https://jsfiddle.net/092b077c/
In response to your comment how to make it work for the opposite...
I'd use the classes on the wrapping div elements to determine the message type. In my example I introduce a new class .sender. Now I create four selectors that determine whether the photo element floats left or right and whether the message element has left or right padding:
New CSS:
.sender .receiverPhoto {
float: right;
}
.sender .receiverMessage {
margin-right: 50px;
}
.receiver .receiverPhoto {
float: left;
}
.receiver .receiverMessage {
margin-left: 50px;
}
HTML:
<div class="sender">
<div class="receiverPhoto"></div>
<div class="receiverMessage">...</div>
</div>
Now the .receiverPhoto and .receiverMessage styles do not need to declare margin or float.
See the updated Fiddle: https://jsfiddle.net/092b077c/1/
Is there anyway to allow flex items to grow in width but only in height when necessary. I love flexbox but find it painful that flex items in a row all grow to the same height even when there is not content to fill them and then display additional items further down the page. Ideally I would like flex items to arrange themselves into available space when previous items don't have sufficient content to fill the box and not leave a big space.
Is this my lack of knowledge or is it just not possible? If it's not possible, could the facility be added in updates etc.
(Sorry. I tried to upload diagrams to explain but my reputation isn't enough!)
[EDIT. Code added as request. Some style left to demonstrate the white space I want to be taken up by the other flex items.]
<!doctype html>
<html>
<head>
<style>
.content {
font-size: 2em;
width: 100%;
margin: 0px;
padding: 0px;
background-color: coral;
display:flex;
flex-direction:row;
flex-wrap: wrap;
justify-content: center;
align-content: stretch;
align-items: flex-start;
}
.flex-item {
box-sizing: border-box;
flex-grow: 1;
flex-shrink: 0;
flex-basis:40vw;
background-color: rgba(255, 255, 255, 0.9);
border: 2px solid white;
border-radius: 2px;
margin: 2vmin;
padding: 2vmin;
}
</style>
</head>
<body>
<div class="content">
<div class="flex-item">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu venenatis nisi. Sed nec purus consectetur, sodales mi vel, efficitur arcu. Vivamus id congue quam. Fusce imperdiet bibendum egestas. Mauris porttitor risus id pharetra pharetra. Vivamus et lorem erat. Nullam ac nulla ex. Nulla sit amet semper ligula. Integer augue sem, pharetra in ex ut, finibus mollis neque. Integer vulputate dolor massa, a maximus sem vehicula malesuada. Morbi a nulla ornare, egestas nisl in, ultrices est. Integer ut maximus elit. Cras ac velit condimentum, dapibus dui quis, mattis ex.
</div>
<div class="flex-item"><img src="https://pixabay.com/get/ec8630811c846e5862cb/1442266437/wheat-797086_1280.jpg" width="100%">
</div>
<div class="flex-item">Vivamus semper at tortor a lacinia. Nulla a suscipit felis. Aliquam erat volutpat. Integer dignissim suscipit nibh a accumsan.Fusce gravida nisl nec elit placerat porta. Ut feugiat feugiat lorem nec commodo. Morbi porttitor vel sapien id tincidunt. Vivamus venenatis pellentesque tempus.
</div>
<div class="flex-item"><img src="https://pixabay.com"/get/ec8630811c846e5862cb/1442266437/wheat-797086_1280.jpg" width="100%"> </div>
</div>
</body>
</html>
Apparently my question is not clear enough! I will try and expand with the sites constraints but not being allowed to post a diagram doesn't help.
There are Flex item boxes containing text, images or both. Flex item boxes containing images scale to the available space.
With high resolutions, text only boxes are the same width and height (square) so images scale ok (square) and all is chipper. However at say viewports of 400 px wide, the boxes containing just text, become long (say 200 x 1000px for sake of argument) and the image boxes are 200 x 200px (square). The next line is then display after the bottom of the flex item text leaving a big gap (say 800px high) below the image. Other flex boxes could fit in the space after the shrunk image but they don't move into the gap. Is that clear people who put the question on hold??
what you are looking for is the 'align-content' property which is default set to 'stretch' and justifies elements vertically (the cross-axis).
Opposed to 'justify-content', default 'flex-start' which justifies elements horizontally (main-axis).
'align-self', default 'auto', can be used to control individual items.
In other cases giving the max-height and height properties the same value will work too.
Which option to use depends on your personal requirement.
A very good resource for background info: Codrops CSS Reference - Flexbox
#Sharon
I believe here is your answer. Essentially everything in your solution has a relative width and height. Thus your inner box too. Giving your 'flex-item' both a min and max height will prevent height resizing. You need to do some more stuff, so have a look at the code.
body {
overflow: hidden;
/* just for testing, remove */
}
.flex-content {
width: 100%;
margin: 0;
padding: 0;
display: flex;
flex-flow: row wrap;
}
.flex-item {
flex: 1 1 40vw;
min-height: 50px;
max-height: 50px;
background-color: rgba(255, 255, 255, 0.7);
text-align: center;
border: 2px solid white;
border-radius: 2px;
margin: 2vmin;
padding: 2vmin;
background-color: #fce4ec; /* for testing*/
}
<div class="flex-content">
<div class="flex-item">some text</div>
<div class="flex-item">some text data</div>
<div class="flex-item">some more text data</div>
<div class="flex-item">again some more text data</div>
<div class="flex-item">some text</div>
<div class="flex-item">some text data</div>
<div class="flex-item">some more text data</div>
<div class="flex-item">again some more text data</div>
<div class="flex-item">some text</div>
<div class="flex-item">some text data</div>
<div class="flex-item">some more text data</div>
<div class="flex-item">again some more text data</div>
</div>
For the sake of brevity, please consult this depiction of my template (your web browser might give you a false positive about that website), that fiddle made with a chunk of my code and a sample of my H.T.M.L. file.
<html>
<!--[…]-->
<body>
<!--[…]-->
<article>
<div class="latest_article_preview">
<img class="latest_article_thumbnail" src="16x9_ratioed_picture.jpg" width="222" height="124"></img>
<div class="latest_article_headline">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
<div class="latest_article_lede">
Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehi
</div>
<div class="read_more">
Read more…
</div>
</div>
</article>
<!--[…]-->
</body>
</html>
Each latest_article_preview visually has three sub-divisions : latest_article_thumbnail, latest_article_headline and latest_article_lede. Technically, there is a fourth one (for now called "read_more") that shall visually replace latest_article_lede.
Wherever latest_article_preview gets hovered by the cursor, latest_article_lede shall be replaced by read_more.
Still, read_more is not a link to the article page as the entire latest_article_preview box is clickable (even before the to-be-animated transitions are over).
This has to be written in vanilla C.S.S., for I know two ways to do such an interaction :
The z-index transformation trick.
The content replacement.
I first tried the content replacement. As it terribly failed when I came to combine it with animations, I went to try the z-index transformation trick.
The reason I first avoided that trick is that I find it dirty. I still chose it anyhow. But I am bugging on something : how can I make the read_more flexible box take the exact same space as the latest_article_lede one ? I tried the C.S.S.'s Position property but the results were unsatisfying either (also, I remember absolute positioning being incompatible with animations).
I searched Google to know if I could base its size, positioning and alignment parameters on latest_article_lede's without finding any satisfying answer at all (despite being sure that the Flex property could help).
… After what I plan to add animations (mostly if not only fading effects), already having those. Animations that, as said earlier do not really go with the Content property.
Any samaritan to save me on this ? Help will be much appreciated.
A simple solution would be a combination of pointer-events and opacity:
section {
width: 200px;
border: 1px solid black;
}
section div {
min-height: 200px;
padding: 20px;
position: relative;
perspective: 1000px;
}
section div:after {
content: 'Read more...';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(255, 255, 255, 0.8);
line-height: 200px;
text-align: center;
opacity: 0;
pointer-events: none;
transition: all .2s;
transform: translateZ(200px);
}
section div:hover:after {
opacity: 1;
transform: translateZ(0);
pointer-events: auto;
}
<section>
<h1>Headline</h1>
<div class="content">Lorem Ipsum Dolor sit Amet!</div>
</section>
In my fiddle you will see a break in text, I would like to put a <hr> there and decorate it in the CSS, but I have no idea how to do this as when I do this it breaks my inline-block, and I'm thinking that's because the <hr> is a block element. Is there any creative solutions around this? I need it to be fixed there between the two paragraphs of text to maintain responsiveness.
Thanks!
FIDDLE
HTML:
<section>
<div class="first">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut rutrum, nisl id ultricies sollicitudin, neque sapien porta nisl, ut gravida elit quam id nisi. <br /><br />Nunc viverra laoreet porttitor. Duis augue justo, pellentesque a luctus eget, luctus a quam. Fusce nec neque nec dolor mattis tempor id vitae nisi.</p>
<img class="ipad" src="http://img1.lesnumeriques.com/news/26/26963/ipad-4-os.jpg">
</div>
</section>
CSS:
.first {
height: 100%;
line-height: 0;
}
.first p {
vertical-align: middle;
display: inline-block;
width: 49%;
}
.ipad {
vertical-align: middle;
display: inline-block;
width: 49.2%;
}
p {
margin: 0;
padding: 1em 0;
font-size: 1.8em;
line-height: 1.5;
}
You could achieve this by wrapping your <p> and <hr> elements into another <div> element, and making it display:inline-block. My solution involved adding this wrapper so your structure ended up being:
<section>
<div class="first">
<div class="text-wrap">
<p></p>
<hr />
<p></p>
</div>
<img class="ipad" src="http://img1.lesnumeriques.com/news/26/26963/ipad-4-os.jpg" />
</div>
</section>
(Additional element is .text-wrap. Note that I split up the two paragraphs into individual <p> elements.) The CSS I left mostly alone, except I removed the definition for .first p, and added these two:
.text-wrap{
vertical-align: middle;
display:inline-block;
width:49%;
}
.text-wrap p {
vertical-align: middle;
display: inline-block;
}
Here's a JSFiddle example that shows what this achieves. If this isn't what you were looking for, or you wanted to use a different method, let me know and I'll be happy to help further!
Here's an alternative to Serlite's answer. It basically puts the <hr> in implicitly, using CSS.
fiddle
We add a border to the top of each paragraph, except the first one in each container.
p {
...
border-top: 1px solid black;
}
p:nth-child(1) {
border-top: none;
}