Nested underlined text elements - css

I have in text paragraphs some rather large portions of underlined texts. Many of them go over several lines.
Within those underlined elements, in some cases I have elements that should be underlined themselfes. Here, the underline of the outer underlined element should go a little down in order to make the underline of the inner underlined elments visible. Look at the third line of my mockup and you will understand what I mean (at least I hope so). "querit" and "Epicurae" are underlined within underlined elements.
How can I achieve this in CSS? With text-decoration: underline the underlines collapse and you won't see which elements are nested underlined elements. On the other hand, display:inline-block; border-bottom:1px solid black; will just underline the last line.
Edit: The HTML for this mockup would look like this: (not particulary interesting, I guess)
<p> de con firt omniandabetisporatienimusi remprobist extrum etis e ipsaenderienimagnos <span class="underlined">quibus quidas mus, ines, quam Solostracum met ipsa horum mum, esispotatus con ipid inprobus, que vollin que <span class="underlined">querit</span> pus nego mo <span class="underlined">Epicurae</span> id sitam mod etia et nectuas ent malosse te. quitus, essendolinxet ob utrus aleganesserisimone ne nitae lium vitae; Metisquiamquae sid los plego ilius, andus adexperibus vitur. quod dictantum alt, num Toriae</span> conc ocorturaec </p>

