Two side by side div's behaving as a single block - css

Div's
<div class="row">
<div class="column">
<ol>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
</ol>
</div>
<div class="column">
<ol>
<li>FirstB</li>
<li>SecondB</li>
<li>ThirdB</li>
<li>FourthB</li>
</ol>
</div>
</div>
Css
.row {
display: flex;
flex-wrap: nowrap;
}
.column {
flex: 50%;
}
The example displays two div's side by side correctly.
************ **********
First FirstB
Second SecondB
Third ThirdB
Fourth FourthB
*********** **********
Problem to solve:
If the div's are rendered before a page break, and the available space is equivalent to two lines of the list (First and Second) these two lines are displayed before the page break and the others and the second div after the page break.
************
First
Second
page break
________________________
Third *************
Fourth FirstB
*********** SecondB
ThirdB
FourthB
***********
My goal is to make the two div's behave as a single block. ie if before the page break there is not enough space available for both div's (lists) they must pass together, as a single block, to after the page break.
The problem is quite evident if converting html to multipage pdf.
EDITED
Laravel blade file to pdf with DomPDF

Apparently as of 2020 DomPDF does not support flexbox. It seems DomPDF has long refused to support float or table CSS styling. Hence it may be impossible to make two side-by-side divs with the technology you are using.
As I noted in my comment, you may want to experiment with adding some CSS like this:
.row {
page-break-after: always;
}
Or perhaps a page break both before and after the row
For the future, you should include the technology you are asking about in your question. You should tag it, if possible. The tag css is far too vague for a question about a very specific PHP package.

Related

why is my css and html not placing my items where i want them

I have just (i.e., today!) started with the CSS grid but it doesnt seem to work. Before that however I notice that every single tutorial about it uses class instead of id. Is this because you have to use classes and not ids? I used class anyway but it still didn't work!
OK... just a simple structure to start with. I want a header, LH column for nav, main area, and RH column for other stuff (css in external stylesheet) but the header text and picture just appear on the LHS rather than 200 pixels in.
.container
{
display:grid | inline-grid;
grid-template-columns:200px auto 250px;
grid-template-rows: 300px auto;
}
.navbar
{
grid-column-start:1;
grid-column-end:2;
grid-row-start:2;
grid-row-end:3;
}
.header
{
grid-column-start:2;
grid-column-end:4;
grid-row-start:1;
grid-row-end:2;
}
and the HTML: (obviously inside the <body> tags!)
<div class="container">
<div class="header"><h1>Astronomy Speakers - Astronomical Societies</h1><img src="headerpic.jpg" alt="astrospe akers header" style="margin-left:40px" /></div>
</div>
for .container, you cannot have both grid and inline grid.
What I think happened here is you copied this code from a website that had grid | inline grid displaying as the options for the display property
The difference between class and Ids is that classes can be used several times on the same page,while Ids can only be used once on the same page. Also I did not see navbar used on your HTML code.

Using flex-box css to format a page header with varying element types

I am trying to style a page header within our application using flex display.
Where I'm having trouble is how to set my class device-name-test to float right on my dashboard header.
<div class="diagnosis-header" [class.disabled]="headerIsDisabled">
<div class="either-toggle diagnosis-title">My Dashboard</div>
<div> more elements here in between... </div>
<!-- Here is my final dev which should be floated all the way right -->
<div class="device-name-test">Device Name here !</div>
</div>
Looking at my online project here, you'll that my text Device Name Here! text is the final div - which should float all the way right (flex-end?)
https://angular-9-dashboard-flex-example.stackblitz.io/
I am trying to get a strong grasp of using flex display but some details are not clear.
thanks in advance.
Bob
I got it to work by removing flex:1 and adding margin-left:auto to the last div. Like this:
.device-name-test {
/* flex: 1; */
margin-left: auto;
}
It's exlained here: https://medium.com/#iamryanyu/how-to-align-last-flex-item-to-right-73512e4e5912.

Resolving overlap between fixed header and first section

I am coding up a landing page with the classical setup :
A fixed header
Several sections (product description, testimonials, google map, etc.)
A footer
My semantics look like this :
<header>
<!-- Responsive navigation bar -->
</header>
<section class="section-first">
<!-- First section -->
</section>
<section>
</section>
...
<footer>
</footer>
As the header is fixed, I need a specific CSS treatment on the first section, as such :
.section-first {
margin-top: 200px;
}
so that the header and the first section do not overlap. So eventually my first section needs to be treated differently than others. My current approach seems like a tweak to me, there should be either a semantical way to approach this or a clean CSS market practice in such common situation. Any ideas ?
You could use the :first-of-type pseudo element!
section:first-of-type{
margin-top:200px;
}
This finds the first section tag in your HTML without having to add an extra class to it and only applies the written styles to that one.

Dreamweaver CC not recognising html5 selectors

