Is there any way to align this perfectly using CSS or something else?

3

I'm currently producing an HTML text that I'm trying to align, I'm doing it raw, using   .

This is an example (do not pay attention to the <font color ... that I plan to improve for CSS):

<div class="page_break"><font color="red"><b>≡ SALMO</b>&nbsp;&nbsp;&nbsp;&nbsp;Sal 110, 1-2. 3-4. 5-6</font><br /><br />
  <font color="red">El Señor recuerda siempre su alianza</font><br /><br />
  <font color="red">℣. </font>&nbsp;&nbsp;&nbsp;&nbsp;Doy gracias al Señor de todo corazón, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;en compañía de los rectos, en la asamblea. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Grandes son las obras del Señor, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dignas
  de estudio para los que las aman.
  <font color="red"> ℟.</font><br /><br />
  <font color="red">℣. </font>&nbsp;&nbsp;&nbsp;&nbsp;Esplendor y belleza son su obra, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;su justicia dura por siempre. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ha hecho maravillas memorables, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;el
  Señor es piadoso y clemente.
  <font color="red"> ℟.</font><br /><br />
  <font color="red">℣. </font>&nbsp;&nbsp;&nbsp;&nbsp;Él da alimento a sus fieles, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recordando siempre su alianza. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mostró a su pueblo la fuerza de su obrar, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dándoles
  la heredad de los gentiles.
  <font color="red"> ℟.</font>
</div>

The type of alignment that I need is this (that the first line of each stanza is aligned with the lines that follow):

It is not solved by adding one or two or three &nbsp; , it is never perfectly aligned, and if changing the size of the letter to present it in an HTML it becomes a disaster. Also, I want to give up &nbsp; for this.

Is there any technique in CSS to do this type of alignments?

    
asked by A. Cedano 11.10.2018 в 21:10
source

3 answers

6

1) Delete everything unnecessary and leave it simple , that is, wrap each paragraph in a container and remove all unnecessary spaces.

<p class="parrafo">Doy gracias al Señor de todo corazón, <br />
    en compañía de los rectos, en la asamblea. <br />
    Grandes son las obras del Señor, <br />
    dignas de estudio para los que las aman.
</p>

2) I recommend calling the 2 symbols with the pseudo elements ::before and ::after in each of the paragraphs. So:

.salmo .parrafo::before{
  content: '℣.';
}

.salmo .parrafo::after{
  content: '℟.';
}

.salmo .parrafo::before,
.salmo .parrafo::after{
  color: #ed462f; /*Con esto pintas ambos del color rojo*/
}

3) All paragraphs except the first two, we will assign a relative position and an external spacing with margin to the left. For the color we can use border or in my example a shadow:

.salmo .parrafo{
  margin-left: 40px; /*O el espacio que consideres*/
  position: relative;
  box-shadow: -7px 0 0 #49a99d;
}

4) To the first symbol we will take it out of the regular flow of html with an absolute position and place it on the left at the same negative distance that we assign margin in the paragraph:

.salmo .parrafo::before{
  content: '℣.'; /*<-- Esta línea ya la habíamos puesto arriba*/
  position: absolute;
  left: -40px;
}

And that's it! At the rate we're taking you'll have something like this:

.salmo .parrafo::before{
  content: '℣.'; /*<-- Esta línea ya la habíamos puesto arriba*/
  position: absolute;
  left: -40px;
}

.salmo .parrafo::after{
  content: '℟.';
}

.salmo .parrafo::before,
.salmo .parrafo::after{
  color: #ed462f; /*Con esto pintas ambos del color rojo*/
}

.salmo .parrafo{
  margin-left: 40px; /*O el espacio que consideres*/
  position: relative;
  box-shadow: -7px 0 0 #49a99d;
}
<div class="page_break salmo">
  <p><b>≡ SALMO</b> Sal 110, 1-2. 3-4. 5-6</p>
  <p>El Señor recuerda siempre su alianza</p>

  <p class="parrafo">Doy gracias al Señor de todo corazón, <br />
    en compañía de los rectos, en la asamblea. <br />
    Grandes son las obras del Señor, <br />
    dignas de estudio para los que las aman.
  </p>
  <p class="parrafo">
    Esplendor y belleza son su obra, <br />
    su justicia dura por siempre. <br />
    Ha hecho maravillas memorables, <br />
    el Señor es piadoso y clemente.
  </p>
  <p class="parrafo">
    Él da alimento a sus fieles, <br />
    recordando siempre su alianza. <br />
    Mostró a su pueblo la fuerza de su obrar, <br />
    dándoles la heredad de los gentiles.
  </p>
