Why does the direction property not work on block level elements - html

I want the hover functionality of the nav bar to extend the full height of the header parent element.
I believe this is currently not doing this because the anchor tag is an inline element. If I add display: inline-block to the CSS for the header .nav a selector, this works as I want it to BUT then does not honour the direction property I set in the header .nav selector and reverses the order of the elements.
Can anyone tell me why this would be?
I have researched this and on the MDN site for the direction CSS property it says
For the direction property to have any effect on inline-level
elements, the unicode-bidi property's value must be embed or override.
if i add the unicode-bidi CSS property:
with the embed value, nothing happens
with the bidi-override value, the words are reversed in place.
Thanks for your patience, I am a noob at all this.
* {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
header {
height: 7vh;
width: 100vw;
background-color: #D1C4E9;
line-height: 7vh;
}
header .nav {
margin-right: 3vw;
direction: rtl;
}
header .nav a {
//display: inline-block;
font-size: 1.25em;
padding: 0 2vw;
text-decoration: none;
color: #6A1B9A;
}
header .nav a:hover {
background-color: #6A1B9A;
color: #D1C4E9;
}
<header>
<div class='nav'>
<a href='#'>Home</a>
<a href='#'>Products</a>
<a href='#'>Services</a>
<a href='#'>About</a>
</div>
</header>

then does not honour the direction property I set in the header .nav selector and reverses the order of the elements.
This is the intended result when changing the direction and having inline-block elements. The order will get switched.
The behavior with text is not exactly the same and here the unicode-bidi play it roles. Basically when a browser will change the direction, it will not break down the text and change the order of each character. this will be done only if you change unicode-bidi
normal
The element does not open an additional level of embedding with respect to the bidirectional algorithm. For inline elements, implicit1 reordering works across element boundaries.
bidi-override
This means that inside the element, reordering is strictly in sequence according to the 'direction' property; the implicit1 part of the bidirectional algorithm is ignored.
Here is an example to better understand and to see the difference when having extra wrapper:
span {
border:1px solid;
}
div {
margin-top:10px;
}
<div style="direction:rtl;">lorem ipsum text</div>
<div style="direction:rtl;">lorem <span>ipsum text</span></div>
<div style="direction:rtl;">lorem <span style="display:inline-block">ipsum text</span></div>
<div style="direction:rtl;unicode-bidi:bidi-override">lorem ipsum text</div>
<div style="direction:rtl;unicode-bidi:bidi-override">lorem <span>ipsum text</span></div>
<div style="direction:rtl;unicode-bidi:bidi-override">lorem <span style="display:inline-block">ipsum text</span></div>
1The algorithm consists of an implicit part based on character properties, as well as explicit controls for embeddings and overrides. CSS 2.1 relies on this algorithm to achieve proper bidirectional rendering. The 'direction' and 'unicode-bidi' properties allow authors to specify how the elements and attributes of a document language map to this algorithm.
Reference: https://www.w3.org/TR/CSS2/visuren.html#direction
All the above is a bit complicated and the use of direction is not the way to go. You can either consider text-align with inline-block:
* {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
header {
height: 7vh;
width: 100vw;
background-color: #D1C4E9;
line-height: 7vh;
}
header .nav {
margin-right: 3vw;
text-align:right;
}
header .nav a {
display: inline-block;
font-size: 1.25em;
padding: 0 2vw;
text-decoration: none;
color: #6A1B9A;
}
header .nav a:hover {
background-color: #6A1B9A;
color: #D1C4E9;
}
<header>
<div class='nav'>
<a href='#'>Home</a>
<a href='#'>Products</a>
<a href='#'>Services</a>
<a href='#'>About</a>
</div>
</header>
Or use flexbox to easily control alignment:
* {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
header {
height: 7vh;
width: 100vw;
background-color: #D1C4E9;
line-height: 7vh;
}
header .nav {
margin-right: 3vw;
text-align:right;
display:flex;
justify-content:flex-end;
}
header .nav a {
font-size: 1.25em;
padding: 0 2vw;
text-decoration: none;
color: #6A1B9A;
}
header .nav a:hover {
background-color: #6A1B9A;
color: #D1C4E9;
}
<header>
<div class='nav'>
<a href='#'>Home</a>
<a href='#'>Products</a>
<a href='#'>Services</a>
<a href='#'>About</a>
</div>
</header>

Related

Why setting div class font-size doesn't set the p element font size?

Here is my html file. I want to change the font size of all p element in the div. So I change the font size of the div containing all paragraphs but it doesn't work. Why?
<div class="footersection__left--address">
<p>2</p>
<p>Melano Park,</p>
<p>CA</p>
<p>USA</p>
</div>
Here is my SCSS file-
.footersection {
background-color: #FFF;
padding: 6rem;
&__left{
font-size: 1.5rem;
&--address{
font-size: 5rem;
color: aqua;
}
}
}
The CSS generated from this SCSS:
.footersection {
background-color: #FFF;
padding: 6rem;
&__left{
font-size: 1.5rem;
&--address{
font-size: 5rem;
color: aqua;
}
}
}
Is this CSS:
.footersection {
background-color: #FFF;
padding: 6rem;
}
.footersection__left {
font-size: 1.5rem;
}
.footersection__left--address {
font-size: 5rem;
color: aqua;
}
As you can see the p take the font size of the last selector .footersection__left--address.
Look at this CodePen.
As pointed out by #Ale_info, your compiled CSS means that your p tags will inherit font-size: 5rem from .footersection__left--address. Or you have something else in your stylesheets setting the font-size on all p tags.
I also wanted to take the opportunity to tell you that you're using BEM wrong.
-- defines a Modifier class, which should modify an existing Element class, thus should be appended to it. You're using a modifier on its own without the actual base styles for the element.
This is bad BEM:
<div class="footersection">
<div class="footersection__left--address"></div>
</div>
This is good BEM:
<div class="footersection">
<div class="footersection__left footersection__left--address"></div>
</div>

How to Fill in Blank Spaces When Padding Does Not Work

I'm trying to figure out why I can't fill this spot, despite trying many things I have been unable to figure out how to fix it. I tried padding the top, but to no avail. I have provided the code below as well as a picture of the space I'm talking about. In the picture there's a white space between the header 2 and the gray area that has a brief summary. I have tried padding and also increasing the height of the background color, but it doesn't seem to work. Thank you in advance for reading this and I really do thank you for taking the time to help me figure this out.
$(document).ready(function()){
$("figure img + figcaption").prev().addClass('hasCaption');
});
.body{
margin: 0px;
}
.homeButton{
width: 40px;
}
#MidPort{
background-image: url("http://www.geocities.ws/spahealthcare/pic/dark-green-home-button.png");
background-size:cover;
position:absolute;
margin-left:1565px;
bottom:10px;
}
.topnav{
font-size: 20px;
font-family: Times New Roman;
position:fixed;
top 0;
width:100%;
}
#bg2{
background-color:red;
}
ul{
list-style-type:none;
margin:0;
padding:0;
overflow: hidden;
background-color: #333
}
li{
float:left;
border-right:1px solid #bbb;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: red;
}
.active{
background-color:#4CAF50;
}
li a:hover:not(.active)
{
background-color: #111;
}
li:last-child{
border-right:none;
}
#margintop1{
margin-top: .5cm;
font-family: Gadget;
}
.jumbotron{
height:175px;
background-color:#808080;
}
hr.style17 {
border-top: 1px solid #8c8b8b;
text-align: center;
}
hr.style17:after {
content: 'ยง';
display: inline-block;
position: relative;
top: -14px;
padding: 0 10px;
background: #f0f0f0;
color: #8c8b8b;
font-size: 18px;
-webkit-transform: rotate(60deg);
-moz-transform: rotate(60deg);
transform: rotate(60deg);
}
img.hasCaption {
padding-bottom: 50px;
}
figcaption {
position: absolute;
left: 14px;
right: 14px;
bottom: 16px;
background-color: white;
text-align: center;
color: blue;
font-family: 'Reenie Beanie', cursive;
font-size: 30px;
padding: 10px;
}
figure {
display: inline-block;
position: relative;
left: 0;
-moz-transform:rotate(-5deg);
-webkit-transform:rotate(-5deg);
-ms-transform:rotate(-5deg);
transform:rotate(-5deg);
}
img {
border-color: white;
border-width: 15px;
-moz-border-image: url(http://tobias-reinhardt.de/img/frame.png) 15 stretch;
border-image: url(http://tobias-reinhardt.de/img/frame.png) 15 stretch;
border-style: solid;
margin: auto;
}
#imgR{
margin-left:1285px;
height:400px;
}
font{
font-family:Gadget;
}
section{
background-color:#00FFFF;
margin-bottom:10cm;
font-family:Gadget;
}
}
<!-- Check to see if the navigation bar remains at the bottom if I use the nav class instead of ul. If not, revert back to ul for when the user scrolls down-->
<div>
<header>
<!--<div class="container">-->
<h2 class="topnav" id="cs2">
<ul>
<li><a class="active" href="/home">Home</a></li>
<li>About Me</li>
<li>Contact</li>
<li id="MidPort"></li>
</ul>
</h2>
</header>
</div>
<body>
<div class="intro-text">
<div class="jumbotron">
<div>
<p id="margintop1"style="margin-right:200px;">
<font color="white">Front-End Developer and Economist, with experience in project management, machine learning, and leadership roles; devoted to functional programming and analyzing mathematical models to solve emerging economic problems
</font>
</p>
<hr class="style17"/>
</div>
<figure>
<img src="http://i.maniadb.com/images/artist/116/116122.jpg" id="imgR">
</figure>
</div>
</div>
<div id="midSec">
<section>
<h2>
<center>
<font color="#2F4F4F" size="20">
Portfolio
</font>
</center>
</h2>
</section>
</div>
</body>
<!--setup a home button at the bottom-->
[![Space is in between Portfolio and the brief summary][1]][1]
You're using an h2 in your code that has a margin.
h2{margin: 0;}
This will fix it.
h2{margin-top:0}
will fix the issue
h2 by default has a margin top . Remove that.
Also, your HTML is not correct . ( that's why i post this as an answer, to explain to the op the problems from his html )
The biggest problem is that you nested ul inside h2 . This practice is not valid.
As stated in the doc
Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content.
Heading tags like h1,h2 etc. are pharsing content, ul is a flow content . So you cannot put ul inside h2
You can check your HTML here > HTML validator and check docs here > documentation
Second problem is that you write <li>About Me</li>
So you first open li, then a but you close first the li and then the a. You need to close the a before closing the li. a being a child of li . Correct form :
<li>About Me</li>
Another problem is using tags that are no longer supported in HTML5 . font,center . ( also the use of size is not supported either) You either use inline styles for example <h2 style="font-size:10px;text-align:center"> or you can use CSS styles separately .
These are just the problems i see from a first look over your code

Align The text as center in menu bar

I'm facing this issue in a menu bar.
I need to align the text with the center of the icon.
Code:
<table id="cssTable">
<thead>
<tr>
<th>
<i style=" text-align: center;vertical-align: middle;" class="icon s20 {{node.icon}}" ng-if="node.icon"></i>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span style=" text-align: center;vertical-align: middle;" class="title" translate="{{node.translate}}" flex>{{node.title}}</span>
</td>
</tr>
</tbody>
</table>
But it's not working. How do I use css to style the center the text.
To fix the issue at hand, remove the text-align: center from the span and instead add it to the parent elements, th and td.
However, your code is showing some other issues that I'd like to point out.
Why the table?
You are using a table for your menu. Unless you have a very specific, pressing reason to do so, you should not do this. The reason is that HTML is all about semantics, and it is not very semantic to make a menu a table - it simply isn't tabular data. The common practice is to use an unordered list (ul) instead.
Why the inline-styles?
There are three ways to apply CSS:
External stylesheet using <link>
<style></style> section within your <head>
Inline-styles (that's what you are using)
Now, inline-styles will override rules from external stylesheets or the style element. They also violate the idea of separating content and presentation. They are therefore considered bad practice, unless you have a specific reason to use them.
Putting it all together
I therefore suggest the following:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul {
list-style: none;
width: 108px;
}
li {
color: #fff;
text-align: center;
background-color: #2d323e;
background-repeat: no-repeat;
background-position: center 20%;
}
li.customers,
li.user {
background-image: url(http://via.placeholder.com/20x20);
}
li a {
display: block;
width: 100%;
height: 94px;
padding-top: 60%;
color: inherit;
text-decoration: none;
font-family: sans-serif;
font-size: 9pt;
font-weight: bold;
}
<ul>
<li class="customers">Customers</li>
<li class="user">User</li>
</ul>
it's because you're adding text-align to the span property, and I can understand why you would try to add it to the span. But text-align is best used on the parent element, to essentially align the children elements.
You would do something like this (not meant to be anything like your code, just an example of how-to-use):
html:
<div id="myDiv">
<img src="img1.png" class="img" />
<p>My Text</p>
</div>
css:
#myDiv {text-align: center;}
not whenever a div with an id of myDiv is loaded it will center-align all child elements inside the div.
In your case, you need to add it to the table <td>/<th> that holds the text you wish to align. E.g.
td, th {text-align: center}
As an alternative, using flexbox and absolute positioning of the icon.
ul {
list-style: none;
width: 5em;
margin: 0;
padding: 0;
display: flex;
}
li {
position: relative;
text-align: center;
padding-top: 1.5em;
min-width: 5em;
background-color: blue;
color: white;
cursor: pointer;
}
li:not(:first-child) {
margin-left: .1em;
}
li:hover {
background-color: lightblue;
}
li:before {
font-family: FontAwesome;
position: absolute;
width: 1em;
top: 0.3em;
left: calc(50% - .5em);
}
.customers:before {
content: "\f0c0";
}
.user:before {
content: "\f2c0";
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<ul>
<li class="customers">Customers</li>
<li class="user">User</li>
</ul>
You need to add text-align:center to the th and td
<th style="text-align: center;"></th>
<td style="text-align: center;"></td>

CSS - items not staying inline within div

I'm trying to get 2 items to display inline-block within a div but nothing I've tried is working.
The html I've used is
<div class="quotation">
<ul>
<li><img src="images/quotes.png" alt="" class="quotemarks"></li>
<li><p class="words">All honour to the Enderbies, therefore, whose house, I think, exists to the present day; though doubtless the original Samuel must long ago have slipped his cable for the great South Sea of the other world.</p></li>
</ul>
</div>
Whilst my CSS at the moment is as follows:
.quotation {
position: absolute;
margin: 20% 5% 10% 5%;
width: 88.2%;
max-height: 100px;
padding: 0.5%;
background-color: red;
color: #bdc3c7;
}
.quotation ul li {
position: relative;
display: inline-block;
text-decoration: none;
font-family: 'PT Sans', sans-serif;
font-weight: 100;
}
.quotemarks {
max-width: 20%;
}
.words {
width: 60%;
}
I cannot understand why .quotemarks and .words won't a) stay within .quotation and b) won't render inline.
You have quite some things wrong in your code and understanding of how css layout works.
You tell your list items to be display: inline-block. This tells them to be just as wide as their content.
You tell the content of your list items - the img and the paragraph - to have their width based on % - which refers to % of the width of the parent element - which happens to be the list item.
So basically the list item asks its content "How wide am I needed to be?" - while the content asks the parent list item "How wide are you? I'll be xy % of that."
It's easy to see that each element needs an answer before it can give one, creating an infinite loop of unanswered questions.
Apart from that, as soon as there is any whitespace (even a linebreak only) between two or more inline-block elements whose summed up width is 100% will make (at least) the last element wrap to a new line.
How to solve the inline-block whitespace issue: Either make your list-items float: left; (which has its own pitfalls!) or set font-size: 0; on the parent element (in this case the ul) , and re-set it on children as needed.
Also, put the width-controlling classes on the list items.
.quotation {
position: absolute;
margin: 20% 5% 10% 5%;
width: 88.2%;
max-height: 100px;
padding: 0.5%;
background-color: red;
color: #bdc3c7;
}
.quotation ul {
/*set this to avoid linebreak due to whitespace */
font-size: 0;
}
.quotation ul li {
display: inline-block;
text-decoration: none;
font-family: 'PT Sans', sans-serif;
/* re-set font-size here to what you need */
font-size: 14px;
font-weight: 100;
vertical-align: text-top;
}
.quotemarks {
max-width: 20%;
}
.words {
width: 60%;
}
.quotemarks img {
max-width: 100%;
}
<div class="quotation">
<ul>
<li class="quotemarks">
<img src="http://placekitten.com/g/200/300" alt="" />
</li>
<li class="words">
<p>All honour to the Enderbies, therefore, whose house, I think, exists to the present day; though doubtless the original Samuel must long ago have slipped his cable for the great South Sea of the other world.</p>
</li>
</ul>
</div>
Move your classes .quotemark and words to parent elements
<div class="quotation">
<ul>
<li class="quotemarks"><img src="images/quotes.png" alt=""></li>
<li class="words"><p>All honour to the Enderbies, therefore, whose house, I think, exists to the present day; though doubtless the original Samuel must long ago have slipped his cable for the great South Sea of the other world.</p></li>
</ul>
</div>
Make sure that you added necessary vertical-align rule (top, middle or bottom... ) to your list items.
Check out demo
I hope this will help.
Thanks guys, your solutions worked and, whilst my CSS is still ugly as sin, everything fits in the box and I was able to change the size of the quotemarks too.
<div class="quotation">
<ul>
<li class="quotemarks"><img src="images/quotes.png" alt=""></li>
<li class="words"><p>All honour to the Enderbies, therefore, whose house, I think, exists to the present day</p></li>
</div>
And the CSS
.quotation {
position: absolute;
margin: 20% 5% 200px 5%;
width: 88.2%;
max-height: 100px;
padding: 0.5%;
background-color: #f5f5f5;
color: #bdc3c7;
}
.quotation ul li {
position: relative;
display: inline-block;
text-decoration: none;
font-family: 'PT Sans', sans-serif;
font-weight: 100;
vertical-align: middle;
}
.quotemarks {
max-width: 20%;
margin: 0 10px 0 0;
}
.quotemarks img {
height: 40px;
}
.words {
width: 80%;
line-height: 15px;
font-size: 20px;
}

Button display inline CSS

I have the following CSS and HTML: http://jsfiddle.net/47w0h73r/6/
.one {
padding: 20px;
background: #f00;
}
.two {
padding: 20px;
background: #00f;
}
a,
button {
font-family: Arial, Helvetica;
font-size: 16px;
padding: 10px;
background: #fff;
color: #000;
display: inline;
border: 0;
text-decoration: none;
}
<div class="one"></div>
<div class="two">
Link
<button>Button</button>
</div>
As you will notice, the button doesn't appear as inline. Why is this? How can I make this button inline, just like its sibling a?
Issue
By changing the button to an a you will notice that the display: inline makes the padding of the parent element to ignore the padding of both child elements, making them really display inline. The problem, is that the button tag doesn't really appear inline, which makes the parent element's padding push both elements down. How can I fix this?
Trying to set a button to display:inline seems to cause some confusion. The inability to get display:inline behaviour is often attributed to it being a replaced element, but that is incorrect. <button> is not a replaced element.
In fact, the HTML5 specification, Section 10.5.2 The button element makes this requirement:
When the button binding applies to a button element, the element is
expected to render as an 'inline-block' box rendered as a button whose
contents are the contents of the element.
The language is a little unusual, but the button binding does apply, and the effect is that the binding takes precedence over the specified value of the display property. The effect is that the button is always rendered as display:inline-block, no matter what its specified value is. There is nothing you can do about it.
Add line-height:17px; to a, button and that should make them the same:
.one {
padding: 20px;
background: #f00;
}
.two {
padding: 20px;
background: #00f;
}
a,
button {
font-family: Arial, Helvetica;
font-size: 16px;
padding: 10px;
background: #fff;
color: #000;
display: inline;
border: 0;
text-decoration: none;
line-height: 17px;
}
<div class="one"></div>
<div class="two">
Link
<button>Button</button>
</div>