clip or ellipses text difficulties with css centered page - css

So I have some php outputted text/data that's centered on my page. I've centered it like this with css
*{
margin:0;
padding:0;
}
body{
text-align:center; /*For IE6 Shenanigans*/
font-size: 100%;
font-weight: 1;
font-family: 'rationale';
background:black;
}
#data {
position: absolute;
width: 100%; /*makes the element 100%, to center it. */
top: 180px;
right: 0px;
line-height: 40px;
}
I'd like to make the data a truncated output, where after a certain amount of space it cuts the output off and gives a "...".
text-overflow: ellipsis;
If I can't get that to work, I'm okay with a
text-overflow: clip;
Thing is, I can't get it to work with my existing css, I believe because to have the text-overflow work, I have to set the width to a specific size. But, when I do this and remove the width 100% on my data, no longer is it centered nicely.
*By the way the reason for the two css divs before data, is that it keeps my entire page centered regardless of any resizing, which is helpful.
Any thoughts on how to get this working, in this situation? A bit stuck.
Thanks so much.

You can get by using following css approach
.box {
text-align: center;
border: 1px solid red;
width: 500px;
margin: 0 auto;
}
.content {
width: 50%;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
margin: 0 auto;
}
<div class="box">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda adipisci vel, dolore aspernatur iste iure blanditiis quam esse repudiandae aperiam debitis doloribus necessitatibus placeat tempora voluptate totam exercitationem neque quae.
</div>
</div>

Related

flex column and wrap will let flex-item overflow

A simple layout that I want to achieve with minimal html tags
Only <img> & <h1> & <p> and no other extra tags
flex + column + wrap
The first column has only one image
The second column contains the title and crossword
The width and height of the parent layer are fixed
The result is that part of the text will overflow
Only add width to <p> to prevent
Is there any way to automatically break text without adding width?
HTML
*{
margin: 0;
padding: 0;
}
.out{
width: 600px;
height: 200px;
border: 1px solid #ccc;
padding: 20px;
margin: 50px auto;
font-family: Verdana;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
img{
/* margin-bottom: 20px; */
margin-right: 20px;
}
p{
line-height: 1.6;
overflow-wrap: break-word;
}
<div class="out">
<img src="https://picsum.photos/id/230/200/200" alt="">
<h1>This is Title</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta iure iusto cupiditate sequi aperiam, nostrum optio ipsam dicta modi officiis eligendi vel. Dignissimos delectus exercitationem nemo. Enim id sed corrupti!</p>
</div>
Another solution as per your expecation:
* {
margin: 0;
padding: 0;
}
.out {
width: 600px;
height: 200px;
border: 1px solid #ccc;
padding: 20px;
margin: 50px auto;
font-family: Verdana;
display: flex;
}
img {
/* margin-bottom: 20px; */
margin-right: 20px;
}
p {
line-height: 1.6;
overflow-wrap: break-word;
margin-left: -200px;
margin-top: auto;
margin-bottom: auto;
}
h1 {
position: relative;
white-space: nowrap;
}
p::before {
content: "";
width: 100%;
}
<div class="out">
<img src="https://picsum.photos/id/230/200/200" alt="">
<h1>This is Title</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta iure iusto cupiditate sequi aperiam, nostrum optio ipsam dicta modi officiis eligendi vel. Dignissimos delectus exercitationem nemo. Enim id sed corrupti!</p>
</div>
Here is my solution
* {
font-family: 'poppins';
}
.card {
display: flex;
padding: 15px;
border: 1px solid #8f8f8f;
}
.content {
margin-left: 10px;
}
.content h6 {
margin-top: 0;
font-size: 32px;
margin-bottom: 5px;
}
<div class="card">
<img src="//via.placeholder.com/150">
<div class="content">
<h6>This is title</h6>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
here, content here', making it look like readable English.</p>
</div>
</div>

how to make a heading always stay horizontal inplace of overflow

I am working on a portfolio project and I am creating the projects section.
The width of the projects section is around 350px so only some of the title could be visible but if the text is not able to fit in 350 px it is making the text overflow vertically but I want it to overflow horizontally.
here is my HTML&CSS:
.project-container {
display: grid;
height: 350px;
width: 350px;
background: #c4c4c4;
margin-bottom: 3%;
}
.project-title{
height: 45px;
width: 100%;
background-color: red;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
overflow: auto;
}
<div class="project-container">
<h1 class="project-title">Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores dignissimos praesentium dolorem saepe velit at libero a consectetur atque molestias.</h1>
</div>
and here is my result when the text can't fit in 350px:
but I want the overflow to be horizontal
white-space: nowrap;
I think you just want this?
.project-container {
display: grid;
height: 350px;
width: 350px;
background: #c4c4c4;
margin-bottom: 3%;
}
.project-title{
height: 45px;
width: 100%;
background-color: red;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
overflow: auto;
white-space: nowrap;
}
<div class="project-container">
<h1 class="project-title">Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores dignissimos praesentium dolorem saepe velit at libero a consectetur atque molestias.</h1>
</div>
You've given your .project-title a width which automatically means the text inside will wrap at the end of the line. If you want it to overflow horizontally instead of vertically, you need to:
Allow space for it to overflow.
Prevent it from wrapping.
This can be achieved by changing .project-title[width] to .project-title[min-width] (meaning the space is at least the width of the container, but may be larger) and setting .project-title[white-space]=nowrap (meaning text is not allowed to break across lines).
.project-container {
display: grid;
height: 350px;
width: 350px;
background: #c4c4c4;
margin-bottom: 3%;
}
.project-title{
height: 45px;
min-width: 100%;
white-space: nowrap;
background-color: red;
margin: 0;
display: flex;
overflow: auto;
}
<div class="project-container">
<h1 class="project-title">Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores dignissimos praesentium dolorem saepe velit at libero a consectetur atque molestias.</h1>
</div>
just add white-space: nowrap; to class project-title

Positioning divs inside wrapper, one of them must have y-scrollbar when content overflows

I'm trying to accomplish the following layout, but I'm having trouble with the description box height definition. I'm trying to avoid javascript.
Right now I have both the wrapper and the title bar working as they should, the title and description divs being nested inside the wrapper div:
#wrapper{
position: fixed;
right: 0;
width: calc(100vw - 1.51 * 95vh - 5vh);
top: calc(40px + 2.5vh + 2.5vh);
height: calc(100vh - 40px - 40px);
}
#title{
width: 100%;
height: auto;
top: calc(2.5vh + 40px + 2.5vh + 5vh);
}
What about the description div? Can anyone point me in the right direction?
Thanks!
Flexbox can do that.
.container {
height: 100vh;
display: flex;
flex-direction: column;
}
header {
background: lightblue;
}
.content {
flex: 1;
overflow-y: auto;
background: orange;
}
.spacer {
height: 2000px;
/* for demo purposes */
}
<div class="container">
<header>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos tenetur magnam labore laboriosam dolores, fugit ipsum quibusdam, aperiam totam itaque soluta debitis cumque provident repudiandae.</header>
<div class="content">
<div class="spacer"></div>
</div>
</div>