I'm not to sure whether I've asked this question in the right place. If not could you direct me to the correct outlet. Thanks. Anyway down to the question. I spent some time last night installing the new shiny Dreamweaver CC (Creative Cloud version) and all seemed to be going swimmingly, until; I found myself having trouble getting DW to recognize HTML5 Css Selectors.
I have a basic page as of current and I'm using the and tags. However when I try to apply styles to these elements, I get no response or change at all. both in DW design view and the browser (Firefox/Chrome).
I'm working from an external style sheet at present, and have built most of the document via hand code. I can see (div) elements in the selector pane to the right of my design view, and divs are receiving their styles. But the 'header' selectors, although hand coded into the Css document are not showing and are not being recognized by DW.
I have;
Hand coded the elements.
Checked doctype.
Checked for spelling errors.
Tried converting the HTML 5 tags to <div id="header"> & Css from header {} to #header {} (Even this draws no change in the selector pane or the browser window.)
<!--/ header /-->
<header>
<!--/ logo / heading /-->
<div id="site-header">
<section id="logo"><h1>title / logo</h1></section>
<section id="heading"><h3>heading</h3></section>
</div>
<!--/ navigation /-->
<div id="site-nav">
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Projects</li>
<li>Achievements</li>
<li>Contact</li>
</ul>
</div>
</header><!--/ << end header /-->
<!--/ (css) heading /-->
header {
position: relative;
width: 100%;
height: 150px;
margin:0;
padding:0;
}
So after staring for hours at the code on here and in the document, it turns out I was using html comments in the css code. - << I'm such a moron. Thanks for the help guys.
<!--> does not work in css. changed the comments from, <!--> to /*--*/.

Semantic HTML Practice

I read about semantic HTML online...
Semantic HTML means using HTML tags for their implied meaning, rather than just using (meaningless) div and span tags for absolutely everything.
If you use <h1> instead of <div class="header">, and <h2> instead of , et cetera, Google and other search engines will interpret your headers as being important titles in your page. This way, when people search on the words in your headers and sub-headers, your page will be considered more relevant (and rank higher). Plus, it's much shorter and cleaner.
So, below is semantic,
<h1>My Website Name</h1>
<h2>My Website Tagline </h2>
What about this below?
<div id="header">
<h1><span class="hide">My Website Name</span></h1>
<h2><span class="hide">My Website Tagline</span></h2>
</div>
I tend to combine h tags with div and span tags like above - is this practised considered as the lack of semantic?
The reason why I have the span with the hide class is that I want to display the site logo instead of text. So use CSS to set the background of h1 as image and then hide the text. is this incorrect practise?
Then, if I don't use div, what can I use to make a box around the h1 and h2?
As far as I know, html 5 is not fully ready yet, we must not use <header> yet, must we??
Thanks.
I would do something like the following if I was going to use HTML5:
<header>
<hgroup>
<h1>My Website Name</h1>
<h2>My Website Tagline</h2>
</hgroup>
</header>
Remember to add display: block; to the HTML5 elements and createElement for IE in the CSS though. The header element shows the block is a header and the hgroup element is there to show that the second h* element is a sub heading, so shouldn't be taken into account when calculating the header levels in the document.
If you don't want to use HTML5 yet then you could use divs instead of the new elements, and use the HTML5 element names as the class value. This will make it easier to switch over when you feel comfortable using HMTL5 on a live site.
You don't really need to use the span elements. You can use tricks such as using a large negative text-indent in the CSS to hide the text off the screen.
If you want to display a logo instead of text, use an image. Google say so (even if they don't know the difference between a tag and an attribute). Taglines, BTW, are not subheadings (and the site name (and thus logo) is usually only a heading on the homepage).
<div id="header">
<h1><img src="foo.png" alt="My Website Name"></h1>
<p><img src="foo.png" alt="My Website Tagline"></p>
</div>
Unfortunately, Internet Explorer 8 does not recognize many HTML5 tags, and when I've tested it, I was unable to set CSS values for the <header> tag, for example. So for now I would recommend that you continue to use div tags to group your semantic meaning.
As a sidenote, Google does not like hidden text, and if you have a lot of it, it will consider it deceptive coding. One is probably fine, but you'd be better off using the alt attribute on the image tag.
Nobody suggested that you should not use DIVs at all... semantic HTML does not mean there cannot be div or span tags in your code. It just only means that whenever possible (there is a specific tag available for a specific semantic meaning) you should try to give semantic meaning.
h2 is not to be used for taglines, as somebody else already suggested.
Also, in my interpretation (some will argue), h1 is not for the name of your website. It is the title for the content on a specific page.
I agree with #David Dorward, the tag line should be in a p tag.
Your example (wrapping the header elements with a div) is perfectly acceptable, though I would like to raise a small caution: Be careful that you do not get in the habit of wrapping everything in div tags. For example:
<div class="content">
<div class="list">
<ul>
<li>something</li>
<li>something</li>
<li>something</li>
</ul>
</div>
</div>
Since a ul tag is already a block element, the above markup would be better off like this:
<div class="content">
<ul class="list">
<li>something</li>
<li>something</li>
<li>something</li>
</ul>
</div>
And then just style the ul to look like the div.
On the matter of displaying the logo as an image:
If your logo is text-based, or has text in it, you would be better off doing the following:
HTML
<div id="header">
<h1 class="logo">My Logo Text - My Website Tagline</h1>
</div>
CSS
.logo { text-indent:-9999px;background-image:url(thelogo.jpg) no-repeat;}
/* Also add height and width based on your logo height and width */

Resources