</div>

The rest will try to accommodate the styles according to what you want to achieve, for example:

.salmo p{
  font-family: sans-serif;
}

.salmo .title,
.salmo .intro
{  
  color: #ed462f;
}

.salmo .intro{
  display: inline-block;
  padding-right: 10px;
}

.salmo p:not(.intro):not(.title){
  margin: 0;
  margin-left: 40px;
  padding: 10px 5px;
  padding-left: 10px;
  position: relative;
  box-shadow: -7px 0 0 #49a99d;
  line-height: 1.2em;
}

.salmo p:not(.salmo):not(.title)::before,
.salmo p:not(.salmo):not(.title)::after{
  color: #ed462f;
}

.salmo p:not(.salmo):not(.title)::before{
  content: '℣.';
  position: absolute;
  left: -40px;
}

.salmo p:not(.salmo):not(.title)::after{
  content: '℟.';
}
<div class="page_break salmo">
  <p class="title"> <b>≡ SALMO</b> Sal 110, 1-2. 3-4. 5-6
  <p class="intro">
    El Señor recuerda siempre su alianza
  </p>

  <p class="parrafo">Doy gracias al Señor de todo corazón, <br />
    en compañía de los rectos, en la asamblea. <br />
    Grandes son las obras del Señor, <br />
    dignas de estudio para los que las aman.
  </p>
  <p class="parrafo">
    Esplendor y belleza son su obra, <br />
    su justicia dura por siempre. <br />
    Ha hecho maravillas memorables, <br />
    el Señor es piadoso y clemente.
  </p>
  <p class="parrafo">
    Él da alimento a sus fieles, <br />
    recordando siempre su alianza. <br />
    Mostró a su pueblo la fuerza de su obrar, <br />
    dándoles la heredad de los gentiles.
  </p>
</div>

In the remote case, that you can not (or do not want to) add classes to each paragraph within each psalm , you can always add a class to only the first two paragraphs and use a selector to the other paragraphs that exclude them. Example:

.salmo p:not(.salmo):not(.title){ /*Este sería el selector*/ }

Or you can even become a hipster and use only the specific CSS selectors without assigning classes to any element within the psalm, something like this:

.salmo p{
  font-family: sans-serif;
}

.salmo p:first-child,
.salmo p:nth-child(2)
{  
  color: #ed462f;
}

.salmo p:first-child b{
  display: inline-block;
  padding-right: 10px;
}

.salmo p:not(:first-child):not(:nth-child(2)){
  margin: 0;
  margin-left: 40px;
  padding: 10px 5px;
  padding-left: 10px;
  position: relative;
  box-shadow: -7px 0 0 #49a99d;
  line-height: 1.2em;
}

.salmo p:not(:first-child):not(:nth-child(2))::before,
.salmo p:not(:first-child):not(:nth-child(2))::after{
  color: #ed462f;
}

.salmo p:not(:first-child):not(:nth-child(2))::before{
  content: '℣.';
  position: absolute;
  left: -40px;
}

.salmo p:not(:first-child):not(:nth-child(2))::after{
  content: '℟.';
}
<div class="page_break salmo">
  <p> <b>≡ SALMO</b> Sal 110, 1-2. 3-4. 5-6
  <p>
    El Señor recuerda siempre su alianza
  </p>

  <p>Doy gracias al Señor de todo corazón, <br />
    en compañía de los rectos, en la asamblea. <br />
    Grandes son las obras del Señor, <br />
    dignas de estudio para los que las aman.
  </p>
  <p>
    Esplendor y belleza son su obra, <br />
    su justicia dura por siempre. <br />
    Ha hecho maravillas memorables, <br />
    el Señor es piadoso y clemente.
  </p>
  <p>
    Él da alimento a sus fieles, <br />
    recordando siempre su alianza. <br />
    Mostró a su pueblo la fuerza de su obrar, <br />
    dándoles la heredad de los gentiles.
  </p>
</div>

Or leaving, the follies on the side the simplest, is that you wrap everything in a single container type list <ul> and each paragraph is a <li> , example:

