Change text-align responsively (with Bootstrap 3)?

后端 未结 9 2228
心在旅途
心在旅途 2021-01-30 09:54

I\'m using Bootstrap 3 for a blog. In my custom CSS, I recently added

body {
    text-align: justify;
    ...
}

I like the result on bigger scr

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 10:36

    Although the provided solution is absolutely right, I think there is a different approach that could be interesting. Bootstrap does not provide alignment classes that depend on window size, but you can define them:

    .text-justify-xs {
        text-align: justify;
    }
    
    /* Small devices (tablets, 768px and up) */
    @media (min-width: 768px) {
        .text-justify-sm {
            text-align: justify;
        }
    }
    
    /* Medium devices (desktops, 992px and up) */
    @media (min-width: 992px) {
        .text-justify-md {
            text-align: justify;
        }
    }
    
    /* Large devices (large desktops, 1200px and up) */
    @media (min-width: 1200px) {
        .text-justify-lg {
            text-align: justify;
        }
    }
    

    Then, you could add this classes to your html elements:

    
    

    You can also create css rules for text-left-xx and text-right-xx.

提交回复
热议问题