PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label vertical-alignment. Show all posts
Showing posts with label vertical-alignment. Show all posts

Friday, November 18, 2022

[FIXED] How to center widgets vertically when orientation is horizontal for an Android LinearLayout?

 November 18, 2022     android, android-linearlayout, listview, listviewitem, vertical-alignment     No comments   

Issue

I have several different item view types in an Android ListView, each with its own LinearLayout. I am trying to center all of their widgets vertically in addition to their being placed horizontally relative to each other. See the the very first item in the ListView in the attached pic. It looks fine except that the widgets are pushed up near the top of the ListView item.

The light blue and light green backgrounds for the TextView and ImageViews are intended to help view the effects of the xml on placement. Immediately below the image is my layout for that topmost item in the ListView. How can I make the TextView as well as the circular images (ImageView) to be centered vertically?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="5dp">

        <TextView
            android:id="@+id/ques_num"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:background="@color/LightBlue"
            android:text="0."
            android:textSize="22sp" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center_vertical"
            android:background="@color/LightGreen"
            android:adjustViewBounds="true"
            android:id="@+id/question_id_0" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center_vertical"
            android:background="@color/LightGreen"
            android:adjustViewBounds="true"
            android:id="@+id/question_id_1" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center_vertical"
            android:background="@color/LightGreen"
            android:adjustViewBounds="true"
            android:id="@+id/question_id_2" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center_vertical"
            android:background="@color/LightGreen"
            android:adjustViewBounds="true"
            android:id="@+id/question_id_3" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center_vertical"
            android:background="@color/LightGreen"
            android:adjustViewBounds="true"
            android:id="@+id/question_id_4" />


</LinearLayout>

UPDATE:

I tried simply adding to the LinearLayout:

android:gravity="center_horizontal"

and afterwards tried changing it to:

android:gravity="center_horizontal|center_vertical"

In both cases it resulted in moving the widgets into the horizontal center of the ListView item, but had no effect on the vertical positioning. See the results here in the image:

enter image description here


Solution

The entire problem was a combination of this line in the LinearLayout:

android:paddingBottom="5dp"

and the fact that, given the size of the content in the TextView and ImageView objects, the upper and lower boundaries of the ListView items were already pressing in as much as they could. There was no room for centering adjustments to take place even though it looked like there was, because of the paddingBottom attribute.



Answered By - Alyoshak
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to vertically align image in a td cell, without vertically-align

 November 18, 2022     alignment, css, html-table, vertical-alignment     No comments   

Issue

Following code:

<div id="test">
  <table>
    <tbody>
      <tr>
        <td>
          <img src="img1.jpg" />
          <p>Bla bla bla</p>
          <p><a href="#"><img src="img2.jpg"></a></p>
        </td>
      </tr>
    </tbody>
  </table>
</div>

and CSS:

#test td {
    width: 450px;
    height: 220px;
    vertical-align: top;
    border-bottom: 1px solid #000;
    border-right: 50px solid #fff;
}

#test td p {
    margin: 0 0 10px 0;
    width: 290px;
}

#test img {
    padding: 20px 5px 5px 5px;
    float:left;
}

How can I align the second image with the link to the bottom of the cell? I was googling a lot but none of the solutions work for me...


Solution

Give the container (td) position: relative and the image, or more specifically the <p> which contains the image, position: absolute; bottom: 0;. See it in action here.



Answered By - Supr
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why my div is not aligning to middle vertically?

 November 18, 2022     css, html, vertical-alignment     No comments   

Issue

I don't know how to ask this...

I made a layout using some css, I have a container div (.truck_info) with 2 elements inside, the first one is on the top, and the second one (.truck_cont) has a height:100% and vertical-align:middle (it covers the whole container), I don't know why the elements inside this second element are not aligned to middle, this is my code:

jsfiddle: https://jsfiddle.net/5qtbkemy/

HTML code:

<div class="truck_slot" >
<table class="table_truck"><tbody><tr>
<td class="truck_colo" style="background-color:#F11; ">
  <div class="truck_time">Left pane</div>
</td>
<td class="truck_info">
  <div class="truck_stop" style="background-color:#F11; ">Top line</div>
  <div class="truck_cont"> 
    <div class="truck_name" style="font-size:28px; ">Middle</div>
    <div class="truck_para" style="font-size:11px;">Why this text isn't</div>
    <div>middle align?</div>
  </div>
</td>
</tr></tbody></table>
</div>

CSS Code:

.truck_slot{
    float:left;
    width:170px;
    cursor:pointer;
    margin:5px 8px;
}
.table_truck{
    width:100%;
    height: 155px;
    padding:0px;
    border:1px #CCCCCC solid;
    border-radius:10px;
    padding:2px;
    border-collapse: separate;
    border-spacing: 0px;
    box-shadow: 2px 2px 3px #999;
}
.table_truck td{
    font-family:Arial, Helvetica, sans-serif;
    color: #666;
}
.table_truck .truck_colo{
    height:100%;
    width: 55px;
    text-align: center;
    vertical-align: top;
    border-radius: 6px 0 0 6px;
    color: #FFF;
}
.table_truck .truck_time{
    font-size:13px;
    font-weight:bold;
    font-family: "Calibri", "Century Gothic", Century, Arial, "Arial Black";
}
.table_truck .truck_info{
    height:100%;
    vertical-align: top;
    color:#666;
}
.table_truck .truck_info .truck_info_div{
    height:90px;
    overflow:hidden;
}
.table_truck .truck_stop{
    border-radius: 0 6px 0 0;
    padding: 0 5px;
    color: #FFF;
    line-height:20px;
    font-size:13px;
    font-weight:bold;
}
.table_truck .truck_cont{
    height: 100%;
    vertical-align:middle;
}
.table_truck .truck_name{
    font-family:Arial, Helvetica, sans-serif;
    font-weight:bold;
    padding: 0 14px 0 3px;
    /*margin-bottom:10px*/
}
.table_truck .truck_para{
    font-family:Arial, Helvetica, sans-serif;
    font-weight:bold;
    padding-left:3px;
}

