Semantically Appropriate Markup of Headings for Content Flow and Accessibility - html

I have a design that has a section that looks like the following:
As with anything, this could be marked up in several ways:
<section>
<header>
<p>About Area Title<p>
<h2>Lorem ipsum[...]</h2>
</header>
<p>Lorem ipsum dolor sit amet[...]</p>
<!-- ... -->
</section>
<!-- OR -->
<section>
<p>About Area Title<p>
<h2>Lorem ipsum[...]</h2>
<p>Lorem ipsum dolor sit amet[...]</p>
<!-- ... -->
</section>
<!-- OR -->
<section>
<h2>About Area Title<h2>
<h3>Lorem ipsum[...]</h3>
<p>Lorem ipsum dolor sit amet[...]</p>
<!-- ... -->
</section>
What would be the the best solution (might not be listed above) that not only is semantically correct but still preserves content flow and hierarchy for screen readers, bots, etc.?

I have an option for you not in the list.
The reason I would recommend this is because of how screen reader users navigate a page, majority using headings and if you did it with a separate <p> to the heading that information may get missed (I am assuming that the "About Area Title" is significant here.)
<section aria-labelledby="heading-a">
<h2 id="heading-a">
<span>About Area Title</span>
<span class="visually-hidden">:</span>
Lorem ipsum[...]
<h2>
<p>Lorem ipsum dolor sit amet[...]</p>
<!-- ... -->
</section>
Now the above is assuming that the "About Area Title" bit makes sense as part of the heading for the section (which logically it should in most circumstances).
What we then do is apply styling to both make the <span> smaller and to implement the visually hidden class to hide the : we use as a separator.
The final thing is that it is a good practice to label a section so we just point it at the heading for that section using aria-labelledby and a corresponding ID on the heading.
The following rough example shows you what I mean.
h2{
font-size: 2.5rem;
}
h2>span{
font-size: 1rem;
display: block;
}
.visually-hidden {
border: 0;
padding: 0;
margin: 0;
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 - a 0 height clip, off to the bottom right of the visible 1px box */
clip: rect(1px, 1px, 1px, 1px); /*maybe deprecated but we need to support legacy browsers */
clip-path: inset(50%); /*modern browsers, clip-path works inwards from each corner*/
white-space: nowrap; /* added line to stop words getting smushed together (as they go onto seperate lines and some screen readers do not understand line feeds as a space */
}
<section aria-labelledby="heading-a">
<h2 id="heading-a">
<span>About Area Title</span>
<span class="visually-hidden">:</span>
Lorem ipsum[...]
</h2>
<p>Lorem ipsum dolor sit amet[...]</p>
<!-- ... -->
</section>

Related

Is there any way in CSS to align an element to the end of the final linebox of a sibling?

