How to keep a text inside a box in small devices - html

I created two rows with their respective columns...but part of the content(heading) of the last column sticks out of the div when I scale the page down.
<div class="container">
<!------------------------------------ first section-------------------------------------------------->
<div class="row" id="firstSection">
<div class="col-xs-12">
<span class="glyphicon glyphicon-tree-deciduous"></span>
<h2 class="heading2">Your home away from home</h2>
<h4>Prima luce, cum quibus mons aliud consensu ab eo. Praeterea iter est quasdam res ex<br/>communi.Etiam habetis sem dicantur magna mollis euismod.</h4>
<p class="p1">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae dolorem id in inventore, maiores consequuntur modi? Omnis dolore quam vel. Illo accusantium, porro laudantium saepe necessitatibus id ullam voluptate nihil!<br/></p>
</div>
</div>
<!------------------------------------ end of first section-------------------------------------------------->
<!------------------------------------ second section-------------------------------------------------->
<div class="row" id="secondSection">
<div class="col-lg-6">
<article class="section1">
<span class="glyphicon glyphicon-tree-deciduous"></span>
<h2>BUSINESS TRAVELLER</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore eveniet distinctio non, dolor asperiores ducimus quidem. Tempore exercitationem, velit magnam beatae quia, similique, eaque aliquam provident inventore iste et sequi! and fre</p>
<button type="button" class="btn btn-default">READ MORE</button>
</article>
</div><!-- end of column --->
<div class="col-lg-6">
<section class="section2">
<span class="glyphicon glyphicon-tree-deciduous"></span>
<h2>ACCOMPANYING A LOVED-ONE</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore eveniet distinctio non, dolor asperiores ducimus quidem. Tempore exercitationem, velit magnam beatae quia, similique, eaque aliquam provident inventore iste et sequi!</p>
<button type="button" class="btn btn-default">READ MORE</button>
</section>
</div><!-- end of column --->
</div><!-- end of row -->
<!------------------------------------ end of second section------------------------------------------->
</div><!-- end of container -->
The CSS is as it follows
.heading2{
font-family: 'Arizonia', cursive;
font-size: 50px;
text-align: center;
}
#firstSection{
background-color:#ffffff;
margin-left:1px;
margin-right:1px;
padding-top: 120px;
margin-top:-80px;
}
.section1{
background: #ffffff;
padding: 50px;
margin-top:30px;
}
.section2{
background: #ffffff;
padding: 50px;
margin-top:30px;
}
And you can also confirm as my jsfiddle shows
https://jsfiddle.net/Wosley_Alarico/g8xj2yq4/

You can add word-break: break-all; to your .section 2 if you're okay with the title breaking in the middle of any two letters:
.section2{
background: #ffffff;
padding: 50px;
margin-top:30px;
word-break: break-all;
}
However, I would personally rather set the font-size relative to the display width with something like:
.section2 h2 {
font-size: 4vw;
}
Or use media queries to change the font-sizes for different screen widths:
#media (max-width: 500px){
h2 {
//set whatever font-size you want for headers
}
p {
//set font-size for p
}
}

By using #media queries to shrink the text down when the device is smaller.
E.g.
#media screen and (max-width:480px){
h2 {
font-size:14px;
}
}

You could do something like this to break long words
h2 {
word-break: break-word;
}
But that isn't very pretty. A better option is to use media queries to resize the font
#media screen and (max-width: 480px) {
h2 {
font: 12px;
}
}

Related

Is there an easy way to stack divs for mobile and tablet plus keep them centered?