I hope you can help me to understand what is wrong.

Thank you!


Solution

The correct original answer was deleted by the author, what I used was a flex-box solution, I added 3 lines:

.table_truck .truck_cont{
    height: 85%;
    vertical-align:middle;
    display: flex; /* To use flexbox I need to set a flex display */
    flex-direction: column; /* to make it vertical I change the direction to column */
    justify-content: center; /* finally, I must set the orientation to center */
}

This is the edited jsfiddle: https://jsfiddle.net/5qtbkemy/5/

I found this link useful to learn quickly about flex-box: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

I hope it helps!



Answered By - stramin
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I vertically align this navigation bar?

 November 18, 2022     css, html, navbar, vertical-alignment     No comments   

Issue

I have a navigation bar, but i don't know how to vertically align some classes. I use bootstrap. The navigation bar is fixed position. The navbar is divided into 3 row. The search row is OK, but I can't vertically align the another rows.

Here is the HTML:

                <div class="col-sm-10" >
                    <p>Reményik Tudástár</p>
                </div>
            </div>
        </div>
    </div>

        <div class="col-sm-4 navbar-search vertical-align">
            <div class="container-fluid">
                <div class="row vertical-align">
                    <div class="col-sm-1"></div>
                        <div class="col-sm-9" style="padding: 0;">
                            <input type="text" name="search" class="navbar-search-input" placeholder="Keresés">
                        </div>

                        <div class="col-sm-1" style="">
                            <button class="navbar-search-button"><i class="fa fa-search"></i></button>
                        </div>
                    <div class="col-sm-1"></div>
                </div>
            </div>
        </div>

    <div class="col-sm-4 navbar-login" style="">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-10">
                    <p style="float: right;">Bejelentkezés</p>
                </div>

                <div class="col-sm-2">
                    <span class="fa fa-sign-in fa-2x"></span>
                </div>
            </div>
        </div>
    </div>
</div>

and here is the CSS:

.navigation-bar {
    background-image: url("../img/nav_background.png");
    padding: 15px;
    box-shadow: 0px 2px 5px #999999;
}

.navbar-search-input {
    width: 100%;
    border: 0;
    border-radius: 3px 0 0 3px;
    height: 35px;
    padding: 10px;
}

.navbar-search-button {
    background-color: #203138;
    color: #fff;
    margin-right: 100%;
    border: 0;
    border-radius: 0 3px 3px 0;
    height: 35px;
    padding-left: 12px;
    padding-right: 12px;
}

So, how can I vertically align the logo and the cim class?


Solution

Try this:-

display: inline-block;
    *display: inline;
    vertical-align: middle;


Answered By - Razia sultana
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I vertically center rotated text using Flexbox layout?

 November 18, 2022     css, css-transforms, flexbox, html, vertical-alignment     No comments   

Issue

How can I vertically center rotated text using flexbox layout? I want something that looks like this:

enter image description here

Here's what I have so far:

