Reputation: 27335
I want to put something into my html that forces a line break if the screen is below a certain width. This is for iOS. Can I do that?
Or, even better, is there a way to do some kind of if/else/endif that triggers off of screen width? Something like this:
if screen width < 600 pixels
some html
else
some other html
endif
If it matters, which I'm hoping it won't, this is for an iOS device, at least initially.
EDIT: Here is an example:
<body>
In spherical coordinates, given a vector field
<math>
<mn class="boldMath">F </mn>
<mn>(</mn>
<mi>r</mi>
<mn>, </mn>
<mi>θ</mi>
<mn>, </mn>
<mi>φ</mi>
<mn>)</mn>
</math>, the curl is<br>
<math>
<mrow>
<mn mathvariant="bold">∇</mn>
<mn> × </mn>
<mi mathvariant="bold">F</mi>
<mn> = </mn>
</mrow>
</math> <!-- I need a line break here on the phone, but not on the pad. On the iPad, I would be delighted to have the above included in the mtable below.>
<div class="center">
<math>
<mtable>
<!-- long mtable here -->
</mtable>
</math>
</div>
</body>
Output is good on the iPhone, not so much on the iPad. See the bottom portion of each screen shot:
Upvotes: 0
Views: 210
Reputation: 3569
opposite logic to @Jonas
#someelement br {
/* ignore <br> on large screen: */
display: none;
}
@media (max-width: 600px) {
/* force <br> on narrow screen: */
#someelement br { display: block; }
}
Upvotes: 0
Reputation: 2747
If you make the containing element less wide it will automatically break the line.
Or if you like to have more control you could use a CSS media query like this:
@media (max-width: 600px) {
#someelement { display: none; }
#someotherelement { display: block; }
}
Upvotes: 1
Reputation: 1544
You can get screen width by using this code:
CGFloat width = [UIScreen mainScreen].bounds.size.width;
Upvotes: 0