Just don't use display: inline-block. Say, we are using the tag <span class="und"> for underlining something. For a nested one, use something like this:
/* Start Praveen's Reset for Fiddle ;) */
* {font-family: 'Segoe UI'; margin: 0; padding: 0; list-style: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
body {margin: 15px;}
/* End Praveen's Reset for Fiddle ;) */
p {margin: 0 0 10px;}
.und {border-bottom: 1px solid; padding: 2px;}
.und .und {border-bottom: 1px solid; padding: 0;}
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime, cumque! Facere iste, adipisci non quam molestias modi! Reprehenderit, quo officia est voluptatibus eum omnis magni voluptate. Similique, voluptatibus quasi dolore!</p>
<p><span class="und">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque quo ea natus deserunt praesentium laudantium similique, officia sequi unde provident quasi aliquid iure, tempora sunt quod doloremque, dolor. Voluptate, tempora! <span class="und">This is double underlined and doesn't break!</span> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor commodi adipisci similique eligendi a praesentium officia repudiandae quaerat ipsum placeat natus nemo, sit magnam laborum error vero, ullam officiis veniam!</span></p>
Nested Items
/* Start Praveen's Reset for Fiddle ;) */
* {font-family: 'Segoe UI'; margin: 0; padding: 0; list-style: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
body {margin: 15px;}
/* End Praveen's Reset for Fiddle ;) */
p {margin: 0 0 10px; line-height: 1.5;}
.und {border-bottom: 1px solid; padding: 4px;}
.und .und {border-bottom: 1px solid; padding: 2px;}
.und .und .und {border-bottom: 1px solid; padding: 0;}
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime, cumque! Facere iste, adipisci non quam molestias modi! Reprehenderit, quo officia est voluptatibus eum omnis magni voluptate. Similique, voluptatibus quasi dolore!</p>
<p><span class="und">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque quo ea natus deserunt praesentium laudantium similique, officia sequi unde provident quasi aliquid iure, tempora sunt quod doloremque, dolor. Voluptate, tempora! <span class="und">This is double underlined and <span class="und">triple consectetur adipisicing</span> doesn't break!</span> Lorem ipsum dolor sit amet, elit. Dolor commodi adipisci similique eligendi a praesentium officia repudiandae quaerat ipsum placeat natus nemo, sit magnam laborum error vero, ullam officiis veniam!</span></p>

Related

Remove only text-shadow from selected text with just CSS

I styled some text to have a faint white text-shadow so that when it passes on a same-color background, it's style legible. The issue comes in that when I select the text, it becomes difficult to read thanks to the text-shadow being the same color as the text.
body {
background-color: #CCC;
margin: 0px;
}
div {
padding: 1.5em;
}
div + div {
margin: 2em 0 0;
}
div p:last-child {
margin: 0em;
}
p {
text-shadow: 0 0 3px #FFF;
margin: 0 0 1em;
}
.actual-effect ::selection {
text-shadow: none;
}
.intended-effect p {
text-shadow: none;
}
<div class="actual-effect">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Optime, inquam. Istam voluptatem, inquit, Epicurus ignorat? Inde igitur, inquit, ordiendum est. Eam tum adesse, cum dolor omnis absit; Ne discipulum abducam, times. </p>
<p><i>Certe non potest.</i> <mark>Honesta oratio, Socratica, Platonis etiam.</mark> Duo Reges: constructio interrete. Recte dicis; Hoc loco tenere se Triarius non potuit. </p>
<p>Non igitur bene. Utram tandem linguam nescio? <b>Quis est tam dissimile homini.</b> Quae sequuntur igitur? Quod ea non occurrentia fingunt, vincunt Aristonem; Hoc ipsum elegantius poni meliusque potuit. </p>
</div>
<div class="intended-effect">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Optime, inquam. Istam voluptatem, inquit, Epicurus ignorat? Inde igitur, inquit, ordiendum est. Eam tum adesse, cum dolor omnis absit; Ne discipulum abducam, times. </p>
<p><i>Certe non potest.</i> <mark>Honesta oratio, Socratica, Platonis etiam.</mark> Duo Reges: constructio interrete. Recte dicis; Hoc loco tenere se Triarius non potuit. </p>
<p>Non igitur bene. Utram tandem linguam nescio? <b>Quis est tam dissimile homini.</b> Quae sequuntur igitur? Quod ea non occurrentia fingunt, vincunt Aristonem; Hoc ipsum elegantius poni meliusque potuit. </p>
</div>
I'm not sure how other browsers render this, but currently in Firefox it accurately removes the text-shadow, but it loses all of the default stylings it would have had had I not changed it (ie. white text, blue background, inverted colors when juxtaposed against a certain backgrounds, etc).
Is there a way to modify ::selection without losing all of the default values? I'd rather not re-add all of the default styles unless that were the only option available.
The issue isn't avoiding that the text-shadow makes things difficult to read, it's more-so trying to avoid p::selection from losing everything else.
Sorry for previous answer 😔🙏.
You can set the text-shadow to 0 0 0.
Example :
body {
background-color: #CCC;
margin: 0px;
padding: 1.5em;
}
p {
text-shadow: 0 0 3px #FFF;
margin: 0 0 1em;
}
::selection {
text-shadow: 0 0 0 !important;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Optime, inquam. Istam voluptatem, inquit, Epicurus ignorat? Inde igitur, inquit, ordiendum est. Eam tum adesse, cum dolor omnis absit; Ne discipulum abducam, times. </p>
<p><i>Certe non potest.</i> <mark>Honesta oratio, Socratica, Platonis etiam.</mark> Duo Reges: constructio interrete. Recte dicis; Hoc loco tenere se Triarius non potuit. </p>
<p>Non igitur bene. Utram tandem linguam nescio? <b>Quis est tam dissimile homini.</b> Quae sequuntur igitur? Quod ea non occurrentia fingunt, vincunt Aristonem; Hoc ipsum elegantius poni meliusque potuit. </p>
Previous Answer (unsatisfactory)
It's because background, change that. I'm try use background-color: transparent, but it's not work. So, in this code i use background-color: #fff.
p {
text-shadow: 2px 2px #FF0000;
}
p::selection {
background-color: #fff;
text-shadow: none;
}
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Autem numquam, laboriosam distinctio impedit qui explicabo corporis optio commodi officiis ratione voluptates corrupti, temporibus iusto recusandae facilis nobis obcaecati nisi quisquam iste ullam excepturi iure. Ratione, molestiae mollitia vitae, error soluta illum ex accusamus voluptatem tempora hic aut rerum! Recusandae impedit consectetur consequatur dolorum, dolore aut officiis nam tenetur aliquid repudiandae natus velit sapiente vero esse, dolor quasi illo at consequuntur aperiam explicabo iusto corporis ex fugit architecto? Placeat, unde suscipit expedita enim ab vel iste cumque quas, asperiores adipisci accusamus? Et, minus. Saepe magni quo, ipsam enim earum placeat voluptates.</p>

Separate two columns using flexbox

I'm new in css
I create two columns using flexbox, so I want to divide them 50% and 50%.
blockquote {
font-family: Georgia, serif;
font-size: 18px;
font-style: italic;
color: #383838;
border-right: 1px solid gray;
}
blockquote:before {
display: block;
content: "\201C";
font-size: 80px;
color: #0e4f1f;
text-align: center;
}
#about-us{
display: flex;
}
.about-us__slogan{
margin:6em 0 0 2em;
text-align: center;
}
.about-us__business{
flex:50%;
}
.about-us__business__title{
color:#0e4f1f;
margin: 2em 0 0 2em;
}
.about-us__business__info{
text-align:left;
}
<section id="about-us">
<p class="about-us__slogan"><blockquote>
“Neque porro quisquam est qui dolorem <br/>
Neque porro quisquam est qui dolorem<br/>
Neque porro quisquam est qui dolorem<br/>
Neque porro quisquam est qui dolorem.</p>
</blockquote>
<div class="about-us__business">
<h1 class="about-us__business__title">Neque porro quisquam est qui dolorem</h1>
<p class="about-us__business__info">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet,
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit.
porro.</p>
<p>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet
pNeque porro quisquam est qui dolorem ipsum quia dolor sit amet.</p>
</div>
</section>
As you can see it's not 50% and 50%, I try using flex:50%. in .about-us__slogan class but it no work, it just create big space at the left.
I think it's not that dimensions because size wrap to the content, how can I fix that? Regards
Your child divs about-us__slogan & about-us__business both needed to be flex:1 so they are equal in size to each other with their parent div about-us with display: flex.
Some of your nesting had also got a little messed up in your example code above so I have tidied it a little for you also.
Try this:
.about-us {
display: flex;
}
.about-us__slogan {
flex: 1;
margin: auto 1rem;
border-right: 1px solid gray;
}
.about-us__blockquote {
font-family: Georgia, serif;
font-size: 18px;
font-style: italic;
color: #383838;
text-align: center;
margin: 0;
}
.about-us__blockquote:before {
display: block;
content: "\201C";
font-size: 80px;
color: #0e4f1f;
}
.about-us__business {
flex: 1;
margin: auto 1rem;
}
.about-us__business-title {
color: #0e4f1f;
}
.about-us__business-info {
/* Add styles you would like to use if any */
}
<section class="about-us">
<div class="about-us__slogan">
<blockquote class="about-us__blockquote">
<p class="about-us__slogan-text">
Neque porro quisquam est qui dolorem Neque porro quisquam est qui dolorem Neque porro quisquam est qui dolorem Neque porro quisquam est qui dolorem.</p>
</blockquote>
</div>
<div class="about-us__business">
<h1 class="about-us__business-title">Neque porro quisquam est qui dolorem</h1>
<p class="about-us__business-info">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit. porro.</p>
<p class="about-us__business-info">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet Neque porro quisquam est qui dolorem ipsum quia dolor sit amet Neque porro quisquam est qui dolorem ipsum quia dolor sit amet Neque porro quisquam est qui dolorem ipsum quia dolor sit
amet pNeque porro quisquam est qui dolorem ipsum quia dolor sit amet.</p>
</div>
</section>

Why is my margin bottom on my float not correct?

I have a content box in which I want a div box that floats to the left and paragraphs that flow around it. So far my HTML looks like this:
.content {
float: left;
padding: 20px;
width: 650px;
height: 500px;
background-color: #F5CF8E;
/* Yellowish */
}
.fake-image {
float: left;
width: 200px;
height: 200px;
border: 0.5px solid gray;
padding: 20px;
margin: 0 20px 20px 0;
}
<div class="content">
<div class="fake-image"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
</div>
What I really don't get is why is the margin-bottom: 20px; of my .fake-image not working? The margin is bigger. Can anyone help?
Here an image of what I mean:
This space is not extra margin. It's the remainder of the height of the wrapping line
In other words, the line that breaks under the image may not break perfectly to match the exact spot where your margin ends unless your lines perfectly divide that space somehow. It would be unreasonable to try to control this for most situations, however, hypothetically you could accomplish a fix if it were completely static content, but I don't recommend trying to do this because you might be fighting an uphill battle.
To test this for yourself: remove all margins except for your bottom margin on your image and manipulate line-height and typography stylings to see how they play together and/or manipulate only the bottom margin on that image and/or the image height.
Whenever I have an issue like this, I add specificity to the related CSS. margin in this case. margin: 0 20px 20px 0; shorthand for margin-top:0; margin-right: 20px; margin-bottom:20px; margin-left:0;
Fix the bottom by knowing also what is around it.
Here I add a div around it and set it's background so you see where the image actually IS. Other space belongs to other elements.
Now, we have the ugly lime and red we can see what is what, adjust that image and paragraphs etc., then we can later remove those ugly CSS things.
.content {
float: left;
padding: 20px;
width: 650px;
height: 500px;
background-color: #F5CF8E;
/* Yellowish */
}
.fake-image {
float: left;
width: 200px;
height: 200px;
border: 0.5px solid gray;
padding:20px;
/* margin-top: 0;
margin-left: 20px;
margin-right: 20px;
margin-bottom: 20px; */
margin: 0 20px 20px 0;
}
.outside-image{float: left;background-color:lime;}
p {border:1px solid red;}
<div class="content">
<div class="outside-image"><div class="fake-image"></div></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam incidunt dolores atque ipsam expedita architecto, dignissimos error consectetur aperiam. At harum in optio voluptatibus ex beatae praesentium eius velit cum!</p>
</div>

CSS file for children of one section

I have many sections on my page. Every of these sections can have similar elements, for example in each of these sections can be h1 element.
I want to add css files where every of these css will be for only one section.
For example I have three sections on my page where ids are:
section1 -- section2 -- section3
I have three css files too with names:
section1.css -- section2.css -- section3.css
How to do that every css file refers to a suitable section?
Maybe can I add any additional block to every of these css files with section id?
I don't know why you want to do that, but if you want to have separate styles for each section which has unique ID just use the ID as a selector. For example:
section1.css
#section1 h1{ color:red;}
#section1 .someclass { color: blue}
section2.css
#section2 h1 { color: green;}
#section2 .someclass {color:yellow;}
And so on. You will have separate styles for each section selecting them by ID. I think it's the easiest way
CSS files doesn't refer to its elements (in your case id). Its the selector which actually targets elements. You can use separate for each of the children on each section.
Instead use inheritance with each id.
Have a look at the example snippet below:
/* Section 1 */
#section1 {
background: #ff0;
padding: 10px 15px;
}
#section1 p {
background: #99d;
}
/* Section 2 */
#section2 {
background: #99d;
padding: 10px 15px;
}
#section2 p {
background: #ae9;
}
/* Section 3 */
#section3 {
background: #ae9;
padding: 10px 15px;
}
#section3 p {
background: #ff0;
}
body {
margin: 0;
}
<div id="section1">
<strong>Section 1</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas quam dicta libero qui sapiente beatae sunt, aspernatur et reprehenderit natus dolor, sint aliquid iure magni quibusdam accusantium provident perspiciatis fugit.</p>
</div>
<div id="section2">
<strong>Section 2</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas quam dicta libero qui sapiente beatae sunt, aspernatur et reprehenderit natus dolor, sint aliquid iure magni quibusdam accusantium provident perspiciatis fugit.</p>
</div>
<div id="section3">
<strong>Section 3</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas quam dicta libero qui sapiente beatae sunt, aspernatur et reprehenderit natus dolor, sint aliquid iure magni quibusdam accusantium provident perspiciatis fugit.</p>
</div>
Hope this helps!