html, body { height: 100%; }
body { background-color: #efefef; }

body > div {
  align-content: center;
  background-color: white;
  border: 1px solid black;
  display: flex;
  height: 100%;
  width: 25px;
}

body > div > div {
  flex: 1;
  transform: rotate(-90deg);
}
<div>
  <div>
    Where did I go?
  </div>
</div>


Solution

Add white-space: nowrap and center horizontally and vertically using:

align-items: center;
justify-content: center;

(and you don't need the flex: 1!)

Also removed the browser margin and added in box-sizing: border-box to add the finishing touches.

See demo below:

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background-color: #efefef;
}
body > div {
  background-color: white;
  border: 1px solid black;
  display: flex;
  height: 100%;
  width: 25px;
  align-items: center;
  white-space: nowrap;
  justify-content: center;
}
body > div > div {
  transform: rotate(-90deg);
}
<div>
  <div>
    Where did I go?
  </div>
</div>



Answered By - kukkuz
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why is veritcal-align:middle not aligning things in my table row?

 November 18, 2022     css, html, vertical-alignment     No comments   

Issue

I'm having trouble vertically aligning content in a table row. I have applied this style

vertical-align: middle;

to this table row

<table id="subscriptions-table">
    <tbody><tr>
        <th>Subscription</th>
        <th>Download</th>
    </tr>
    <tr class="even subscription-row header">
        <td class="ig-header-title ellipsis">
        <img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons/matte-grey-square-icons-alphanumeric/118474-matte-grey-square-icon-alphanumeric-letter-s.png" height="25" alt="S icon">
        <a class="name ellipsis" href="/scenarios/18">Simulation #1</a>
    </td>  
    <td align="center"><a href="/scenarios/18/download"><img src="/assets/zip_icon-c2a0694959db12a0939d264d4283478c1f59a4b118df839d7020aca929a1df61.png" alt="Zip icon"></a></td>
    </tr> 
</tbody></table>

but the text is aligning to the bottom even though the image seems to be aligning in the middle -- https://jsfiddle.net/ny39f2qx/ . How do I make everythign vertically align in the middle?


Solution

Not enough vertical-align: middle. The image needs it too.

table {
  border-collapse: collapse;
}
table tbody tr:hover {
  background-color: #F6F8F9
}
.subscription-row img, .subscription-row .name {
  vertical-align: middle;
}
.subscription-row .name {
  color: #3d454c;
  font-size: 15px;
  font-size: .9375rem;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
  font-weight: bold;
}
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ig-header .ig-header-title {
  line-height: 20px;
}
<table id="subscriptions-table">
  <tbody>
    <tr>
      <th>Subscription</th>
      <th>Download</th>
    </tr>
    <tr class="even subscription-row header">
      <td class="ig-header-title ellipsis">
        <img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons/matte-grey-square-icons-alphanumeric/118474-matte-grey-square-icon-alphanumeric-letter-s.png" height="25" alt="S icon">
        <a class="name ellipsis" href="/scenarios/18">Simulation #1</a>
      </td>
      <td align="center">
        <a href="/scenarios/18/download">
          <img src="/assets/zip_icon-c2a0694959db12a0939d264d4283478c1f59a4b118df839d7020aca929a1df61.png" alt="Zip icon">
        </a>
      </td>
    </tr>
  </tbody>
</table>



Answered By - Oriol
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I align these pictures vertically?

 November 18, 2022     alignment, css, html, vertical-alignment     No comments   

Issue

I'm creating a footer, and I would like to align the images of social networks vertically and automatically. As it has an increase in the size of the source of the contacts, the images are up. And I do not know how to proceed.

My code on jsfiddle: Demo Code

HTML

<!DOCTYPE html>
<title>Teste</title>

<body>
  <footer class="footer">
    <div class="content">
      <div class="footer-right">
        <p><b>(43)3333-3333</b></p>
        <p>contact@contact.com</p>
      </div>
      <div class="footer-left">
        <ul>
          <li>
            <a href="#"><img src="http://imgur.com/RVvPQt9.png" alt="Twitter"></a>
          </li>
          <li>
            <a href="#"><img src="http://imgur.com/LsqUBIh.png" alt="Facebook"></a>
          </li>
          <li>
            <a href="#"><img src="http://imgur.com/8PhKmDe.png" alt="Instagram"></a>
          </li>
          <li>
            <a href="#"><img src="http://imgur.com/hDSPEMm.png" alt="Linkedin"></a>
          </li>
        </ul>
      </div>
    </div>
  </footer>
</body>

CSS

* {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Source Sans Pro', sans-serif;
}

.content {
  margin: 0 auto;
  max-width: 1100px;
  padding: 0 4% 0 4%;
}

li {
  list-style: none;
}

.footer {
  background-color: rgba(158, 158, 158, 0.42);
  box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
  box-sizing: border-box;
  width: 100%;
  text-align: left;
  padding: 15px 0;
  overflow: hidden;
}

.footer .footer-right {
  float: right;
}

.footer .footer-right {
  font-size: 18px;
  text-align: right;
}

.footer .content .footer-left {
  float: left;
}

.footer .content .footer-left > ul > li {
  display: inline-block;
}

.footer > .content > .footer-left > ul > li > a {
  display: block;
}

.footer > .content > .footer-left > ul > li > a > img {
  height: 30px;
  width: 30px;
}


/*MEDIA QUERIES*/

@media screen and (max-width: 400px) {
  .footer > .content > .footer-right,
  .footer-left {
    float: none !important;
    text-align: center;
  }
  .footer > .content > .footer-right {
    margin-bottom: 10px;
  }
}

Solution

Use table display css - the table-cell causes the floating to work and the table-header-group and table-footer-group cause the reordering.

* {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Source Sans Pro', sans-serif;
}

.content {
    margin: 0 auto;
    max-width: 1100px;
    padding: 0 4% 0 4%;
    min-width:92%;
    display:table;
}

li {
    list-style: none;
}

.footer {
    background-color: rgba(158, 158, 158, 0.42);
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    width: 100%;
    text-align: left;
    padding: 15px 0;
    overflow: hidden;
}

.footer .footer-right {
    display:table-cell;
    width:50%;
}

.footer .footer-right {
    font-size: 18px;
    text-align: right;
    width:50%;
}

.footer .content .footer-left {
    display:table-cell;
    vertical-align:middle;
}

.footer .content .footer-left > ul > li {
    display: inline-block;
}

.footer > .content > .footer-left > ul > li > a {
    display: block;
}

.footer > .content > .footer-left > ul > li > a > img {
    height: 30px;
    width: 30px;
}


/*MEDIA QUERIES*/

@media screen and (max-width: 400px) {
    .footer > .content > .footer-left {
        display:table-footer-group;
        width:100%;
        float:none;
        text-align: center;
    }
    .footer > .content > .footer-right {
        display:table-header-group;
        margin-bottom: 10px;
        float:none;
        width:100%;
    }
    .footer > .content > .footer-right p {
        width:100%;
        display:block;
        text-align: center;
    }
}
<!DOCTYPE html>
    <title>Teste</title>
<body>
    <footer class="footer">
        <div class="content">
            <div class="footer-left">
                <ul>
                    <li>
                        <a href="#"><img src="http://imgur.com/RVvPQt9.png"
                                alt="Twitter"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/LsqUBIh.png"
                                alt="Facebook"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/8PhKmDe.png"
                                alt="Instagram"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/hDSPEMm.png"
                                alt="Linkedin"></a>
                    </li>
                </ul>
            </div>
            <div class="footer-right">
                <p><b>(43)3333-3333</b></p>
                <p>contact@contact.coma</p>
                <p><b>(43)3333-3333</b></p>
                <p>contact@contact.coma</p>
            </div>
        </div>
    </footer>
</body>



Answered By - WEBjuju
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to vertically align div inside Bootstrap 3 column

 November 18, 2022     css, html, twitter-bootstrap, twitter-bootstrap-3, vertical-alignment     No comments   

Issue

I have a page with Twitter Bootstrap container-fluid class div, one row and one col-md-6 inside that row. Row is set to 50% height of the container, and a column has 100% height of the row. I have a div inside that column, that I want to be in the center of the column.

<body>
    <div class="container-fluid cont">
        <div class="row logoRow">
            <div class="col-md-6 logoCol">
                <div class="logoCont center-block"></div>
            </div>
        </div>
    </div>
</body>

And the style is:

html, body {
    height: 100%;
}

.cont {
    height: 100%;
    background: blue;
}
.logoRow {
    height: 50%;
    background: green;
}
.logoCol {
    height: 100%;
    background: yellow;
}

.logoCont {
    height: 50%;
    width: 50%;
    background: red;
}

Here is my fiddle of this: http://jsfiddle.net/p9ou30g7/2/

Adding a center-block class to inner div aligned it to horizontal center, but I also need to align it vertically to the center of the column. So that red div is in the center of the yellow one. How can this be done?


Solution

This is one way to do it, and is more crossbrowser supported than flexbox.

http://jsfiddle.net/p9ou30g7/3/

.logoCont {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    height: 50%;
    width: 50%;
    background: red;
}

There are other ways that you can check out here: https://css-tricks.com/centering-css-complete-guide/



Answered By - Muhammad Umer
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I vertically align a bootstrap glyph inside an <input> larger than default

 November 18, 2022     css, html, twitter-bootstrap, vertical-alignment     No comments   

Issue

I have to make an <input> that's larger than the usual. The height must be 55px. I am having trouble vertically aligning the glyph image inside the orange square. It looks like this: enter image description here

It should look like this: enter image description here

I have tried using margin-top on my <i> element but it moves the rectangle down too, I need to move just the glyph. It looks like this: enter image description here

Please let me know if you have any ideas on how I could vertically center the glyph inside the orange box. I have setup a jsfiddle at https://jsfiddle.net/vteL375o/1/

HTML:

<div class="container">

  <div class="form-group has-feedback" style="margin-top:20px;">
    <input type="text" id="search-query" class="form-control not-rounded search-input">

    <i class="glyphicon glyphicon-search form-control-feedback glyph-class" style=""></i>
  </div>

</div>

CSS:

.not-rounded {
  border-radius: 0;
}

.search-input {
  font-size: 20px;
  margin-bottom: 50px;
  height: 55px;
}

.glyph-class {
  height: 55px;
  width: 55px;
  color:white;
  background-color: orange;
  font-size: 20px;
}

Solution

You can use Flexbox for this, or inline-flex in this case.

.not-rounded {
  border-radius: 0;
}
input.search-input {
  font-size: 20px;
  margin-bottom: 50px;
  height: 55px;
}

.glyphicon.glyphicon-search.form-control-feedback.glyph-class {
  height: 55px;
  width: 55px;
  color: white;
  background-color: orange;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
  <div class="form-group has-feedback" style="margin-top:20px;">
    <input type="text" id="search-query" class="form-control not-rounded search-input">
    <i class="glyphicon glyphicon-search form-control-feedback glyph-class" style=""></i>
  </div>
</div>



Answered By - Nenad Vracar
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to vertical align text to the center in the bottom left footer

 November 18, 2022     css, html, vertical-alignment     No comments   

Issue

It is a single row made of 3 columns. I want to make the "h5 class:footer-small" vertical aligned to the div "class: col-1"

image of how it currently looks

I found out that using display: inline-block, it made the text vertical aligned in the center. But I did not understand how was it possible? Can someone explain why using display:inline-block worked?

HTML

<footer>
      <div class="row-4">
        <div class="col-1">
          <p class="col-1">
            <h5 class="footer-small">Seattle<br>Grace<br>Hospital</h5>
          </p>
        </div>
        <div class="col-5">
          <h5 class="footer-desc">He is a Bowdoin College graduate and attended Columbia University College <br>of Physicians and Surgeons</h5>
        </div>
        <div class="col-6">
          <h2 class="footer-frase">McDreamy</h2>
            <em class="footer-frase">"It's a beautiful night to save lives"</em>
        </div>
      </div>
    </footer>

Solution

you can simply do it using css3 flexbox concept

add the following styles to your col-1

  • display:flex;

  • align-items:center;

  • justify-content:center;

Note: you can't declare a header tag (<h1>,<h2>,etc..) inside a paragraph tag(<p>) ,so replace it by <span> tag or any other tags

div.row-4{
  display:flex;
  color:#fff;
  }

div.row-4 div{
  padding:5px;
  }
.col-6{
  background:#73819b;
  flex:2;
  }
.col-5{
  background:#438cab;
  flex:2;
  }
.col-1{
  background:#438cab;
  display:flex;
  align-items:center;
  justify-content:center;
  }
<footer>
      <div class="row-4">
        <div class="col-1">
          <span class="col-1">
            <h5 class="footer-small">Seattle<br>Grace<br>Hospital</h5>
          </span>
        </div>
        <div class="col-5">
          <h5 class="footer-desc">He is a Bowdoin College graduate and attended Columbia University College <br>of Physicians and Surgeons</h5>
        </div>
        <div class="col-6">
          <h2 class="footer-frase">McDreamy</h2>
            <em class="footer-frase">"It's a beautiful night to save lives"</em>
        </div>
      </div>
    </footer>



Answered By - ADH - THE TECHIE GUY
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to vertically align text in the middle

 November 18, 2022     alignment, css, text-alignment, vertical-alignment, wordpress     No comments   

Issue

In my wordpress posts I have a div that is half image half text. On the side where the text is I want to vertically align the text in the middle. I have tried vertical-align:middle but it did not work. Does anyone have any solutions? Thanks in advance.

css

.half-width-img{
    width:50%;
    height:auto;
    float:left;
}
.half-width-text{
    width:50%;
    height:auto;
    float:left;
    box-sizing: border-box;
padding:0 100px 0 100px;
    text-align: justify;
    display: table-cell;
    vertical-align: middle;
}
.half-image-half-text {
    display: inline-block;
}
<div class="half-image-half-text">
    <img class="half-width-img" src="IMAGE URL" />
    <p class="half-width-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
</div>


Solution

do not use float, but display :)

test snippet in full page mode

  • display:inline-block; and html comments to erase the white-space :

.half-width-img {
  width: 50%;
  display: inline-block;
  vertical-align: middle;
}
.half-width-text {
  width: 50%;
  height: auto;
  display: inline-block;
  box-sizing: border-box;
  padding: 0 100px 0 100px;
  text-align: justify;
  vertical-align: middle;
}
.half-image-half-text {
}
<div class="half-image-half-text">
  <img class="half-width-img" src="http://dummyimage.com/100x100" /><!--
  --><p class="half-width-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
    quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
    Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
    Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum.
    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla
    mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
</div>

  • display:table; and 2 containers for each content so content can be vertical-align to middle. the tallest will set wich one will align to center

.half-width-img ,
.half-width-text {
  display: table-cell;
  width:50%;
  box-sizing: border-box;
  vertical-align: middle;
  }
.half-width-text {
  padding: 0 100px 0 100px;
  text-align: justify;
}
.half-width-img img{
  width:100%;
  }
.half-image-half-text {
  display:table;
  width:100%;
  table-layout:fixed;
}
<div class="half-image-half-text">
  <div  class="half-width-img"><img src="http://dummyimage.com/100x100" /></div>
  <p class="half-width-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
    quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
    Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
    Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum.
    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla
    mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
</div>

  • or display:flex; flex:1; will spray both evenly, margin:auto will manage visually the vertical-align

.half-width-img {
  width: 50%;
  flex: 1;
  margin: auto;
}
.half-width-text {
  flex: 1;
  margin: auto;
  display: inline-block;
  box-sizing: border-box;
  padding: 0 100px 0 100px;
  text-align: justify;
}
.half-image-half-text {display:flex;}
<div class="half-image-half-text">
  <img class="half-width-img" src="http://dummyimage.com/100x100" />
  <p class="half-width-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
    quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
    Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
    Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum.
    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla
    mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
</div>



Answered By - G-Cyrillus
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I vertically align all the content including borders in the columns?

 November 18, 2022     css, css-tables, grid, html, vertical-alignment     No comments   

Issue

Please see codepen for reference: http://codepen.io/rezasan/pen/apvMOR

I'm trying to make all the contents in the columns (Date, Title and Button even the separator to be vertically aligned. Tried display table but doesn't work. Require some assistance from the experts here.

HTML:

    <ul class="ir_home_news">                 
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
        </li>
    </ul>

CSS:

    ul,li{
      margin:0;
      padding:0
    }

    li{
      list-style-type:none;
    }
    .ir_home_news li{
      border-top:1px solid #ebebeb;
      padding: 10px;
    }

    .ir_home_news li:nth-child(even){
      background-color: #f8f8f8;
    }

    .ir_home_news li::after {
        content: "";
        clear: both;
        display: table;
    }

    .ir_home_news li div{
      display: table-cell;
      vertical-align: middle;
      padding: 0px 15px;
      border-right: 1px solid red;
    }

    .ir_home_news li div:last-child{
      border-right: none;
    }

    .ir_home_newsDate {
      float: left;
      width: 18%;
      margin-bottom: 10px;
      font-size: 18px;
      color:#003087;
    }

    .ir_home_newsTitle{
      float: left;
      width: 65%;
      font-size: 17px;
      color:#003087;
    }

    .ir_home_button{
      float: left;
      width: 10%;
    }
    .ir_home_button button{

      background-color: #003087;
      color: #fff;
      padding: 15px 25px;
      border-radius: 0;
      font-size: 13px;
    }

 ul,
    li {
        margin: 0;
        padding: 0
    }
    
    li {
        list-style-type: none;
    }
    
    .ir_home_news li {
        border-top: 1px solid #ebebeb;
        padding: 10px;
    }
    
    .ir_home_news li:nth-child(even) {
        background-color: #f8f8f8;
    }
    
    .ir_home_news li::after {
        content: "";
        clear: both;
        display: table;
    }
    
    .ir_home_news li div {
        display: table-cell;
        vertical-align: middle;
        padding: 0px 15px;
        border-right: 1px solid red;
    }
    
    .ir_home_news li div:last-child {
        border-right: none;
    }
    
    .ir_home_newsDate {
        float: left;
        width: 18%;
        margin-bottom: 10px;
        font-size: 18px;
        color: #003087;
    }
    
    .ir_home_newsTitle {
        float: left;
        width: 65%;
        font-size: 17px;
        color: #003087;
    }
    
    .ir_home_button {
        float: left;
        width: 10%;
    }
    
    .ir_home_button button {
        background-color: #003087;
        color: #fff;
        padding: 15px 25px;
        border-radius: 0;
        font-size: 13px;
    }
<ul class="ir_home_news">                 
            <li class="si_fixed">
                <div class="ir_home_newsDate">18 November 2016</div>
                <div class="ir_home_newsTitle">Disclosure Of Interest</div>
                <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
            </li>
            <li class="si_fixed">
                <div class="ir_home_newsDate">18 November 2016</div>
                <div class="ir_home_newsTitle">Disclosure Of Interest</div>
                <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
            </li>
            <li class="si_fixed">
                <div class="ir_home_newsDate">18 November 2016</div>
                <div class="ir_home_newsTitle">Disclosure Of Interest</div>
                <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
            </li>
        </ul>


Solution

do not use floar: left inside your li, it will cause your vertical-align no worked,

ul,
    li {
        margin: 0;
        padding: 0
    }
    
    li {
        list-style-type: none;
    }
    
    .ir_home_news li {
        border-top: 1px solid #ebebeb;
        padding: 10px;
    }
    
    .ir_home_news li:nth-child(even) {
        background-color: #f8f8f8;
    }
    
    .ir_home_news li::after {
        content: "";
        clear: both;
        display: table;
    }
    
    .ir_home_news li div {
        display: table-cell;
        vertical-align: middle;
        padding: 0px 15px;
        border-right: 1px solid red;
    }
    
    .ir_home_news li div:last-child {
        border-right: none;
    }
    
    .ir_home_newsDate {
        width: 18%;
        margin-bottom: 10px;
        font-size: 18px;
        color: #003087;
    }
    
    .ir_home_newsTitle {
        width: 65%;
        font-size: 17px;
        color: #003087;
    }
    
    .ir_home_button {
        width: 10%;
    }
    
    .ir_home_button button {
        background-color: #003087;
        color: #fff;
        padding: 15px 25px;
        border-radius: 0;
        font-size: 13px;
    }
<ul class="ir_home_news">
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button">
                <a href="">
                    <button>VIEW DETAILS</button>
                </a>
            </div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button">
                <a href="">
                    <button>VIEW DETAILS</button>
                </a>
            </div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button">
                <a href="">
                    <button>VIEW DETAILS</button>
                </a>
            </div>
        </li>
    </ul>

I just remove all float: left inside your li

.ir_home_newsDate {
    width: 18%;
    margin-bottom: 10px;
    font-size: 18px;
    color: #003087;
}

.ir_home_newsTitle {
    width: 65%;
    font-size: 17px;
    color: #003087;
}

.ir_home_button {
    width: 10%;
}


Answered By - Horken
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I mix vertical and horizontal alignment on a variable height div?

 November 18, 2022     alignment, css, vertical-alignment     No comments   

Issue

I want to align three blocks: one to the left bottom, one in the middle top, and one in the right bottom.

The width is fixed, but one or two of the blocks may be absent.

I couldn't find a way to use position:absolute because the container must have the height of the higher block.

My solution so far is using three inline-block whose widths add up to the container width, and mixed vertical-alignment. But when i hide the middle block it breaks.

I set a fiddle for it here that shows my desired result, except when I hide.

Of course I can add a script to set the margins when I hide the block, but I'm looking for a CSS only solution. Also I would rather not use tables or display:table-cell, for their side effects.


Solution

You may use display:flex; flex:1 and margin:auto will keep away from the direction it is applied, on 2 opposite direction it will be centered :

  • when middle is hidden, left and right comes 50% of width. width of div is set via flex:1:

$("input").click(() => {
  $("#middletop").toggle();
})
div {
  border: 1px solid green;
  margin: 0;
  flex: 1;
}
#container {
  min-height: 50vh;/* demo purpose */
  display: flex;
}
#leftbottom {
  margin-top: auto;
}
#middletop {
  margin: auto 0;
  text-align: middle;
}
#rightbottom {
  width: 200px;
  margin-bottom: auto;
  text-align: right;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
  <div id="leftbottom">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
  </div>
  <div id="middletop">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididun.
  </div>
  <div id="rightbottom">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  </div>
