Centring text in CSS within a "V" shape - html

I have this picture.
Is this possible in CSS?
Now I know you can use text-align: center and I could even make every line a span and incrementally increase the padding but is there a property I don't know about like centre from centre, or something similar?
This feels really obvious but I just can't think of a reasonable approach.
Update
The question was because in the picture the text tends to get shorter towards the bottom, much like the letter V, so t starts off wide and gets progressively narrower.
I had never seen a similar thing done so was very curious.

shape-outside can do it:
.wrapper {
display:flex; /* this is needed for the percentage height */
}
.box {
font-size: 25px;
text-align:justify;
}
.box > div,
.box::before{
height:150%; /* should be at least 100% but we consider bigger to avoid overflow */
width:100px; /* adjust this */
}
.box > div {
float:right;
shape-outside:linear-gradient(to bottom right,#0000 50%,#000 0);
}
.box::before {
content:"";
float:left;
shape-outside:linear-gradient(to bottom left,#0000 50%,#000 0);
}
/* the below is not need, it's only to illustrate the shape
uncomment it to see what is happening
.box > div {
background:linear-gradient(to bottom right,#0000 50%,red 0);
}
.box::before {
background:linear-gradient(to bottom left,#0000 50%,green 0);
}
*/
<div class="wrapper">
<div class="box">
<div></div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pretium lacus ipsum, at placerat nunc sollicitudin scelerisque. Donec vulputate ex odio, et facilisis nisi tristique et. Maecenas tortor nisi, euismod et tellus sit amet, tincidunt congue
eros. Nam et viverra magna, id ultricies augue.
</div>
</div>

White-space: break-spaces.
With appropriate width you will get this:
#text {
font-family:sans-serif;
padding:10px;
text-align: center;
width: 600px;
white-space: break-spaces;
background-color:gray;
color: silver;
}
<div id="text">“Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sodales ultrices nibh
at bibendum. Vivamus in volutpat diam. Vivamus ut mi non leo vehicula mattis.
Maecenas nec dolor id tellus consequat laoreet nec sit amet lacus.”
Jane from Cool Business Ltd</div>

Just apply text-align:center on the parent div.
Like this:
<div style='text-align:center'>
Your<br>
Multiline<br>
Text<br>
</div>

Related

Transparent Background in Front of Another Background

I have two DIVs that are layered; one in front (z-index:1), and one in back (z-index:-1). I would like the DIV in front to have a 'background-color: transparent', and the DIV in back to have a 'background-color: grey'.
The problem is the transparent color just shows grey (which is expected I suppose), so both DIVs display as one color. Is there a way to have an inner DIV that has a transparent color, and then a larger DIV around it that has a different background color wherever there isn't overlap?
Maybe you want something like this:
body {
background:url(https://lorempixel.com/g/1000/800/) center/cover;
}
.container {
margin:50px;
padding:20px;
--c:linear-gradient(red,red);
background-image:var(--c),var(--c),var(--c),var(--c);
background-size:30px 100%,100% 30px;
background-position:left, top,right,bottom;
background-repeat:no-repeat;
position:relative;
color:#fff;
}
.overlay {
position:absolute;
content:"";
top:30px;
left:30px;
right:30px;
bottom:30px;
background:rgba(0,255,0,0.5);
}
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vitae mollis nisi. Mauris vestibulum ac lacus ac vulputate. Maecenas molestie ex dolor, et aliquet augue varius sit amet. Vivamus eleifend nisl nulla, a pellentesque ipsum pharetra eget. Curabitur tincidunt non nibh vitae convallis. Nunc magna
<div class="overlay"></div>
</div>

How to extend columns background outside of grid, while maintaining grid in center of page?

Some time ago, i was hired to create company website. With help of Zurb Foundation Framework, i created site with layout like this:
It's just a grid with several rows(for header, main area, and footer), each of which divided to two columns(4 for left side and 8 for right side).
Client loved this design, so it was deployed to production.
Several months later, client started to want something new in this site design. So he hired independent designer for consultation. Designer said that everything is good, but it's need some "simple feature" - background colors for some visual blocks. He photoshoped screenshot of site and send it to client.
With his edits, new site layout should look like this:
Is there any way to make blocks backgrounds be extended to outside of the grid, while maintaining grid itself in center of page? And if it's not possible, and only way is to add additional blocks for that 'extending backgrounds' - how to maintain their height and position in sync with main layout blocks?
Is there any way to get this with minimal number of edits, without rebuilding whole layout?
You can use background-size and position with gradient or image :
you can reverse gradient .... (example in codepen linked below playing with colors)
codepen to play with
main , header div, footer div{
width:800px;
margin:auto;
box-shadow: 0 0 5px;
}
* {
box-sizing:border-box;
}
section , header h1, footer nav{
width:600px;
float:right;
padding:1em;
}
footer h3 {
float:left;
width:200px;
}
footer {
text-align:center;
line-height:50px;
overflow:hidden;
}
li {
display:inline-block;
margin:0;
}
aside {
padding:1em;
overflow:hidden;
}
html {
background:linear-gradient(to left, gray 74.25%,black, white 74.5% ) center repeat-y ,linear-gradient(to left, gray 50%, white 50% ) gray repeat-y top right;
background-size: 800px 800px, 100% 100% ;
min-width:800px;/* mind this */
}
img {
margin:20px 50px;
}
header{
background:linear-gradient(to left, white 74.25%,black, gray 74.5% ) center repeat-y ,linear-gradient(to left, white 50%, gray 50% ) gray repeat-y top right;
background-size: 800px 800px, 100% 100% ;
min-width:800px;/* mind this */
}
footer {
background:linear-gradient(to left, white 74.25%,black, gray 74.5% ) center repeat-y ,linear-gradient(to left, turquoise 50%, tomato 50% ) gray repeat-y top right;
background-size: 800px 800px, 100% 100% ;
min-width:800px;/* mind this */
}
body {
margin:0;
display:flex;
min-height:100vh;
flex-direction:column;
}
main {
flex:1;
}
<header>
<div class="top">
<h1> play me in full page</h1>
<img src="http://lorempixel.com/100/100/"/>
</div>
</header>
<main>
<section><h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
</section>
<aside>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}
</code></pre>
</aside>
</main>
<footer>
<div class="top">
<h3>footer title </h3>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Clients</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</footer>

Having 2 responsive Divs Side By side

So basically I am trying to make a page with 2 responsive columns, the same size side by side and instead of using px for measurement I'm sizing them using percentage. No matter what I do, setting both divs to have a margin of 5% and width of 40% they should sit side by side in a container with 'display: inline-block'. But for some reason it's not.
Here's the J-Fiddle demonstrating my issue. I have content above and below these divs on the page I'm working on... so they can't interfere with that, using, declaring float positions just seems to complicate things further.
http://jsfiddle.net/avh9s6pa/
If you guys could help I'd really appreciate it. It'll be something simple no doubt, but it's driving me nuts.
.post-reg-columns {
width: 100%;
display:block;
}
.firstcolumn {
display: inline-block;
max-width: 40%;
margin:5%;
padding:10px;
}
.firstcolumn button {
color: #fff;
background-color: #6496c8;
text-shadow: -1px 1px #417cb9;
border: none;
font-size: 1.4em;
font-family: 'Bree Serif', serif;
font-weight:bold;
width: 100%;
padding:15px;
}
.firstcolumn button:hover {
background-color: #416386;
}
.secondcolumn {
display: inline-block;
background:#fff7ca;
max-width: 40%;
margin:5%;
padding:10px;
}
<div class="post-reg-columns">
<div class="firstcolumn">
<div class="title2"> Basic Listing </div>
<button>Test Button</button>
ewfwefw efwefwefw fwefwef wefwefwef wefwefwe fwefwef wefefw efwe fefwefwefw eiofj erio jweriojgjphi owriog jerioj gerijg ejfwefwef wefj weijfwe jfjiw efjwej wef weijf hello this is a test blah blah blah! My name is Chris Mayberry and this is a test
</div>
<div class="secondcolumn">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod sollicitudin magna, sed placerat dui pretium quis. Vivamus sit amet velit nisi. Etiam consectetur mauris ligula, id fermentum felis fermentum ac. Phasellus pharetra a lorem ac dictum. Nullam vitae tempor ex. Mauris in vehicula augue. Maecenas sit amet porttitor enim, eu vehicula orci. Aliquam id nisl non sem mattis varius in sed nulla. Nulla ultrices fringilla erat, vitae tincidunt turpis malesuada vitae. Cras vehicula ex at arcu eleifend cursus. Sed varius dignissim risus eu fringilla.
</div>
</div>
As per your code, both divs have 40% width which means total 80%. Further, 5% margin which mean 5*4 =20%. So total becomes 100% here. And in your second div it has also 5% margin which force it to break as (100%+20%) there is no more space. You need to remove margin:5%; from .firstcolumn.
Check this fiddel
Remove margin:5%; from .firstcolumn class.
Demo here
Update answer
.post-reg-columns {
width: 100%;
display:block;
margin:5%
}
Demo Here

CSS equal height columns with :before - unexpected background behaviour/stacking order

I'm trying to implement something based upon:
http://webdesign.tutsplus.com/tutorials/quick-tip-solving-the-equal-height-column-conundrum--cms-20403
In a nutshell, here is my test case:
http://jsfiddle.net/7CGCW/
Why are not both .panel's displayed with a green background?
All is well when my column sits atop a background-color'ed BODY (the second .panel), but when it sits atop a background-color'ed block (the first .panel, on top of .content), then the background of this DIV appears to sit atop my column, even when it is seemingly given an z-index that is lower in the stacking order.
The HTML:
<div class="content">
<div class="positioned">
<div class="panel">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vel rutrum libero. Proin in metus id odio rutrum posuere at ac dui. Etiam sollicitudin in dui sed imperdiet. Suspendisse eu erat nec ipsum facilisis iaculis.
</div>
</div>
</div>
<div class="positioned">
<div class="panel">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vel rutrum libero. Proin in metus id odio rutrum posuere at ac dui. Etiam sollicitudin in dui sed imperdiet. Suspendisse eu erat nec ipsum facilisis iaculis.
</div>
</div>
The CSS:
body {
background-color: red;
color: blue;
}
.content {
background-color: red;
z-index: -2;
}
.positioned {
position: relative;
}
.panel:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
z-index: -1;
background-color: green;
width: 100%;
}
your content div needs to be positioned for z-index to work - read this about stacking context
at the moment it will have a z-index of 0 so it will be above your :before content
try
.content {
background-color: red;
position:relative;
z-index: -2;
}
Example
ps, that tutorial is rubbish - if he is going to use pseudo selectors to make a background be equal height then he may as well make use of the display table property for proper equal height columns
Much easier to do with less markup and styles and don't have to think about all that z-indexing and positioning

