I am trying to put MathJax content inside a div with the css 'overflow:auto' so that the div will show a horizontal scroll bar for long mathematical expressions.
But, i am getting a strange behavior. The existing div is like the first one in the following snippet. However when I add overflow:auto, a vertical scroll bar appear (see the second div in the following snippet). By looking into the details, I understand, it is caused due to the alignment caused by MathJax classes.
Note that, changing box-sizing or vertical-align property does not solve this issue. But, if I add a padding-bottom to the div or if i set overflow-y:hidden, this can be solved. But I am not sure if this is the right approach.
Could anyone help me to understand exactly why the overflow-auto is forcing a padding bottom for the div, why it is not included in the height of the div forcing the vertical scrollbar to appear, and what is the best way to resolve it. Thanks
.margin-botom-zero {
margin-bottom: 0;
}
.red {
background: red;
}
.blue {
background: blue;
}
.overflow-auto {
overflow-x: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax:{inlineMath: [['$','$']]} });
</script>
<div class="red">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
<br>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
As I commented there is a lot of code dynamically added by the plugin and it's difficult to identify the issue. It's clearly an overflow issue created by one among all the nested span and it's somehow random.
For example, if you replace the numbers with letters you won't have the issue:
.margin-botom-zero {
margin-bottom: 0;
}
.red {
background: red;
}
.blue {
background: blue;
}
.overflow-auto {
overflow-x: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax:{inlineMath: [['$','$']]} });
</script>
<div class="red">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
<br>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{j}$</p>
</div>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{9}$</p>
</div>
An idea of fix is to increase the line-height of p to avoid the overflow. It remains an approximate solution for this particular case. It will probably not work in other situations:
.margin-botom-zero {
margin-bottom: 0;
line-height: 2.7em;
}
.red {
background: red;
}
.blue {
background: blue;
}
.overflow-auto {
overflow-x: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax:{inlineMath: [['$','$']]} });
</script>
<div class="red">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{j}$</p>
</div>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{9}$</p>
</div>
Related
Contained within a parent element (e.g., div, ul), I would like to set the color of a single paragraph, then have all subsequent paragraphs receive the same color -- until a new class of paragraph comes along to change the color. I tried to implement selectors to get the job done, but the mixed results only ended up confusing me. Suggestions would be appreciated. Thank you.
<html>
<head>
<style>
p.r { color: red; }
p.g { color: green; }
</style>
</head>
<body>
<p class="r">RED
<p class="g">GREEN
<p class="r">RED
<p>red
<p class="g">GREEN
<p>green
<p class="r">RED
<p>red
<p>red
<p class="g">GREEN
<p>green
<p>green
</body>
</html>
Set the style on the parent class ie.
HTML
<div class="parentdiv">
<p>this will appear blue</p>
<p>this will also appear blue</p>
<p class="green">this will appear green</p>
</div>
CSS
.parentdiv p {
color: blue;
}
.parentdiv .green {
color: green;
}
It's not a very scalable solution, but one option is to repeat the adjacent sibling combinator and p:not([class]) for as many consecutive <class> + <classless> elements there are in a row:
p.r,
p.r+p:not([class]),
p.r+p:not([class])+p:not([class])
{
color: red;
}
p.g,
p.g+p:not([class]),
p.g+p:not([class])+p:not([class])
{
color: green;
}
<p class="r">RED</p>
<p class="g">GREEN</p>
<p class="r">RED</p>
<p>red</p>
<p class="g">GREEN</p>
<p>green</p>
<p class="r">RED</p>
<p>red</p>
<p>red</p>
<p class="g">GREEN</p>
<p>green</p>
<p>green</p>
Basically, I have two columns, each with row divs of different height (dynamic content). on the right column, the bottom div has a scrollable set of content. What I want to do is to be able to make the scrollable div have a max-height such that its bottom lines up with the end of the divs in the first column.
The biggest difference I see between my question and How do I keep two divs that are side by side the same height? is that my 2 divs do not start at the same point (and I don't want to use flexbox due to compatibility issues with IE)
VERY simple plunkr: http://plnkr.co/edit/P1yvJon24xOeb3B9as3P?p=preview
HTML
<div class="row">
<div class="col-md-8">
<div class="row row1">randomly heighted content</div>
<div class="row row2">
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
</div>
</div>
<div class="col-md-4">
<div class="row row3">
<p>random content</p>
</div>
<div class="row row4">
<div class="scroll-container">
<div class="scroll">
<p>item1</p>
<p>item2</p>
<p>item3</p>
<p>item4</p>
<p>item5</p>
<p>item6</p>
</div>
</div>
</div>
</div>
</div>
(in the plunkr I want the item1....item6 to line up with the bottom of the red div)
CSS
.row1 {
background-color: yellow;
}
.row2 {
background-color: red;
}
.row3 {
background-color: blue;
}
.row4 {
background-color: green;
}
.scroll {
overflow-y: scroll;
max-height: 100px;
}
Things I've tried:
1) Setting fixed heights for each div. This doesn't work because I need the height to change with the content for the other divs. In addition, the inner content isn't responding to fixed heights.
2) I don't think I want to use tables because a) I have heard it is very bad style b) It doesn't matter/really shouldn't be the case that row1 and row3 are the same height
3) Flexbox is a problem because it works very poorly in tandem with percentages padding. And the top left div is a video with the 0 height padding-bottom trick to make it preload the space properly. So one option would be to find a way around the padding-bottom trick and then use flex box.
4) The weird padding: 100000px; margin: -1000000px; trick didn't work when I tried it, however I could simply be missing an additional step
I don't think this is possible using only HTML/CSS, because the height of a particular div needs to be dynamically determined that relies on another div that isn't its parent or child.
Therefore I was able to solve it using JavaScript:
http://liveweave.com/3014aD
Here are the files should Liveweave ever go down.
index.html
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css"> <!-- Put your style.css below bootstrap, so that your custom css overrides it -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <!-- jQuery -->
<script src="script.js"></script>
</head>
<body>
<div class="row">
<div class="col-left col-md-8"> <!-- Added col-left class here -->
<div class="row1">
<p>randomly heighted content</p>
</div>
<div class="row2">
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
</div>
</div>
<div class="col-right col-md-4"> <!-- Added col-right class here -->
<div class="row3">
<p>random content</p>
</div>
<div class="row4">
<div class="scroll-container">
<div class="scroll">
<p>item1</p>
<p>item2</p>
<p>item3</p>
<p>item4</p>
<p>item5</p>
<p>item6</p>
<p>item7</p>
<p>item8</p>
<p>item9</p>
<p>item10</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
style.css
.row1 {
overflow: auto;
background-color: yellow;
}
.row2 {
overflow: auto;
background-color: red;
}
.row3 {
overflow: auto;
background-color: blue;
}
.row4 {
overflow: auto;
background-color: green;
}
.scroll {
overflow-y: scroll;
}
.col-left {
padding-right: 0px !important;
}
.col-right {
padding-left: 0px !important;
}
script.js
function SetHeight() {
var left = $(".col-left").css("height");
var right = $(".row3").css("height");
var result = parseInt(left) - parseInt(right);
$(".scroll").css("height", result);
}
$(window).resize(function() {
SetHeight();
});
SetHeight(); // Call once to start off with
In my html I get 'response' from controller. Number of lines in the response varies (max is 3).
What is the best way to 'reserve' 3 lines on my html page so the next div with 'SOMETHING' paragraph is not scrolled down by 'response' ?
<div class="row">
<p ng-bind-html="response"></p>
</div>
<div class="row">
<p>SOMETHING</p>
</div>
Using CSS, fix the height occupied by your 3 rows and use overflow to scroll within that fixed height div.
CSS Overflow might help you.
.row-fixed-height {
height: 150px;
overflow: scroll;
}
and in HTML:
<div class="row-fixed-height">
<p ng-bind-html="response"></p></div>
Since the height of the lines varies based on font and font size, I would use line breaks to "reserve" the three lines. If you were to use for instance a fixed height on the div or p, it might jump around on a different browser that uses a different font.
Live Demo:
#response {
background: red;
}
<div class="row">
<p id="response" ng-bind-html="response">
<br />
<br />
<br />
</p>
</div>
<div class="row">
<p>SOMETHING</p>
</div>
JSFiddle Version: https://jsfiddle.net/rspyho74/
As oori pointed you, this is is about CSS, not Angular. The easiest way to fix the height to 3 lines is using the em unit:
.row{
margin: 10px;
padding: 5px;
border: 1px solid #000;
border-radius: 5px;
}
p{
float: left;
margin: 0 5px;
padding: 5px;
border: 1px solid #000;
height: 3em;
}
<div class="row">
<p ng-bind-html="response"></p>
<p ng-bind-html="response">Line 1</p>
<p ng-bind-html="response">Line 1<br>Line 2</p>
<p ng-bind-html="response">Line 1<br>Line 2<br>Line 3</p>
<div style='clear: both;'></div>
</div>
<div class="row">
<p>SOMETHING</p>
<div style='clear: both;'></div>
</div>
As you can see, the paragraph keeps its height no matter how many lines there are. If you remove the height property you can see the difference.
I have a column layout design where I will have some fields on the left, and--when hovering one such field--info about them on the right. However, I can't seem to get it working. Please let me know what you think.
EDIT I am totally flexible to changing the HTML, CSS, or both. Also, I would prefer not to use javascript, if possible.
HTML:
<div id="content">
<div class="content-left">
<p class="one">This is page1 left content</p>
</div>
<div class="content-right">
<p class="one_info">This is page1 right content</p>
</div>
</div>
CSS:
.content-left{
background-color: #bcc5d8;
display: inline-block;
float: left;
width: 75%;
margin-left:15px;
margin-right:5px;
}
.content-right{
background-color: lightsteelblue;
display: inline-block;
margin-right:15px;
//margin-bottom:16px;
}
.one_info{
opacity:0;
}
.one:hover .one_info{
opacity:1;
}
Code in motion:
https://jsfiddle.net/828qthhq/3/
Your CSS is written in a way such that .one_info will only get an opacity of 1 if it is a child of .one.
In other words, you would get the desired effect using the following HTML.
<div class="one">
Always visible
<div class="one_info">Show on hover</div>
</div>
In order to use your current HTML and still get the desired effect, you would need to use javascript.
As others have stated, the way you're doing it is a tad off! Here is a solution using javascript! I added onmouseover and onmouseout events to the first div which call a JS function to toggle the opacity.
<script>
function toggleInfo(on){
var styleToSet;
if(on){
styleToSet = "opacity:1";
} else{
styleToSet = "opacity:0";
}
document.getElementById("test").style=styleToSet;
}
</script>
<div id="content">
<div class="content-left" onmouseover="toggleInfo(1)" onmouseout="toggleInfo(0)">
<p class="one">This is page1 left content</p>
</div>
<div class="content-right">
<p id="test" class="one_info">This is page1 right content</p>
</div>
</div>
I need the right column to have the same height as the left column, because the border needs to go all the way down to the end of the page, it is apart of the design.
I thought about setting the border on the row class but there is spacing between the column and row and was unable to override that spacing.
Any help getting the right column to stretch the entire page would be appreciated, thanks.
http://www.bootply.com/117727
css
html, body { min-height: 100%; }
.container { min-height: 100%; }
.left { border: 1px solid red; }
.row { border: 1px solid purple; }
.right { border: 1px solid green; height: 100%; }
html
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-8 left">
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
</div>
<div class="col-sm-4 right">
<p>this is a paragraph</p>
</div>
</div>
</div>
</div>
Add a class .equalCol to both of your column. And use this jQuery code to do the magic.
BOOTPLY DEMO
var highestCol = Math.max($('.left').height(),$('.right').height());
$('.equalCol').height(highestCol);
The code here is calculating and comparing the height of both columns and storing the max value in the highestCol variable. Later that highest value is being applied to both the column via same class i.e. .equalCol