</div>
<input type="button" value="Hide middle" />

https://jsfiddle.net/9b9a7wqv/8/

  • when middle is hidden, it leaves a gap. Here width of div is set via width.

$("input").click(() => {
  $("#middletop").toggle();
})
div {
  border: 1px solid green;
  margin: 0;
  }
#container div {
  width:33%;
}

#container {
  min-height: 50vh;
  display: flex;
}

#leftbottom {
  margin-top: auto;
  margin-right:auto;
  ;
}

#middletop {
  margin: auto 0;
  text-align: middle;
}

#rightbottom {
  margin-bottom: auto;
  margin-left:auto;
  text-align: right;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
  <div id="leftbottom">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
  </div>
  <div id="middletop">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididun.
  </div>
  <div id="rightbottom">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  </div>
</div>
<input type="button" value="Hide middle" />

https://jsfiddle.net/9b9a7wqv/10/



Answered By - G-Cyrillus
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does unchecking the vertical-align property on this image change the list instead of the image?

 November 18, 2022     css, html, vertical-alignment     No comments   

Issue

Why does unchecking the vertical-align property on this image change the list instead of the image?

Checked:

checked

Unchecked:

unchecked


Solution

Inline elements share an invisible guide called a linebox. The linebox guides the vertical positioning of the elements inside of it, relative to each other. Because it's encapsulating a relationship between these inline elements inside, the box itself will be also affected by those elements.