Is there any way to achieve the layout shown in this mockup?
The supplementary text is right-aligned and if there is space it shares the same linebox as the final line of the main text.
Things I've tried
Floating the supplementary text.
Problems with this approach:
It's a float, so has all the edge cases and bugs floats have, and the next element has to deal with clearing it, and margins act in unexpected ways.
If the supplementary text is a different size, it's difficult to align it to the same baseline as the main text since vertical-align does not work on floating elements. It's possible to align them if all sizes are known, but in most cases this will require extra wrapper elements.
To share the same line as the main text, the supplementary text has to come first (this is unacceptable for me) or the main text has to be floating rather than the supplementary. And the latter case only works when the main text and supplementary text all fit on a single line, otherwise the supplementary will be below the final linebox of the main text.
Here it is with the supplementary text floated right, in both orders:
article {
clear: both;
}
header p {
float: right;
}
<article>
<header>
<h2>Lorem ipsum dolor sit amet, adipiscing</h2>
<p>Supplementary</p>
</header>
</article>
<article>
<header>
<p>Supplementary</p>
<h2>Lorem ipsum dolor sit amet, adipiscing</h2>
</header>
</article>
Flexbox
This is better in one way: flex items can be aligned by baseline without extra wrappers and tricky styling. However:
If flex wrap is not enabled the supplemental text will only ever align to the first baseline of the main text, and the horizontal area available to all lines of the main text is reduced by however much space the supplemental text takes up.
If flex wrap is enabled and the main text wraps to a second line, or otherwise doesn't leave enough space for the supplemental text, the main text's flex element's width is the full width of the flexbox or close to it, and so the supplemental text will always be on a new flex line, even if there is visual space available for it in the main text's last linebox.
header {
display: flex;
align-items: baseline;
}
header p {
margin-left: auto;
}
<header>
<h2>Lorem ipsum dolor sit amet, adipiscing</h2>
<p>Supplementary</p>
</header>
<header style="flex-wrap: wrap">
<h2>Lorem ipsum dolor sit amet, adipiscing</h2>
<p>Supplementary</p>
</header>
Absolute positioning
This is no good since if absolutely positioned, the supplemental text doesn't reserve any space and it may overlap with the main text.
This is definitely an interesting issue. Unfortunately, it does actually seem like a prime usecase for inline and floated elements, as much of a pain as they are. Of course it's a bit more difficult to see how they'll interact in a "real world" environment, but if you were to use the ":after as a table" clearfix, make the h2 inline, float the p, and remove the line-height of it, it should rest at the bottom of the typographic x-height of the h2.
Here's a quick demo:
article:after {
content: "";
display: table;
clear: both;
}
header h2 {
display: inline;
}
header p {
float: right;
line-height: 0;
}
/* Just for example layout */
body{width:100vw;overflow-x:hidden;min-height:100vh;display:flex;align-items:center;justify-content:center}div{max-width:50%}header p{position:relative}header p:after{content:"";position:absolute;width:calc(50vw - 40px);height:1px;background:red;top:6px;right:0}article{padding:20px;border:1px solid #ccc}
<div>
<article>
<header>
<h2>Lorem ipsum</h2>
<p>Supplementary</p>
</header>
</article>
<article>
<header>
<h2>Lorem ipsum dolor sit amet, adipiā€¦</h2>
<p>Supplementary</p>
</header>
</article>
<article>
<header>
<h2>Lorem ipsum dolor sit amet, adipiscing Lorem ipsum dolor sit amet, adipiscing Lorem ipsum dolor sit amet, adipiscing Lorem ipsum.</h2>
<p>Supplementary</p>
</header>
</article>
</div>
Interesting note, as #Temani Afif noted, you can replace the article:after { content: ""; display: table; clear: both; } with header { overflow: auto; } to make it self-clearing. A nice little trick to prevent littering your CSS with clear fixes
h2 {
display: contents;
}
p {
float: right;
transform: translateY(-50%);
}
article {
clear: both;
}
article:after {
content: "";
display:block;
width: 100%;
height: 1px;
background: red;
}
<article>
<header>
<h2>Lorem ipsum dolor sit amet, adipiscing blah blahh blahhhh, and long looong looooooong text content</h2>
<p>Supplementary</p>
</header>
</article>
<br>
<article>
<header>
<p>Supplementary</p>
<h2>Lorem ipsum dolor sit amet, adipiscing</h2>
</header>
</article>
and then without display: contents
and the extra gap that came can solve by setting line-height on the h2 (ex: line-height:1em;)
h2 {
display: inline;
/*line-height: 1em;*/
}
p {
float: right;
transform: translateY(-50%);
}
article {
clear: both;
}
article:after {
content: "";
display:block;
width: 100%;
height: 1px;
background: red;
}
<article>
<header>
<h2>Lorem ipsum dolor sit amet, adipiscing blah blahh blahhhh, and long looong looooooong text content</h2>
<p>Supplementary</p>
</header>
</article>
<br>
<article>
<header>
<p>Supplementary</p>
<h2>Lorem ipsum dolor sit amet, adipiscing</h2>
</header>
</article>

Always show image regardless of desktop browser dimensions

For the below image I need to always show the whole background image regardless of the desktop window size and always ensure that the text layout remains the same, ie, the button is always sitting at the bottom of the section and not have a big blue gap below it.
*Note my image is just an example, the white rectangle is really a picture of a product but I have removed it because I cannot release such photos.
How best can I achieve this? This modern web design of maintaining the same look across different desktop browser screens is really troubling me because the methods I have used mean the design is not consistent across different browser screens, ie, the white rectangle gets clipped at the bottom or the text content height is too small for the blue section height and we get a big blue gap below it.
My techniques I have tried:
Use a bootstrap 3.3 row (the website uses this version of the library no choice in this) with 2 columns with the dimensions 3/12 and 9/12. This works but sometimes I get a big blue gap under the text content (button) when I would really like it to spread out vertically evenly.
Make the section have a CSS background image. Set the image to 'cover'. This results in clipping of the bottom of the white rectangle in certain desktop window dimensions.
Any advice on how best to approach this design using CSS3, Bootstrap 3.3 or etc.?
.blue-section {
background-color: #1caaf2;
color: #fff;
padding-top: 10px;
padding-bottom: 10px;
}
.blue-section h1,
.blue-section h2,
.blue-section h3,
.blue-section h4,
.blue-section h5,
.blue-section p {
color: #fff;
}
.blue-bk {
background: url('https://i.stack.imgur.com/Sgm8G.png') !important;
-webkit-background-size: contain !important;
-moz-background-size: contain !important;
-o-background-size: contain !important;
background-size: 100% !important;
background-repeat: no-repeat !important;
width: 100%;
}
.banner-img {
height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<section class="section-container blue-section">
<div class="container">
<div class="row">
<div class="col-xs-3">
<img class="img-responsive banner-img" src="https://i.stack.imgur.com/Sgm8G.png" />
</div>
<div class="col-xs-9 mht-db-header-information">
<h1 class=""><strong>Lorem ipsum Lorem ipsum Lorem ipsum </strong></h1>
<h3>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</h3>
<div class="text-center">
<a class="button-primary" href="">Button</a>
</div>
</div>
</div>
</div>
</section>
<section class="section-container blue-section blue-bk">
<div class="container">
<div class="row">
<div class="col-xs-3">
</div>
<div class="col-xs-9 mht-db-header-information">
<h1 class=""><strong>Lorem ipsum Lorem ipsum Lorem ipsum </strong></h1>
<h3>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</h3>
<div class="text-center">
<a class="button-primary" href="">Button</a>
</div>
</div>
</div>
</div>
</section>
All images:
White rectangle only (in production will be an image of a product):
Background image I use:

Unable to design a HTML/CSS block, can't get images to align using bootstrap

I'm trying to design the following block, given in image
The background image of building is separate from the human image, how can I use bootstrap grid system to align the images and text in this way, also keep the aspect ratio of images?
The background image is spread to 100% but the the content and human image is centered and aligned with other content
Use the building image as background for your body tag and the human image as an background for either .container or .row class.
Also the human image should be aligned right.
Something like
body {
/* image just for reference*/
background: url('http://www.eliteconcreterestoration.com/blog/wp-content/uploads/concrete-office-park-buildings.jpg');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.container {
height: 100%;
/* image just for reference*/
background: url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcS2-Dj0_UAhag-zIDaVGoV2LuCIy62nGvt_zNJoeILF1VqM3EXOdK20qR6N');
background-repeat: no-repeat;
background-position: right;
}
.jumbotron {
background: transparent !important;
}
.jumbotron h1 {
font-size: 36px;
color: white !important;
}
.jumbotron .text{
color:white;
font-size:12px;
}
<html>
<head>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="row">
<div class="jumbotron">
<h1>A good <span style="color:lightgreen;">investment</span> pays the best <span style="color:orange;">interest</span></h1>
<p class="text">lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum </p>
<p><a class="btn btn-primary btn-lg" style="background:lightgreen;" href="#" role="button">Register</a><a class="btn btn-primary btn-lg" style="background:orange;" href="#" role="button">Learn more</a>
</p>
</div>
</div>
</div>
</body>
</html>
With this design, you don't (strait forward that is) The hand part will mess up your grid layout. Or merge images, or use a smaller version of your human image that will stay inside the grid (all blocks are squares with Bootstrap, and there is NO layering beyond background image of parent element.).
* Edit As Kishore Kumar Points out, you can. Something like this:
<body> <!-- has CSS background with buildings -->
<div class="container"> <!-- has CSS background with human, float: right --> <div class="row">
<div class="col-md-3">And more stuff for layout...</div>
</div
</div>
</body>
Here is how i would do.
create a section and give it the background image with background-size: cover; property and then use a container inside the section and put my grid.
<section class="building-bg">
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- text content -->
</div>
<div class="col-md-4">
<!-- png image with some negative margins or translate property -->
</div>
</div>
</div>
</section>

Issue with text exceeding the container (bootstrap)

as you can see on this jsfiddle, if you play with the window size, the lorem ipsum text sometimes goes outside the white container.
I can't figure out why, because when I look at the code, everything seems to be embedded within the main container so I would expect the text to adapt the fluidly adapt to the window size.
What is the issue?
Thanks,
<section>
<div class="container content">
<div class="row">
<div class="col-md-3 bordering">
<h2>Qui <b>sommes-nous?</b></h2>
<h3>Actifs depuis </h3></div>
<div class="col-md-9">
<div class="title-block">
<p>
Lorem ipsum dolor sit amet, connecteur adipiscin
<p>
etc.
It is because you have applied a fixed width to .container:
.container {
width: 1260px; /* remove or edit this line */
}

Alignment not coming correcting when browser resizing - responsive page

I am using Bootstrap3 for my responsive page design here. I am adding a box inside the banner content with some text inside it as follows:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<section id="slider">
<ul class="rslides" id="modest-slider">
<li class="slider-wrapper">
<div class="slider-img-container">
<img src="http://placehold.it/350x150&text=slider1" alt="slider1" />
</div>
<div class="slider-caption container">
<div class="col-md-7" style="border-left-width: 4px; top: auto; bottom: 126px; width: 600px; background: rgba(255, 255, 255, 0.6); height:130px;">
<h1>Exclusively New Concept!</h1>
<p class="slider-description2">
Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample...
</p>
</div>
</div>
<!-- /.slider-caption -->
</li>
<!-- /.slider-wrapper -->
</ui>
</section>
It is working fine in full screen. When I am resizing the browser the alignment is not working correctly. The box with content is not fit with the page. Any help will be appreciated!!
Try the solution with minor changes
Demo http://www.bootply.com/p6wIuR17QB
/* CSS used here will be applied after bootstrap.css */
#modest-slider {
position: relative;
}
.slider-caption {
position: absolute;
bottom: 0;
margin-bottom: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<section id="slider">
<ul class="rslides list-unstyled" id="modest-slider" stye="position:relative;">
<li class="slider-wrapper">
<div class="slider-img-container">
<img src="http://placehold.it/600x300&text=slider1" alt="slider1" class="img-responsive">
</div>
<div class="slider-caption container">
<div class="col-xs-10 col-sm-8" style="background: rgba(255, 255, 255, 0.6);">
<h1>Exclusively New Concept!</h1>
<p class="slider-description2">
Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample...
</p>
</div>
</div>
<!-- /.slider-caption -->
</li>
<!-- /.slider-wrapper -->
</ul>
</section>
Try this:
<div class="row" >
<!-- changing width to 100% with 600px maximum -->
<div class="col-md-7" style="border-left-width: 4px; top: auto; bottom: 126px; width: 100%; max-width: 600px; background: rgba(255, 255, 255, 0.6); height:130px;">
<h1>Exclusively New Concept!</h1>
<p class="slider-description2">
Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample Lorem ipsum sample...
</p>
</div>
This will not make the height change though, for that try:
change "height:130px;" to "height: 100%; max-height: 130px;"
You really need to read more about how Bootstrap works though as this is not a good way to use it
First, you should not assign width to your div, in case you are using bootstrap.
<div class="col-md-7" style="...width: 600px...
Using class col-md-7 assign a particular width to your section, which is in %, so that when you resize your browser, the div resizes accordingly.
But, you overwrote the width with 600px, which is a fixed width and does not flex with browser resize.