I have a block of text inside a div tag that looks great on the desktop, but when you shrink the page for mobile and the div's get stacked, the text does not wrap and just trails off the side. I am not very experienced with this, but I'd really like to learn how to fix this.
My CSS for the div
#homemain {
line-height: 15px;
background-color: transparent;
height: 500px;
width: 600px;
float: left;
padding: 10px;
font-size: 100%;
margin: 10px;
word-wrap: break-word;
}
My HTML on the page
<div id="homemain">
[rev_slider home_small]
<h2>[title size="2"]Explore Our Services[/title]</h2>
Text text text, texty text, lots and lots of stuff about our services and what we do. We really want you to use our services and what not. We're the best.
</div>
This is a page inside WordPress btw, if that makes much difference here. I did not create the page, just inherited it and tasked with fixing it because I'm the most "techie" person in the office. Lucky me! Any help on this would be helpful.
The problem is that you want a responsive layout, yet you're using a non-responsive approach. Remember that in order to get a responsive layout, you need to think it in terms of non-fixed sizes (%, rem, etc)
So, in your code, where you have this:
#homemain {
line-height: 15px;
background-color: transparent;
height: 500px;
width: 600px;
float: left;
padding: 10px;
font-size: 100%;
margin: 10px;
word-wrap: break-word;
}
You should change it to :
#homemain {
line-height: 15px;
background-color: transparent;
height: 500px;
max-width: 100%;
float: left;
padding: 10px;
font-size: 100%;
margin: 10px;
word-wrap: break-word;
}
However, if you need to have that 600px width on desktop, then you can use this:
#media handheld, only screen and (min-width: 767px) {
#homemain {
line-height: 15px;
background-color: transparent;
height: 500px;
width:600px;
max-width: 600px;
float: left;
padding: 10px;
font-size: 100%;
margin: 10px;
word-wrap: break-word;
}
}
and for smaller screens:
#media handheld, only screen and (max-width: 767px) {
#homemain {
line-height: 15px;
background-color: transparent;
height: 500px;
width:600px;
max-width: 320px; /* or whatever size you want */
float: left;
padding: 10px;
font-size: 100%;
margin: 10px;
word-wrap: break-word;
}
}
This way, by using media types, you can have more control over your layout on different sizes
The issue you're seeing (I suspect) is that #homemain is still displaying as 600px wide, even on screens which have a screen-width smaller than 600px.
What you need is for #homemain to be full-screen-width on screens narrower than 600px but no more than 600px wide on screens wider than 600px.
Try something like:
#homemain {
[...]
width: 99%;
max-width: 600px;
[...]
}
Related
When I resize my webpage everything goes out of position. The text goes below the container and the image get too wide. How can I make it so everything stays in place when the image gets resized? I looked at a few solutions but none seemed to work for me. Any help would be appreciated!
body {
background-color: #ADD8E6;
padding: 10px;
margin: 0;
}
.hcontainer {
background-color: #FFFFE0;
height: 600px;
text-align: center
}
div h1, p {
padding-top: 10px;
padding-left: 10px;
padding-bottom: 5px;
margin: 0;
}
img {
margin: 0;
padding-top: 20px;
}
#mini {
font-size: 13px;
margin-top: 5px;
}
.imgcontainer {
background-color: pink;
}
.mcontainer {
background-color: #FFFFE0;
height: 600px;
margin-top: 20px;
padding-top: 30px;
}
li {
margin-top: 30px;
margin-left: auto;
margin-right: auto;
}
h3 {
text-align: center;
}
.list {
width: 50%;
margin-left: auto;
margin-right: auto;
}
h4 {
text-align: center;
padding-top: 20px;
Use percentages instead of px, this will make any elements a relative size when resizing the window.
Use percentages instead of Pixels, And be careful the width of all the components companied should be 100%.
So all the components width, the paddings, the margins even the borders counts! All companied should be 100% at the width.
Note: if you want to use borders is make sense more to use pixels so if you set the border for 1px for example you make the other components width companied 99%.
Another thing I recommend to you to learn and use Bootstrap to make responsive website to all platforms.
I am having an issue with the web page display on iPad. The last div jumps out at the bottom when viewed in iPad (landscape mode). See screenshot below
Here is the CSS.
div .container-home
{
float: left;
width: 290px !important;
padding: 20px;
}
img.section-icon
{
display: block;
margin-left: auto;
margin-right: auto;
width: 150px;
max-height: 150px;
}
h2.section-head
{
text-align: center;
line-height: normal;
font-size: 22px;
}
p.section-description
{
text-align: center;
}
I would really appreciate any help.
Many thanks!
Are you including a viewport?
Its because of float left and the width of them together is more than the display. You define their width for 290px and also a padding of 20px which means they're 330px and you will need a display width of 1320px at least.
Try using a gridsystem for them or give them a width value in per cent.
If you don't know what gridsystem to use, I recommend Skeleton because it is very light.
EDIT: Don't use !important because then you cannot change the value anymore !important will overwrite any other rule
Don't use hard value for width, example
div .container-home
{
float: left;
width: 20% !important;
padding: 20px;
}
img.section-icon
{
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
max-height: 150px;
}
h2.section-head
{
text-align: center;
line-height: normal;
font-size: 22px;
}
p.section-description
{
text-align: center;
}
I have 3 media queries in my CSS which seem to work fine when I resize the browser, but don't when I use the responsive design tool from the inspector ("toggle device mode") and on mobile phones.
Here is part of my CSS :
#media screen and (max-width: 1500px) {
body {
width: 100%;
}
}
#media screen and (max-width: 1200px) {
body {
width: 100%;
}
#slider_container {
float: none;
padding-top: 2em;
width: 75%;
display: block;
overflow: hidden;
padding-left: 0px;
margin-left: auto;
margin-right: auto;
}
#slide_desc {
//
width: 30%;
display: block;
float: none;
margin-top: 0;
margin-left: auto !important;
margin-right: auto;
overflow: hidden;
font-size: 1.3em;
color: #353535;
/* line-height: 2em; */
text-align: justify;
font-family: georgia;
width: 80%;
}
}
#media screen and (max-width: 768px) {
#slider_container {
width: 100%;
margin: 0px;
padding: 0px;
padding-top: 1em;
}
#menu_button {
display: block;
width: 2em;
float: right;
margin-top: 0.5em;
margin-right: 2em;
cursor: pointer;
}
#top_menu {
overflow: hidden !important;
height: 3em;
/* background-color: gray; */
}
#top_menu>ul {
margin-top: 3em;
width: 100%;
height: 0;
position: absolute;
z-index: 100;
overflow: hidden;
}
#top_menu>ul>li {
margin: 0;
/* background-color:red !important; */
width: 100% !important;
display: block !important;
}
#top_menu>ul>li>a {
text-align: left;
width: 100%;
margin-left: 0;
padding-left: 1em;
height: auto;
}
#slides_container {
display: none;
}
}
The first 2 media queries always work fine, but the 3rd gets ignored. The 3rd media query only works if the browser itself is resized below 768px.
I know there are other similar questions, but are mostly related to the use of !important, or misplacement of the queries. My queries are at the end of the file, and what's strange is they do work if the browser is resized.
Any ideas why this might be happening?
You need to set your viewport meta tag to content="width=device-width, initial-scale=1". This tells the browser to render the width of the page at the width of the device's screen. So if that screen is 320px wide, the browser window will be 320px wide, rather than way zoomed out and showing 960px (or whatever that device does by default).
HTML
<meta name="viewport" content="width=device-width, initial-scale=1">
The width property controls the size of the viewport. It can be set to
a specific number of pixels like width=600 or to the special value
device-width value which is the width of the screen in CSS pixels at a
scale of 100%. (There are corresponding height and device-height
values, which may be useful for pages with elements that change size
or position based on the viewport height.)
The initial-scale property controls the zoom level when the page is
first loaded. The maximum-scale, minimum-scale, and user-scalable
properties control how users are allowed to zoom the page in or out.
You can read more about the viewport meta tag and how it works here.
Because you have a syntax error:
#slide_desc {
//
Double-slashes are not valid in CSS.
I have this url:
oios.kemne.com
when I visit this in the mobile I get this:
The relevant html segment is as follows:
<div class="focus">
<div id="f_image">
<img src="/assets/6112e42e/images/man.jpg"></img>
</div>
<div id="text4">
<div id="f_heading"></div>
<div id="f_tex1"></div>
<div id="f_tex2"></div>
</div>
</div>
is the container.
is the image holder.
is the header.
is the column 1.
is the column 2.
The relevant css styles are as follows:
#f_image {
width: 35%;
height: 111px;
float: right;
margin-top: 12px;
}
* {
margin: 0px;
padding: 0px;
color: #333;
font-family: Arial,Helvetica,sans-serif;
}
.focus {
height: auto;
background-color: #DCDDDE;
float: left;
margin-top: 20px;
margin-right: 10px;
}
* {
margin: 0px;
padding: 0px;
color: #333;
font-family: Arial,Helvetica,sans-serif;
}
#text4 {
width: 60%;
height: auto;
}
* {
margin: 0px;
padding: 0px;
color: #333;
font-family: Arial,Helvetica,sans-serif;
}
#f_heading {
width: 80%;
height: 30px;
font-size: 15px;
color: #1A6EB4;
margin-left: 10px;
margin-top: 10px;
}
* {
margin: 0px;
padding: 0px;
color: #333;
font-family: Arial,Helvetica,sans-serif;
}
#f_tex1 {
width: 46%;
height: auto;
float: left;
font-size: 10px;
text-align: left;
margin-left: 10px;
}
* {
margin: 0px;
padding: 0px;
color: #333;
font-family: Arial,Helvetica,sans-serif;
}
#f_tex2 {
width: 46%;
height: auto;
float: left;
font-size: 10px;
text-align: left;
margin-left: 20px;
}
* {
margin: 0px;
padding: 0px;
color: #333;
font-family: Arial,Helvetica,sans-serif;
}
As can be seen from the mobile (note3), the styles are completely messed up. The image spill over the containing div and the heading overlap the column1.
If I remove the width attribute from the #f_image, then the image fits inside the containing div (.f_focus). But the problem is that, it affects the rendering in desktop browser. I can probably use two separate stylesheets for desktop and mobile. But then it would require a lot of rewriting and duplication and the styles would be scattered. More importantly, the logic of the layout is very simple - the image is 35% of the containing div. So if the containing div resizes in the mobile or any other screens, then the image should resize automatically. The fact that removing the width fits the image inside the containing div also bears testimony that there are enough room to accommodate the image. For the rest of things, ie the overlapping of the header with the column, I am not quite sure of the reason of it failing.
I am completely clueless. I even tried to debug the mobile version using firefox remote debugger. So please help me with resolving this.
Many thanks in advance.
You can use the CSS3 #media-queries over here. I don't know the width at which you'd like the mobile styles to take over the desktop styles but just for an example, I am using 768px as the width after which the mobile styles will take over the desktop styles.
#media (max-width: 768px) {
#f_image img {
width: 100%;
}
#f_heading {
height: auto;
}
}
Please place the above styles at the bottom of your stylesheet and then try viewing the website on your mobile device or try resizing your browser window to less than 768px.
I am trying to convert an existing site into responsive however there is one thing I'm struggling with here:
http://www.brandonsuffolk.com
When you resize the window I want the right column to squash the left one, however at the moment it drops underneath (however once the screen hits the other left div it will change).
When I do it with single divs it works, however as soon as I add a new div inside it, it won't work properly.
Here is the relevant CSS:
.MainOuter {
float: left;
width: 100%;
}
.MainWrapper {
max-width: 980px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
padding-top: 0px;
padding-right: 10px;
padding-bottom: 0px;
padding-left: 10px;
}
.ColumnRight {
margin-top: 20px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 20px;
float: right;
width: 290px;
padding: 0px;;
}
.ColumnLeft {
margin-top: 20px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
float: left;
width: auto;
max-width: 670px;
padding: 0px;
}
I'm afraid you're fighting the normal process of responsiveness. responsiveness is supposed to do just what it's doing. If you don't want it to drop under, find the #media for this element and change it to:
#media (min-width:0px) {
width:50%;
}
This may help
Assuming I understood, and you want the right-side column to maintain the fixed width, you'll need to use position:absolute with a left and right value, and width set to auto. This gives you a fixed side and a side that takes the rest of the screen.
Wanting it to only apply after they touch though, is where you'll have to use a media query. Set the media query to apply only when the screen is lower than 1000px, which will tell the left column to change there and become flexible.
EDIT
Try adding this CSS to your site's CSS file, at the end. Additionally I've updated the Fiddle to show how that it works. You might have to tweak the numbers a little, but it'll do what you need.
Example Fiddle
#media screen and (max-width: 1000px) {
.ColumnLeft {
position: absolute;
left: 20px;
right: 320px;
width:auto;
}
}
May this is what you mean with "squash" ?
http://jsfiddle.net/7QVVz/
CSS
.wrap {
display: table;
width: 100%;
}
.left {
display: table-cell;
border: 1px solid green;
width: 350px;
max-width: 350px;
}
.right {
display: table-cell;
border: 1px solid red;
}
.right > .text {
width: 200px;
float: right;
border: 1px solid yellow;
}
HTML
<div class="wrap">
<div class="left">LEFT</div>
<div class="right">
<div class="text">RIGHT TEXT</div>
</div>
</div>