When the vertical-align of the image is set to "middle", the linebox is shifted to the center of the parent container. That's because the image element is larger than the linebox, therefore the linebox is the one that moves when the property changes (If the image was smaller than the linebox, the image would have moved and not the linebox).

Removing the vertical align from the image causes it to default back to "baseline", and when the baselines of the linebox and image are realigned, the linebox now sits at the bottom of the parent container which shifts the rest of the content it contains down there too.

Here's a really good read on the whole thing (Much more useful than the MDN docs)



Answered By - relic
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What does top: 50%; actually do on relatively positioned elements?

 November 18, 2022     centering, css, html, position, vertical-alignment     No comments   

Issue

I've been using relatively positioned elements to center things vertically for a while. I never understood, though, why position: relative; top: 50%; doesn't vertically center the element, or at least center the top edge of the element in it's container div.

position: relative according to MDN:

lays out all elements as though the element were not positioned, and then adjusts the element's position, without changing layout

The top keyword:

specifies the amount the element is moved below its normal position.

And a % value on the top keyword:

Is a percentage of the containing block's height

So a relatively positioned element with a value of top: 50% should be moved 50% of the containing blocks height downward, right? Doesn't this mean that the top edge of that element is exactly in the middle of the containing element?

Consider this snippet:

.container {
  overflow: hidden;
  width: 90%;
  height: 90%;
  margin: 0 auto;
  background-color: #eee;
}
.child {
  width: 40%;
  height: 40%;
  margin: 0 auto;
  background-color: #444;
  border-top: 5px solid #f00;
}
.top-50-percent {
  position: relative;
  top: 50%;
}