How to get content to fit snug with border-image

fiddle
.chrome-frame {
border-width: 80px 120px 1px 324px;
border-image: url(http://i.imgur.com/m7QqzJi.png) 80 120 1 324 stretch;
border-image-outset: 0;
box-sizing: border-box;
}
<div class="chrome-frame">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem earum in necessitatibus neque veritatis. Ab aspernatur delectus dignissimos eaque eius fugiat hic, ipsa modi natus, officiis reiciendis sequi totam voluptates. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit id neque nostrum perferendis, quam quas quibusdam, quisquam quos repellat repellendus, repudiandae sequi. Amet dolor eligendi excepturi ipsa molestiae placeat veniam!</div>
border-image requires me to set huge borders to render my image border correctly, but I don't want my content nudged in that far.
How can I get my content to ignore the borders so that I can use paddings to position it how I want?
Put the border image in the ::before pseudo element and put it behind the text. The text itself can be positioned using padding.
.chrome-frame {
position: relative;
padding: 90px 10px 10px 10px;
}
.chrome-frame::before {
display: block;
left: 0;
top: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
content: "";
border-width: 84px 120px 1px 324px;
border-image: url(http://i.imgur.com/m7QqzJi.png) 84 120 1 324 fill;
border-image-outset: 0;
box-sizing: border-box;
}
<div class="chrome-frame">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem earum in necessitatibus neque veritatis. Ab aspernatur delectus dignissimos eaque eius fugiat hic, ipsa modi natus, officiis reiciendis sequi totam voluptates. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit id neque nostrum perferendis, quam quas quibusdam, quisquam quos repellat repellendus, repudiandae sequi. Amet dolor eligendi excepturi ipsa molestiae placeat veniam!</div>
I went with a bit of a different solution. This is a bit more flexible, and I think has better browser compat.
.chrome-frame {
background: #f7f7f7 url(http://i.stack.imgur.com/jNvtF.png) top left repeat-x;
position: relative;
padding: 85px 6px 6px 6px;
border: 1px solid #c2c2c2;
}
.chrome-tl {
background: url(http://i.stack.imgur.com/TVQ3z.png) top left no-repeat;
position: absolute;
top: 0;
left: 0;
width: 326px;
height: 81px;
}
.chrome-tr {
background: url(http://i.stack.imgur.com/wWuRT.png) top right no-repeat;
position: absolute;
top: 0;
right: 0;
width: 123px;
height: 81px;
}
<div class="chrome-frame">
<div class="chrome-tl"></div>
<div class="chrome-tr"></div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. At blanditiis ducimus excepturi laudantium quam, quod repellat? A aperiam corporis dicta dolore doloremque explicabo inventore laboriosam molestiae pariatur, perferendis, reiciendis sed.
</div>
Resize it on JS Fiddle to see how it behaves.
If you want to do it in a less hacky way, you can just wrap your text in another div, and then apply negative margin to it, like this:
<div class="chrome-frame">
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem earum in necessitatibus neque veritatis. Ab aspernatur delectus dignissimos eaque eius fugiat hic, ipsa modi natus, officiis reiciendis sequi totam voluptates. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit id neque nostrum perferendis, quam quas quibusdam, quisquam quos repellat repellendus, repudiandae sequi. Amet dolor eligendi excepturi ipsa molestiae placeat veniam!
</div>
</div>
.chrome-frame {
border-width: 80px 120px 1px 324px;
border-image: url(http://i.imgur.com/m7QqzJi.png) 80 120 1 324 stretch;
border-image-outset: 0;
box-sizing: border-box;
}
.chrome-frame div {
margin-left: -300px;
}
However, the most elegant way would be to just use the image as a background image instead of a border image.

Resources