I did this neat heading for a website using Bootstrap and some CSS tricks : http://www.bootply.com/QH5olSGxDU
But when using a smartphone with small width (such as an iPhone), the text overflows as shown here : http://imgur.com/k6JaKbi
Have you any idea how to prevent this (idealy by cropping the title like "Some Stuff #6 - Lorem...")? I tried the CSS property text-overflow, but it doesn't work.
You could use media queries to reduce the font size of the <h2> when the screen size is smaller than a certain size.
#media (max-width: 400px){
div.header-image-single h2 { font-size: 16px; }
}
Alternatively, you could use javascript to check the window size and if it is smaller than a certain value trim certain tags to a set number of characters.
var str = originalString.substring(0, X); //original string comes directly from the content of the <h2>, the 0 is the starting position and the X is the number of characters you want to keep
here is a JSFiddle that shows this alternative in action (I utilized jQuery to make the selection/manipulation of elements easy, but it would be done with plain JS too)
What about
h2 {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
width: 300px; (I've used this to test without a mobile device)
}
?
You could only apply white-space: nowrap; in your mobile css if desired.
Beside adjusting the font size of the text you can also add simple min-height to the image.
.header-image img {min-height: 275px;width: 100%;}
Related
I have the issue that on mobile devices with a screen size less/equal 320px the content is not shown 100% wide which you can see in this image:
I have also uploaded the files here:
http://files.ailola.com/tmp/v1/privacy.php
I have been able to figure out the following points:
When I add a width to the < html > tag, e.g. width=150%, I can somehow fix the issue but it breaks then other areas of the site. I assume that it might be related somehow to this line:
The issue does not happen when I remove the DIV with ID=container. However editing the styles for the container does not bring me to any solution.
The issue happens only in Chrome browser (My version is 83.0.4103.97 (Official Build) (64-bit) on Mac OS 10.15.4) and iOS (My version is 13.3.1 on iPhone 6s). However in Firefox I cannot reproduce the issue. Maybe it is just Apple-related.
Removing the linked stylesheet does not solve the issue neither.
I just do not figure out the reason. Do you have an idea? Thanks so much for your help.
There are multiple paragraphs on your page which are overflowing container due to default word wrapping strategy.
To fix the issue apply either word-break or overflow-wrap style to your paragraph:
p {
...,
word-break: break-all;
}
or
p {
...,
overflow-wrap: break-word;
}
I fixed this with the following:
#media only screen and (max-width: 320px)
#container {
max-width: inherit;
width: 100%;
padding: 0 1em;
word-break: break-word;
}
The problem is because, inside the content, you have links, those are like an entire word, so the container tend to adapt to the longest word (this issue is present in some languages that have long words or expressions). In those cases, you have to use the property word-break. You can find more info here
EDIT:
Apparently, the value break-word of the property word-break is deprecated. Also you can use the property overflow-wrap with the value break-word, as it is has a similar effect.
Set initial-scale=1 inside the meta viewport tag in line number 6
We have to give width: 100% to header, footer and #container.
The word-break property specifies how words should break when reaching the end of a line.
p {
word-break: break-word;
}
#media only screen and (max-width: 767px) {
header, footer, #container {
width: 100%;
padding: 0 25px;
}
}
I learn to build websites. Now I'm making page to practice and I have a problem. I haven't already made it responsive but I've seen that below 630px width page isn't 100% width anymore. On the right of the page appear white space and I don't know why is that and how to fix that.
Can you help me?
screen of my problem
This happens if any box (e.g. an <img>, a <span> or a <table>) is wider than width of browser window.
Images does not shrink and words does not break by default. Boxes can not be smaller than all cells in a row together.
Utilize different responsive techniques to avoid overstretching of viewport.
img {
max-width: 100%;
}
a,
p,
span {
hyphens: auto;
}
/* wrap tables in <div class="horizontal-scroll-wrapper"> */
.horizontal-scroll-wrapper {
overflow-x: scroll;
}
Browser's built-in inspectors helps to find types of not shrinkable elements.
I have 2 boxes (About Us and Contact Us) that don't change (stack) when you resize the browser. I've checked the forums and it looks like I need either a clear:both or overflow:hidden. My problem is, I've tried both of those anywhere I can think of and nothing happens.
So far, I've tried overflow in the wrapper, box1 and box2. As well as paragraphs 1-3. I've also tried clear in pretty much every spot around/in/under the wrapper div in my HTML.
When the browser reaches the 768px breakpoint, you need to change the div's display mode to block so that it doesn't allow any other item in its horizontal space.
#media (max-width: 768px) {
#box1 {
display: block;
width: 60%; /* Set according to your requirement */
}
}
Output:
JSbin
I am working on a webpage, and I want to use JavaScript to center some text (contained in a "p" with the display:inline-block attribute) when the text is shifted under everything else (on a smaller window). When the window size is big enough, I have the text on the right of the screen (where I want it for larger windows).
Basically, I have content on the left and right of the screen for bigger windows, but I want that content to become centered and vertical when the browser is smaller.
I've tried using .addEventListener() but my JavaScript knowledge is pretty limited.
Any thoughts? Does this make sense?
I see you're trying to do some sort of responsive design. You're better off doing this without any javascript.
You should look into Css Media Queries, that are meant to set specific css styles depending on the screen size:
#media screen and (max-width: 500px) {
Similar to your scenario, here's a sample showing the concept: http://jsfiddle.net/xkJ3G/
Resize the window and test it!
You can achieve desired effect using only HTML and CSS.
JSFiddle
HTML
<div class="outer">
<div class="A">A</div>
<div class="B">B</div>
</div>
CSS
div.outer {
width: 100%;
text-align: center;
}
div.A,
div.B {
width: 40%;
min-width: 250px;
display: inline-block;
}
Linebreak will be when width is lesser than min-width (in this example when 40% < 250px)
I'm using bootstrap 2.0 from twitter and unsure how to make it responsive.
How can I remove elements when in mobile/small screen mode?
How can I replace elements (i.e replace a big picture with a smaller one)?
Change a <h2> to be <h5>? etc.
Hiding Elements
You can hide elements with:
display: none;
visibility: hidden;
Hopefully you're using LESS or SASS so you can just specify:
#mixin hidden {
display: none;
visibility: hidden;
}
And then easily mix it in when necessary:
footer {
#include hidden;
}
Just apply them to any selector in the relevant media query. Also, understand that media queries cascade onto smaller media queries. If you hide an element in a wide media query (tablet sized), then the element will remain hidden as the website shrinks.
Replacing Images
Bootstrap doesn't offer image resizing as the screen shrinks, but you can manually change the dimensions of images with CSS in media queries.
But a particular solution I like is from this blog post: http://unstoppablerobotninja.com/entry/fluid-images/
/* You could instead use ".flexible" and give class="flexible" only to
images you want to have this property */
img {
max-width: 100%;
}
Now images will only appear in their full dimensions if they don't exceed their parent container, but they'll shrink fluidly as their parent element (like the <div> they're in) shrinks.
Here's a demo: http://unstoppablerobotninja.com/demos/resize/
To actually replace images, you could swap the background image with CSS. If .logo has background: url("logo.png");, then you can just specify a new background image in a media query with .logo { background: url("small-logo.png");
Change h2 to h5
If this is because you want to change the size of the heading, don't do this. H2 has semantic value: It's not as important as H1 and more important than H3.
Instead, just specify new sizes for your h1-h6 elements in media queries as your website gets smaller.
#media (max-width: 480px) {
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: 80%;
}
}
I've been playing with the responsive parts of bootstrap for the last few days, take a look at /less/responsive.less to get an idea of how you can utilize the responsive features of bootstrap.
You basically look at the browser's width/height to determine which css properties to apply to the page. So, for example if you want to change h2 when the user is using a smaller device, you would do something like this:
#media (max-width: 480px) {
h2 { font-size: 15px; }
}
You can do this with any style you want to affect when the size of the screen changes.
You can replace some elements by utilizing css replacement methods and then just have different styles affect things at different widths. Or you could use jquery or maybe response.js to do it. I'm still playing with this part of it.
For responsive images you could have
.responsive-image { max-width:100%; height:auto; }
and you could use this as
<img src="testimage.jpg" border="0" alt="blank image" class="responsive-image">
For responsive navigation
Use tinynav https://github.com/viljamis/TinyNav.js
This converts <ul> and <ol> navigation to a select box for small screens.
As to your first question - I'm not sure if this was available when you asked, but Bootstrap has classes "hidden-phone", "visible-desktop" etc to handle hiding of elements on different sized screens. Just add the .hidden-phone class to an element and it will disappear on screens smaller than 768px wide.
EDIT
After the release of bootstrap 3, the 2.3.2 documentation is now at:
http://getbootstrap.com/2.3.2/scaffolding.html#responsive
The new 3.x documentation is at:
http://getbootstrap.com/css/#responsive-utilities
I think bootstrap has built-in features for this (in responsive-utilities.less):
<a href="#">
<span class="visible-desktop">Click here to get more information</span>
<span class="visible-tablet">More information</span>
<span class="visible-phone">Info</span>
</a>