.contract-and-expand {
  animation-name: contract-and-expand;
  animation-duration: 5s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}
@keyframes contract-and-expand {
  50% {
    height: 0%;
  }
}
<html>
  <head>
    <style>
      /* Just initial/basic CSS rules here to make this look better */
      
      @import url("https://necolas.github.io/normalize.css/latest/normalize.css");

      * {
        box-sizing: border-box;
        margin: 0;
      }
      html, body {
        height: 100%;
      }
      body {
        color: #aaa;
      }
      .center-vertically {
        position: relative;
        top: 50%;
        transform: translateY( -50% );
      }
      p {
        position: absolute; /* Remove paragraphs from flow so they don't interfere */
      }
    </style>
  </head>
  <body>
    <div class="container center-vertically contract-and-expand">
      <p>Container Wrapper</p> <!-- Paragraphs are removed from the flow -->
      
      <div class="child top-50-percent">
      </div>
      
    </div>
  </body>
</html>

From the snippet it looks like the top edge is centered. Is this always correct? there's this similar fiddle: https://jsfiddle.net/9kyjt8ze/5/ when the height of the viewport is pulled up the top border of the child element no longer looks centered.


Solution

I measured this with Inkscape and 2 ( yellow ) vertical blocks the same exact size. It's an optical illusion. The top edge never actually gets off center in that fiddle. Also all of my assumptions appear correct: top:50% on relatively positioned elements moves the top border of that element down 50% of the container's height. The reason this doesn't perfectly vertically center the element is the top edge is the pivot point when using top: 50% on relatively positioned elements.