Native IE8 - Why do these 'inline-block' elements not 'wrap words' if their parent is the first floated item?

Sorry in advance, this is long and weird.
I found this bug in native IE8 when working with Bootstrap and have stripped it all the way back to find the cause. But I want to know why it happens.
The setup: I have a .container, inside the container I have a .box (another container essentially) and inside that box I have a <div> element that is display: inline-block.
The conditions: .box must be floated.
The issue: The inline block element that is inside the first .box element will have it's text not wrapping (it will overflow the containers). The inline block element that is inside any other .box element will have it's text wrapping as expected.
Fixes: This can be fixed either removing the float of the .box or by applying a border to the .inline-block element (can be transparent), suggesting that it's a hasLayout bug (although zoom: 1 doesn't fix it). But I thought display: inline-block didn't have the hasLayout bug?
So why does this issue happen and why is it only that first child?!?
I've put the demo code on my server as JSBin doesn't work on IE8, sorry for the link off.
HERE'S THE DEMO
Demo HTML
<div class="container">
<h2>A container (red) with 1 box child (blue) which has 1 inline-block child (green background - border will fix issue)</h2>
<div class="box">
<div class="inline-block">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis lectus metus, at posuere neque. Sed pharetra nibh eget orci convallis at posuere leo convallis. Sed blandit augue vitae augue scelerisque bibendum. Vivamus sit amet libero turpis, non venenatis urna. In blandit, odio convallis suscipit venenatis, ante ipsum cursus augue.</div>
</div>
</div>
<div class="container">
<h2>A container (red) with 2 box children (blue) which each have 1 inline-block child (green background - border will fix issue)</h2>
<div class="box">
<div class="inline-block">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis lectus metus, at posuere neque. Sed pharetra nibh eget orci convallis at posuere leo convallis. Sed blandit augue vitae augue scelerisque bibendum. Vivamus sit amet libero turpis, non venenatis urna. In blandit, odio convallis suscipit venenatis, ante ipsum cursus augue.</div>
</div>
<div class="box">
<div class="inline-block">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis lectus metus, at posuere neque. Sed pharetra nibh eget orci convallis at posuere leo convallis. Sed blandit augue vitae augue scelerisque bibendum. Vivamus sit amet libero turpis, non venenatis urna. In blandit, odio convallis suscipit venenatis, ante ipsum cursus augue.</div>
</div>
</div>
</div>
Demo CSS
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
body {
margin: 0;
}
.container {
width: 800px;
margin: 10px auto;
padding: 10px;
border: 1px solid red;
}
/* Clear the float */
.container:before,
.container:after {
content: " ";
display: table;
}
.container:after {
clear: both;
}
.box {
float: left; /* THIS IS THE TRIGGER (without float it works) */
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid blue;
}
.inline-block {
display: inline-block;
background: #c4df9b;
/*border: 1px solid green;*/ /* Having a border fixes it (when there's a float) */
}
.inline-block + .inline-block {
background: #9db678;
}
BIG PICTURE!
Is there any specific reason to use display: inline-block; in class .inline-block
I use all your code and here is the Demo. checked in IE7 and IE8 works.
.block {
display: block; /*I remove the inline*/
background: #c4df9b;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
/*border: 1px solid green;*/ /* Having a border fixes it (when there's a float) */
}
.block + .block {
background: #9db678;
}