Can't align quote to middle

I am trying to vertically align to the middle at all times an open quote by a pseudo element. As you shrink the size it aligns, but by default it's above my quote. Is there a way I can have it vertically in the middle aligned at all times?
CSS
blockquote {
margin: 3em;
padding: 0 3em;
position: relative;
}
blockquote::before {
content: open-quote;
left: -40px;
}
blockquote::before, blockquote::after {
top: 50%;
color: #F1722E;
font-size: 124px;
position: absolute;
transform: translateY(-50%);
}
HTML
<blockquote>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus iure rem repudiandae incidunt corporis obcaecati voluptate officia. Facere laborum ipsam molestiae dolorum libero nesciunt ducimus aliquid voluptatibus. Ad praesentium fugiat.</blockquote>
http://jsfiddle.net/gfybkpc9/
You can do it by adjusting the margin top of the open quote. See this fiddle
I adjusted the CSS like so:
blockquote {
margin: 3em;
padding: 0 3em;
position: relative;
}
blockquote::before {
content:'"';
left: -40px;
}
blockquote::before, blockquote::after {
top: 50%;
color: #F1722E;
font-size: 124px;
position: absolute;
margin-top:-48px;
}
Essentially, the margin top would be half the height of the element, which would position the middle of the element at 50%, per the top property. Since it's a quote mark, we have to fudge the numbers a little.

Left align menu icon

Im trying to left align a menu icon.
The icon is displaying above the menu name but I would like to align in to the left of the menu name.
The CSS I have is:
.icon_name_here:before {
content: '';
width: 24px;
height: 24px;
display: inline-block;
float: left;
background: url('http://url_of_icon_here.com') no-repeat left;}
How / what do I have to do to align the icon to the left of the menu name?
Without posting a relevant code its hard to give a exact answer. I've tried to re-build on the assumption of the CSS you posted and here I've build a demo. See the DEMO .
CSS is like this.
ul{margin:0;padding:0;}
ul li {padding:4px;}
.icon_name_here:before {
content: '';
width: 24px;
height: 24px;
display: block;
float: left;
padding:4px;
background: url('http://lorempixel.com/24/24/') no-repeat 0 0;}
HTML is like it.
<ul>
<li class="icon_name_here">Item1</li>
<li>Item2</li>
</ul>
Updates
you have to add a display:inline-block on <a> tag. Check the uploaded image.
HOME
use display: inline style for both image and Text
You can use this method like a variant. It can be helpfull when you want to use sprites
HTML
<div class="your-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, beatae consequatur dolore doloribus dolorum harum, laboriosam magnam natus, numquam odit officiis quia quisquam suscipit tempora voluptatum. Facere quae quis sed?
</div>
CSS
.your-content {
position: relative;
padding: 0 0 0 10px; /*space between block edge and displaying of your text*/
}
.your-content:after {
content:'';
position: absolute;
top: 0px; /*position of your icon*/
left: 0px; /*position of your icon*/
width: px; /*width of your icon*/
height: px; /*height of your icon*/
background: url(img/your-icon-bg.png) no-repeat;
}

Resources