enter image description here



Answered By - sol acyon
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to scale height of views and postion of the views relative to the screen size using AutoLayout

 November 18, 2022     aspect-ratio, autolayout, height, ios, vertical-alignment     No comments   

Issue

Using Autolayout what is the best way to keep a view's relative position and scale to each screen size? For example there are drastic differences between the 4s and iPad Pro. What type of constraints and thought processes should I be using?

The views being scaled may each have varying height and take up a different proportions of the screen. I know there are many methods to tackle this but what are the best ways.

Can the answer attach pictures so that I might clearly understand the process?

Thank u very much,


Solution

This is a pretty in depth question but to scale a view to the size of the parent and on down you need to use

Equal Width Constraints

Equal Height Constraints

Aspect Ratio Constraints

I use these very often. Here is a quick example

Suppose we want to divide the screen into 3 views. All with equal widths to the main controller view and we want the top to take up maybe 40% the 2nd view to take up 30% and the bottom to take up 20%. We can use equal heights constraints to the superview and edit and adjust the multiplier 0.2=20%.

To set a equal height constraint drag from the view to the parent view in storyboard and let go(you can also do this in the view hierarchy to the left Ex.Picture included).

EqualHeights

You will see this menu. EqualWidths

Choose Equal heights and Repeated for equal widths. The width is fine in this example as I want it to be the width of the main view but we need to alter the multiplier on the height or each view will be the height of the main view.

Find the constraint in the size inspector and locate the constraint that says equal heights to superview(image below). Double click or click edit and bring up the menu in the image above. In this case I am setting the multiplier to 0.3 which is 30% of the parent. Now proceed to do this for all the views setting the percentage you desire. EqualToSuper

OTHER Examples of Control Dragging to Parent Below: OtherExamples

I pinned all my views together.Meaning the top and bottom constraints are 0 between the views. I hope understanding these types of constraints and this is not an issue.

Example Picture of the pin menu. You can change these to 0 or whatever and quickly add Top,Bottom,Leading and Trailing for Any View PinMenu

You can also use center horizontally and vertically and you can use a multiplier to keep relative position to parent view as well.

Now as to adding subviews to these views and having them scale proportionately. The process works the same way. See my final 3 big views and I am adding a smaller view to the top view I had just added that is taking up the majority of our screen. I want this new view to be like an avatar in a design.

I put it inside the top view and I am control dragging inside the small view without leaving it to get an option to add aspect ratio(notice I set the width and height equal in the size inspector before I did this step 90x90).

AspectRatio

Let go you you will see this menu. This constraint means the view will always be square. It only needs to know its width or height and will solve for the other. Note:make sure the view is the ratio you want before control dragging in storyboard. See next image.

AspectAdd

Now I add a top constraint of say 10 and a left of 15 to the view holding this avatar small view using the pin menu. Autolayout is still mad but all I have to do is add a width or a height since the aspect ratio constraint will solve the one we do not provide. I control drag from the small view to it's parent(anywhere outside the small view). I choose equal heights. I locate that in the size inspector to the right and change the multiplier from 1 to maybe 0.4. Now Autolayout is happy again as the small view knows how wide and tall it should be since we gave it a equal heights constraint and it knows that is supposed to stay square it solves its width.

Side Note: If I don't want to use fixed top, bottom,trailing,leading you can adjust multipliers for align vertically and horizontally to work the same as equal widths and keep relative position.

I update the views and I can continue adding views. Here is what the result would be in Preview. Final



Answered By - agibson007
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I make the text of my button been perfectly aligned vertically?

 November 18, 2022     css, html, vertical-alignment     No comments   

Issue

Good day,

I have two buttons with an up and down arrow, as shown in my picture below.

enter image description here

The corresponding html code is the following :

[...]

<tr>
  <td class="tablerows" height="40">lab01 - Temp&#233;rat. pi&#232;ce [T1]</td>
  <td class="tablerows"><input id="lab01" type="text" name="country" class="resizedTextbox" value="20" readonly>
    <a href="#" class="myButton" onclick="TemperatureControl('lab01','decrease')"><i class="fa fa-chevron-down"></i></a>
    <a href="#" class="myButton" onclick="TemperatureControl('lab01','increase')"><i class="fa fa-chevron-up"></i></a>
</td>
</tr>

[...]

Edit, thanks to your help. However, I am still not able to align all my elements, as I would like

The linked CSS is the following :

td{
  vertical-align:middle;
}
.myButton {
    -moz-box-shadow:inset 0px 1px 0px 0px #54a3f7;
    -webkit-box-shadow:inset 0px 1px 0px 0px #54a3f7;
    box-shadow:inset 0px 1px 0px 0px #54a3f7;
    background-color:#3e12cc;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
    border-radius:3px;

    display:inline-block;
    cursor:pointer;
    color:#ffffff;
    font-family:Arial;
    font-size:18px;
    padding: 0 10px 10px 10px;
    text-decoration:none;
    text-shadow:0px 1px 0px #154682;
    width:20px;
    height:25px;
    vertical-align:-1px;
    line-height:auto;
}
.myButton:hover {
    background-color:#0061a7;
}
.myButton:active {
    position:relative;
    top:1px;
}
.resizedTextbox {width: 50px; 
height: 20px;
padding: 5px 5px 5px 5px;
border-color:#3e12cc;
text-shadow:0px 1px 1px #154682;
background-color:#f5effb;
vertical-align:text-top;
text-align:center;
font-size:18px;
}
progress {
  background-color: #0061a7;
  border: 0;
  height: 18px;
  border-radius: 9px;
}