.salmo{
  --red: #ed462f;
  --green: #49a99d;
}

.salmo p,
.salmo li{
  font-family: sans-serif;
}

.salmo p:first-child,
.salmo p:nth-child(2)
{  
  color: var(--red);
}

.salmo p:first-child b{
  display: inline-block;
  padding-right: 10px;
}

.salmo ul{
  list-style: none;
  padding: 0;
}

.salmo li{
  margin: 0;
  margin-left: 40px;
  padding: 10px 5px;
  padding-left: 10px;
  position: relative;
  box-shadow: -7px 0 0 var(--green);
  line-height: 1.2em;
}

.salmo li::before,
.salmo li::after{
  color: var(--red);
}

.salmo li::before{
  content: '℣.';
  position: absolute;
  left: -40px;
}

.salmo li::after{
  content: '℟.';
}
<div class="page_break salmo">
  <p> <b>≡ SALMO</b> Sal 110, 1-2. 3-4. 5-6
  <p>
    El Señor recuerda siempre su alianza
  </p>
  
  <ul>

    <li>Doy gracias al Señor de todo corazón, <br />
      en compañía de los rectos, en la asamblea. <br />
      Grandes son las obras del Señor, <br />
      dignas de estudio para los que las aman.
    </li>
    <li>
      Esplendor y belleza son su obra, <br />
      su justicia dura por siempre. <br />
      Ha hecho maravillas memorables, <br />
      el Señor es piadoso y clemente.
    </li>
    <li>
      Él da alimento a sus fieles, <br />
      recordando siempre su alianza. <br />
      Mostró a su pueblo la fuerza de su obrar, <br />
      dándoles la heredad de los gentiles.
    </li>
  
  </ul>
  
</div>

If you have any other questions, do not forget to leave your comment.

    
answered by 12.10.2018 / 00:00
source
2

Here is an example of how you can do it using only css:

.salmo p{
           color: red;
        }
        .salmo p b{ 
            margin-right: 20px;
        }
        .salmo ul {
            list-style: none;
        }
        .salmo ul li:before{
            color: #f00;
            content: '℣';
            float:left;
            margin-left: -20px;
            font-size: 1.2em;
            font-weight: bold;
        }
        .salmo-cierre{
            color: red;
        }
<div class="page_break">
        <div class="salmo">
            <p><b>≡ SALMO</b>Sal 110, 1-2. 3-4. 5-6</p>
            <p>El Señor recuerda siempre su alianza</p>
            <ul>
                <li>
                    Doy gracias al Señor de todo corazón,
                    <br>en compañía de los rectos, en la asamblea. 
                    <br>Grandes son las obras del Señor, 
                    <br>dignas de estudio para los que las aman.<span class="salmo-cierre">℟.</span>
                </li>
            </ul>
        </div>
    </div>

The br tag should only be used inside the p tag as a line break. To separate elements you must use the margin property. I also build a base layer that will be the body of the psalm, it is represented in the css with the class ".salmo".

Each "li" you place would be a new "paragraph" I do not know what each part of the psalm is called.

Greetings!

    
answered by 11.10.2018 в 21:38
1

If you use 5 &nbsp; and you add text-align: justify; it seems to work.

.page-break {
  text-align: justify;
}
<div class="page_break"><font color="red"><b>≡ SALMO</b>&nbsp;&nbsp;&nbsp;&nbsp;Sal 110, 1-2. 3-4. 5-6</font><br /><br />
  <font color="red">El Señor recuerda siempre su alianza</font><br /><br />
  <font color="red">℣. </font>Doy gracias al Señor de todo corazón, <br/>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;en compañía de los rectos, en la asamblea. <br/>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Grandes son las obras del Señor, <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dignas de estudio para los que las aman.
  <font color="red"> ℟.</font><br /><br />
  <font color="red">℣. </font>Esplendor y belleza son su obra, <br/>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;su justicia dura por siempre. <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ha hecho maravillas memorables, <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;el Señor es piadoso y clemente.
  <font color="red"> ℟.</font><br /><br />
  <font color="red">℣. </font>Él da alimento a sus fieles, <br/>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recordando siempre su alianza. <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mostró a su pueblo la fuerza de su obrar, <br/>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dándoles la heredad de los gentiles.
  <font color="red"> ℟.</font>
</div>
    
answered by 11.10.2018 в 21:24