I've got a container with some divs which make 3 boxes display horizontally.
I am trying to get the divs to stack vertically (centered) on mobile and tablets. The problem I'm having is the media queries and styles I'm using don't seem to be working properly.
<div class="container-2">
<div class="box">
<div class="icon"><i class="fa fa-compact-disc" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Artists</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
<div class="box">
<div class="icon"><i class="fa fa-calendar-alt" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Calendar</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
<div class="box">
<div class="icon"><i class="fa fa-envelope" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Contact Us</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
</div>
.container-2 {
position: relative;
width: 1200px;
height: 300px;
margin: 100px auto;
}
.container-2 .box {
position: relative;
width: calc(400px - 30px);
height: calc(350px - 30px);
background: #0000005b;
float: left;
margin: 15px;
box-sizing: border-box;
overflow: hidden;
border-radius: 10px;
}
The 3 divs (they are the boxes) will go from horizontal to vertical when on mobile and tablet plus center themselves.
Any pointers on the best way to align/move divs?
display: flex is going to be your friend here-- you change the flex-direction at your breakpoint and tweak the flex settings:
.container {
display: flex;
justify-content: space-around;
height: 100vh;
width: 100vw;
}
.inner {
height: 100px;
width: 100px;
background-color: red;
}
#media screen and (max-width: 768px) {
.container {
flex-direction: column;
align-items: center;
}
.inner {
background-color: blue;
}
}
<div class="container">
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
</div>
Using flexbox will make this task significantly easier. A link to the Codepen is here.
A rough version of your HTML and CSS are as follows:
HTML:
<div class="container-2">
<div class="box">
<div class="icon"><i class="fa fa-compact-disc" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Artists</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
<div class="box">
<div class="icon"><i class="fa fa-calendar-alt" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Calendar</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
<div class="box">
<div class="icon"><i class="fa fa-envelope" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Contact Us</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
</div>
CSS:
.container-2 {
position: relative;
width: 1200px;
height: 300px;
margin: 100px auto;
display: inline-flex;
}
.container-2 .box {
position: relative;
width: calc(400px - 30px);
height: calc(350px - 30px);
background: #0000005b;
float: left;
margin: 15px;
box-sizing: border-box;
overflow: hidden;
border-radius: 10px;
display: flex;
}
#media screen and (max-width:800px) {
.container-2 {
flex-direction: column;
width: 70vw;
}
}
I updated your CSS to switch on tablet 768px to stack the way you asked for (width: 90% with left/right margin of 5%). However I would take a different approach. I'm absolutely not happy with your fixed widths. I didn't want to rework your whole CSS and markup to something that might not fit your needs so I added just the #media queries to answer your question. I would go for a flex based approach or at least some percentage based widths depending what you are looking for.
.container-2 {
position: relative;
width: 1200px;
height: 300px;
margin: 100px auto;
}
.container-2 .box {
position: relative;
width: calc(400px - 30px);
height: calc(350px - 30px);
background: #0000005b;
float: left;
margin: 15px;
box-sizing: border-box;
overflow: hidden;
border-radius: 10px;
}
#media (max-width: 768px) {
.container-2 .box {
width: 90%;
margin: 15px 5%;
}
.container-2 {
width: 100%;
}
}
<div class="container-2">
<div class="box">
<div class="icon"><i class="fa fa-compact-disc" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Artists</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
<div class="box">
<div class="icon"><i class="fa fa-calendar-alt" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Calendar</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
<div class="box">
<div class="icon"><i class="fa fa-envelope" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Contact Us</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit, nam quae quasi enim, praesentium, deserunt voluptatibus dolores laboriosam ex odio quod aperiam ipsa aspernatur soluta suscipit et iusto quas impedit.</p>
</div>
</div>
</div>
Update: If you want to stop that unpretty overflow from happening during shrink use in the media query a value of roughly 1200px. But I still highly recommend a better approach.
Try using media query and flex container.

3 columns overlapping the footer on mobile browser

Footer is on right place but the columns in section are overlapping the footer
.columns {
float:left;
width: 22%;
height: 30%;
margin-left:8%;
}
Instead of float:left; I have used display:inline-block; but issue
not resolved this problem is occurring when website displayed on
mobile. When viewed on desktop it's working fine.
Try adding this to your CSS
box-sizing: border-box;
.container {
background: #f4f4f4;
padding: 5%;
margin: 5%;
}
.column1 {
background: #b40404;
padding: 5%;
color: #fff;
}
.column2 {
background: #000;
padding: 5%;
color: #fff;
}
.column3 {
background: #b40404;
padding: 5%;
color: #fff;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="column1">
This is column 1<br><br> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloribus vero labore obcaecati illum reprehenderit incidunt consequatur quidem, id repellendus impedit, quaerat, mollitia ea culpa sint? Totam sunt omnis quis
eaque.
</div>
</div>
<div class="col-md-4">
<div class="column2">
This is column 2<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium mollitia, incidunt accusantium iure eius suscipit fugit tempore veniam deleniti, nulla dolore repudiandae voluptas, eaque architecto ratione recusandae
consectetur officia. Saepe.
</div>
</div>
<div class="col-md-4">
<div class="column3">
This is column 3<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quis vitae nulla, beatae tenetur ea eaque obcaecati perspiciatis, architecto nemo culpa id non facilis distinctio aliquam. Accusamus voluptatum mollitia perferendis
libero.
</div>
</div>
</div>
</div>
you can use Bootstrap. Use the class container then row and define columns inside it. Like this:

How to make child-div get equal height of its parent without using flexbox

I am trying to solve this problem in many different ways and it is not working.
I have a row of 2 columns. The first column has text that will receive dynamic text. The other column has an image that must adapt its size responsively, no matter the text-content height is. The text column is leading the height of the row-parent div, so, my image-parent div must get the 100% height of that. Is there any solution available that does not use flex-box or JS? I am trying to avoid using flexbox/JS in this case.
This is the result at the moment:
The parent div is high because of a Text that is beside the image on the same row.
PS: I put a height of 100px on the image just to show you. I know I can't use a fix height. How do I make that div that contains the background-image follow the height of the parent-row div independently of the amount of content (text) that it has?
Thank you so much in advance!
Here's my HTML:
<section>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-5 col-sm-push-7 no-padding">
<div class="img-parent"></div>
</div><!-- ./col-xs-12 -->
<div class="col-xs-12 col-sm-7 col-sm-pull-5 text-parent">
<h2>My Title</h2>
<h3>My subtitle</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure, totam ducimus! Aspernatur porro, accusantium consequatur neque id praesentium ipsum consequuntur cum? Voluptates minus ad repellendus aspernatur, rem modi dolor cum.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Error culpa facere quae pariatur nam dolorem ab est perferendis! Ipsa id aut nesciunt sit ea fugiat saepe sequi quisquam labore quae.</p>
</div><!-- ./text-parent -->
</div><!-- ./row -->
</div><!-- ./container -->
</section>
And the CSS:
.text-parent{
background-color:lightgrey;
padding:30px;
}
.text-parent h2,
.text-parent h3{
font-weight:600;
text-transform:uppercase;
}
.text-parent h2{
font-size: 45px;
}
.text-parent h3{
max-width:560px;
font-size:20px;
color:#ed1c24;
margin-bottom:40px;
}
.text-parent p{
max-width:500px;
font-size:12px;
line-height:20px;
text-align:justify;
}
.row{
border:3px solid green;
}
.no-padding{
padding:0;
}
.img-parent{
height:100px; /*just to show a little part of the image*/
background-image:url("https://www.cesarsway.com/sites/newcesarsway/files/styles/large_article_preview/public/Natural-Dog-Law-2-To-dogs%2C-energy-is-everything.jpg?itok=Z-ujUOUr");
background-size:cover;
background-position:center center;
background-repeat:no-repeat;
}
Hope this will help you :
html
<section>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-5 col-sm-push-7 no-padding"></div>
<!-- ./col-xs-12 -->
<div class="col-xs-12 col-sm-7 col-sm-pull-5 text-parent">
<h2>My Title</h2>
<h3>My subtitle</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure, totam ducimus! Aspernatur porro, accusantium consequatur neque id praesentium ipsum consequuntur cum? Voluptates minus ad repellendus aspernatur, rem modi dolor cum.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Error culpa facere quae pariatur nam dolorem ab est perferendis! Ipsa id aut nesciunt sit ea fugiat saepe sequi quisquam labore quae.</p>
</div>
<!-- ./text-parent -->
</div>
<!-- ./row -->
</div>
<!-- ./container -->
</section>
css
.text-parent h3 {
font-weight: 600;
text-transform: uppercase;
}
.text-parent h2 {
font-size: 45px;
}
.text-parent h3 {
max-width: 560px;
font-size: 20px;
color: #ed1c24;
margin-bottom: 40px;
}
.text-parent p {
max-width: 500px;
font-size: 12px;
line-height: 20px;
text-align: justify;
}
.row {
border: 3px solid green;
display: table;
width: 100%;
}
.row > div {
display: table-cell;
float: none;
}
.no-padding {
background-image: url("https://www.cesarsway.com/sites/newcesarsway/files/styles/large_article_preview/public/Natural-Dog-Law-2-To-dogs%2C-energy-is-everything.jpg?itok=Z-ujUOUr");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
#media only screen and (max-width: 767px) {
.row > div {
display: block;
}
.no-padding {
padding: 25% 0;
}
.row {
display: block;
width: auto;
}
}
image-size, image-position and image-repeat are not valid CSS properties, you mean background-size, background-position and background-repeat.
Also, you don't need a separate bootstrap row for that, just set it as background for your "text" row and it'll work fine.
.text-parent{
background-color:lightgrey;
padding:30px;
}
.text-parent h2,
.text-parent h3{
font-weight:600;
text-transform:uppercase;
}
.text-parent h2{
font-size: 45px;
}
.text-parent h3{
max-width:560px;
font-size:20px;
color:#ed1c24;
margin-bottom:40px;
}
.text-parent p{
max-width:500px;
font-size:12px;
line-height:20px;
text-align:justify;
}
.row{
border:3px solid green;
}
.no-padding{
padding:0;
}
.img-parent{
background-image:url("https://www.cesarsway.com/sites/newcesarsway/files/styles/large_article_preview/public/Natural-Dog-Law-2-To-dogs%2C-energy-is-everything.jpg?itok=Z-ujUOUr");
background-size:cover;
background-position:center center;
background-repeat:no-repeat;
}
<section>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-7 col-sm-pull-5 text-parent img-parent"><!-- ADDED img-parent class -->
<h2>My Title</h2>
<h3>My subtitle</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure, totam ducimus! Aspernatur porro, accusantium consequatur neque id praesentium ipsum consequuntur cum? Voluptates minus ad repellendus aspernatur, rem modi dolor cum.</p>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Error culpa facere quae pariatur nam dolorem ab est perferendis! Ipsa id aut nesciunt sit ea fugiat saepe sequi quisquam labore quae.</p>
</div><!-- ./text-parent -->
</div><!-- ./row -->
</div><!-- ./container -->
</section>
First, image-size、image-position and image-repeat should be background-size、background-position and background-repeat。
Now, you can change '.img-parent' to:
.img-parent {
height: 100%;
background:url("https://www.cesarsway.com/sites/newcesarsway/files/styles/large_article_preview/public/Natural-Dog-Law-2-To-dogs%2C-energy-is-everything.jpg?itok=Z-ujUOUr") no-repeat center / cover;
}

Remove gap between <h1> and <p>?

How would I remove a gap between a h1 and p element? I've tried removing the padding and margins with no luck. I'm using the default bootstrap css. Any ideas?
.section1{
background-color: bisque;
}
p, h1 {
margin: 0px;
padding: 0px;
}
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
I've attached a screenshot to this post as it appears correctly when I run the code using stackoverflows 'run snippet' feature.
The page-header bootstrap class is causing the space reset it using:
h1.page-header {
margin: 0;
padding: 0;
}
See demo below:
.section1 {
background-color: bisque;
}
p,
h1 {
margin: 0px;
padding: 0px;
}
h1.page-header {
margin: 0;
padding: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
Add line-height to h1 class in your CSS. If font size is 26px, just ad 26px line height.
like:
h1.page-header{
font-size:26px;
line-height:26px;
}
Try line-height to it
.section1 {
background-color: bisque;
line-height: 15px;
}
p,
h1 {
margin: 0px;
padding: 0px;
}
.page-header{
margin:0 !important;
padding:0 !important;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
You need to reset css first. Because Browser has format CSS itself
{
margin: 0px;
padding: 0px;}
Add this above your css file

how to align column content in css

In the following html code I created a row with two columns.The first column i have an image and on the second I have my heading and a paragraph.
<div class="row">
<div class="col-6">
<img src="image/beds.jpg" alt="">
</div>
<div class="col-6">
<h2>Nevex has the experiencce</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates velit, inventore praesentium. Delectus nulla, voluptates excepturi earum minima eligendi cumque ullam, opdfgdtio nostrum ipsa maiores cupiditate facilis sint debitis aliquid. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia id beatae nostrum ducimus possimus, odit eligendi fuga perspiciatis placeat nisi facilis unde adipisci illo fugit doloremque, at porro magni, perferendis?</p>
</div>
</div>
And next is my styling code:
.row {
margin: 0 -10px;
margin-bottom: 10px;
}
.row:last-child {
margin-bottom: 0;
}
[class*="col-"] {
padding: 10px;
}
#media all and ( min-width: 600px ) {
.row {
display: table;
table-layout: fixed;
width: 100%;
}
[class*="col-"] {
display: table-cell;
}
.col-1{
width:100%;
}
.col-6{
width:50%;
}
}
How can I alter the size of the image with responsiveness and align the content of both columns?
Meaning that the image would decrease a bit in terms of height and the content of the other column would also be in the middle of the div.
one solution is to use image as a background to that div, and once you do it, you can give it a width:100%.
If you are using bootstrap, you can add the class="img-responsive" and it will automatically adapt to the width of the screen