What I am basically trying to do is to have a 'good' vertical alignment (in my example, we can see that it's not very well aligned).

Before annoying you - and risking a negative downvote - I tried to google my problem, but I could not find the issue that I am having. Am I missing a property or did I set it incorrectly ?

Thanks for your hints


Solution

I was able to align it with

vertical-align:-6px;

Try this it should work. Please share a codepen going forward, so that its easier for others



Answered By - Gowtham Shiva
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to vertical center Bootstrap column contents that collapse to vertical on small screens

 November 18, 2022     css, html, twitter-bootstrap, vertical-alignment     No comments   

Issue

Short version:

I am using Bootstrap 3.3.7 and have a row where I need:

  • the columns to be horizontal, when the screen is wide enough
  • the column contents to be vertically centered when horizontal
  • the columns to stack vertically, when the screen is too narrow

The column heights aren't the same as each other or knowable in advance. How do I achieve my three goals?

Detail:

I have a visual component in my web page that has an image on the LHS and some text in media blocks on the RHS. The media blocks are taller than the image (exactly how much depends on the screen width and wrapping of the text).

We are using Bootstrap 3, so the basic HTML for this is:

<Row>
  <Col md={6}>
    <img src="myimage.jpg"/>
  </Col>
  <Col md={6}>
    <div>a media block</div>
    <div>another media block</div>
    <div>etc</div>
  </Col>
</Row>

So that the visual design looks clean and tidy I need to vertically centre the image on the LHS. To do this I've used flex boxes:

.eq-height-cols-wrapper: {
  display: flex;
}

.eq-height-col: {
  margin-top: auto;
  margin-bottom: auto;
}

<Row class="eq-height-cols-wrapper">
  <Col class="eq-height-col">
  ...

This seems to be the pretty standard solution for modern browsers (e.g.: 1, 2), but it means the columns don't stack at small screen width.

What can I do to vertically centre a column of unknown height relative to the other columns, also of unknown height, so that at small screen width it collapses and displays vertically?


Solution

Use a @media query to only apply on larger screens. Since the md breakpoint is 992px in Bootstrap, you'd use this. Flexbox is a good method for vertical centering.

@media (min-width: 992px) {
 .eq-height-cols-wrapper: {
  display: flex;
 }

 .eq-height-col: {
  margin-top: auto;
  margin-bottom: auto;
 }
}


Answered By - Zim
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I vertically align a TableCell (or its content) of a FlowDocument

 November 18, 2022     flowdocument, vertical-alignment, wpf, xaml     No comments   

Issue

Is there any way to align the content of a TableCell to the bottom? I thought this was easy, but obviously, it is not.

The situation:

Inside a FlowDocument I have the following (simplified) Table:

<Table>
    <Table.Columns>
        <TableColumn Width="Auto"/>
        <TableColumn Width="Auto"/>
        <TableColumn Width="Auto"/>
    </Table.Columns>
    <TableRowGroup>
        <TableRow>
            <TableCell>
                <BlockUIContainer>
                    <Image Source="{Binding to an image}"/>
                </BlockUIContainer>
            </TableCell>
            <TableCell containing something else/>
           <TableCell>
                <BlockUIContainer>
                    <Image Source="{Binding to another image}"/>
                </BlockUIContainer>
            </TableCell>
        </TableRow>
    </TableRowGroup>
</Table>

The two images do not have the same height so there is some empty space below the smaller of them.

What I want:

Instead, I want the empty space above the smaller image (i.e. the images aligned to the bottom of the TableRow).

What I tried:

I tried to find a VerticalAlignment property to change the alignment. However, there is no VerticalAlignment property in BlockUIContainer, TableCell or TableRow.

Also, I tried replacing the BlockUIContainer by an InlineUIContainer and setting its BaselineAlignment. However, to do this, I had to wrap it into a Paragraph like so:

<TableCell>
    <Paragraph>
        <InlineUIContainer BaselineAlignment="Bottom">
            <Image Source="{Binding to an image}"/>
        </InlineUIContainer>
    </Paragraph>
</TableCell>

Now I have an image aligned to the bottom of a Paragraph which is aligned to the top of the TableCell and only as high as required for the Image. So it looks exactly as it did before.


Solution

The only way to do this in my experience is to use a grid to format an entire table row. Use the grid to create columns, not the table. Therefore you can use the capabilities of the grid to bottom align your images. Here is what your table might look like now...

    <Table>
        <TableRowGroup>
            <TableRow>
                <TableCell>
                    <BlockUIContainer>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Image Grid.Column="0" Source="Images/globe.png" Height="10" Width="10" VerticalAlignment="Bottom"/>
                            <TextBlock Grid.Column="1" TextWrapping="Wrap">This is something else</TextBlock>
                            <Image Grid.Column="2" Source="Images/globe.png" Height="20" Width="20" VerticalAlignment="Bottom"/>
                        </Grid>
                    </BlockUIContainer>
                </TableCell>
            </TableRow>
        </TableRowGroup>
    </Table>


Answered By - AQuirky
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to center large font text and let small font text align bottom

 November 18, 2022     css, font-size, html, vertical-alignment     No comments   

Issue

I want to have two text blocks on the same row, where the text with larger font is vertically aligned middle and the text with smaller font has the same text baseline as the one with larger font. Look at my fiddle where the large text is centered as desired. The smaller text though is also centered, but I want it to be a bit lower so that it feels like the two text blocks are on the same "line". https://jsfiddle.net/phzzhevq/2/

HTML:

<div class="my-table">  
    <div class="my-cell">
        <span class="large-text">Large text</span>
    </div> 
    <div class="my-cell">
        <span class="small-text">Small text</span>
    </div>
</div>

CSS:

.my-table {
    display: table;
    height: 80px;
    background-color: red;
}

.my-cell {
    display: table-cell;
    vertical-align: middle;
}

.large-text {
    font-size: 40px;
}

.small-text {
    font-size: 20px;
}

Image that explains the desired result: Desired result


Solution

Try this little fix. Please let me know if this is what you wanted.

.my-table {
  display: table;
  height: 80px;
  background-color: red;
}

.my-cell {
  display: table-cell;
}

.large-text {
  font-size: 40px;
  line-height:80px;
}

.small-text {
  font-size: 20px;
   line-height:80px;
}


Answered By - Sree Nath
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing