ad

Wednesday, November 16, 2022

CSS Box property

 

CSS Box property 




Box property

All Html element can be measured as boxes. In CSS the term "box model" is used when talking about design and layout. The CSS box model is basically a box that wraps around each HTML elements it consists of margins, borders, padding and action content. The image below illustration the box model


Details of the different parts

 

Margin :

The blank area around the border of an element is called margin. It is used to create an extra space around an element. The margin is transparent.


 Border :-

 A border that goes around the padding and content. One is a visual border in a document, sometimes a solid line, dotted or dashed line, or one made up of various objects, like flowers, baseballs, animals, or virtually any other object.  


Padding :-

 It is used to generate space around an element's content, inside of any defined borders. The padding is transparent, An element's padding is the space between its content and its border. The padding property is a shorthand property for padding-top. padding-right. padding-bottom.


Content :-

 The contents of box, where text and images appear. The content attribute gives the value associated with the http-equiv or name attribute.

box model allows us to attach a border around elements and to classify space between elements. 


CSS Box property

 Example 

<!DOCTYPE html>

 <html>

<head>

<style>

 div {

 background-color: lightblue:

width: 400px;

 border: 20px solid yellow;

 padding: 50px;

 margin: 50px;

 text-align: justify;

}

 </style>

</head> 

 <body>

 <h2> Welcome Toalaji Publication</h2> 17 <p> Here we see the demonstration of Box Model.</p>

<div>This text is written in the box or you can say that it is the text content of the box. The width of the box is 400px and the ineternal color is lightblue. We have added a 50px padding, 50px margin and a 20px yellow border.</div>

</body>

</html>


CSS Box property 

output 


CSS Box property

overflow: scroll

The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area.

overflow: scroll 

Example 

<!DOCTYPE html>

<html>

<head>

<style>

div.ex1 {

background-color: purple;

width: 200px;

height: 70px;

overflow: scroll;

border: 5px solid black;

}

</style>

</head>

<body>

<h2>overflow: scroll:</h2>

<div class="ex1">

It Indicates that the content is clipped but scroll-bar is added to see the rest of the content.It Indicates that the content is clipped but scroll-bar is added to see the rest of the content.</div>

</body>

</html>


overflow: scroll 

output 


overflow: scroll

overflow: hidden

The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area

overflow: hidden Example 

<!DOCTYPE html>

<html>

<head>

 <style>

div.ex2 {

background-color: yellow;

 width: 110px; 

height: 70px; 

overflow: hidden;

}

</style></head><body>

 <h2>overflow: hidden </h2> 

<div class="ex2">It Indicates that the content is clipped and that no scrolling mechanism should be provided to view the content outside the clipping region. </div>

</body>

</html>


overflow: hidden 

output 

overflow: hidden



overflow:auto

The auto value is similar to scroll , but it adds scrollbars only when necessary: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.

overflow:auto 

Example 

<html>
<head>
<style>
div.ex3 {
background-color: lightblue; 
width: 110px;
 height: 70px; 
}
</style></head>
<body>
<h2>overflow:auto </h2> 

<div class="ex2">It Indicates that the content is clipped and that no scrolling mechanism should be provided to view the content outside the clipping region. </div>
</body>
</html>



overflow:auto 

output 

overflow:auto



Overflow: visible (default)

By default, the overflow is visible , meaning that it is not clipped and it renders outside the element's box: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.
 

Overflow: visible 

Example 

</html>
<head>
<Style>
 div.ex4 {
background-color: lightblue;
 width: 110px;
height: 70px; 
 border: 5px dotted black;
}
 </style>
</head>
<body>
<h2>overflow: visible</h2>
<div class="ex4">It Indicates that the content is clipped and that no scrolling mechanism should be provided to view the content outside the clipping region. </div>

</body>

</html>

 

Overflow: visible 

 Output

Overflow: visible


Related post 

background image html table

design web page use html css

html table program

Tuesday, November 15, 2022

Css inline block

    inline block





1.display:inline-block

display:inline-block the top and bottom margins/paddings are respected, but wit display: inline they are not.Compared to display: block, the major difference is that display: inline-block does not add a line 14 <mead> break after the element, so the element can sit next to other elements.

Display inline - block

 Example 

 <!DOCTYPE html>

 <html>

 <head> 

 <style>

 nav {

 background-color: lightblue

list-style-type: none;

  text-align: center;

 margin: 0; 

padding: 0; 

}

.nav li {

 display: inline-block;

 font-size: 30px; 

padding: 30px;

Margin:20px;

}

 </style>

</head>

 <body>

 <h1>display: inline-block</h1>

 <ul class="nav">

 <li><a href="#home">Home</a></li>

<li><a href="#about">Projects</a></li> 

 <li><a href="#clients">Clients</a></li> 

<li><a href="#contact">Contact</a></li>

 </ul>

</body>

 </html>

display:inline-block

 output

 

Inline block




Sunday, November 13, 2022

CSS Background propertie


 CSS Background propertie



1. Properties

The CSS background properties  use to define the background effect for element. To shorten  code, it  also possible to specify all the background properties in one single property. This is called a shorthand property.

Syntax:

 background Properties :- 

 bg-color and bg-image position/bg-size, bg-repeat, bg-origin bg-clip or bg-attachment initial | inherit;


1) Background  :-   Sets all the background properties in one declaration.

background-colorbackground- image, background-repeat, background-attachment, background-position


2) background- attachment :- Sets whether a background image is fixed or scrolls with the rest of the page. 

scroll, fixed


3) background- color :- The background-color property  specifies the background color of element.

color-rgb, color-hex, color- name, transparent


4) background- image :- 

Sets the background image for the html element. put url(URL) 

5) background- position :-

 Sets the starting position on the background image.

top left, top center, top right, center left, center center, center bottom left, bottom center, bottom right, x% y%, xpos ypos

6) background- repeat :-

    Set  background image will be repeat. the repeat-x, repeat-y, no- repeat

Saturday, November 12, 2022

CSS in combinators

 

  combinators in CSS 



1. Descendant selector  

Descendant selector (space) matches all the elements that are descendants of a specified elements, it means that selectors can select element that are descendants of others selector. The element does not have  be  direct child, but rather  descendant down the line.


Syntax:

element1 element2

{

style_properties

}


Descendant selector

 Example 

<!DOCTYPE html>

<html>

<head>

<style>

 ol li { 

color: red;

 } 

 </style>

</head>

 <body>

<ol>

<li>Databases</li> <br>

<ul>

<li>Oracle/PLSQL</li> 

<li>SQL</li>

</ul>

<li>ASP.Net</li>

<li>Java</li>

</ol> </ul>

 </body>

 </html>

Friday, November 11, 2022

Type of CSS Selectors

 Types of CSS selectors


 Type 

1. Universal Selector 

 2. ID Selector 

3. Tag Selector

4. Class Selector 

 5.Attribute Selector


1. Universal Selector 

The universal selector, written as is star symbol matches every single element the page. It is used for selecting all elements on a page. The universal selector omitted if other conditions exist on the target element. This selector is often use to remove the default margins and padding from the element for quick testing purpose.

Syntax:

*{

style properties

}

Universal Selector 

Example 

<!DOCTYPE html>

 <html> 

<head>

 <style>

*{

 color: green; 

font-size: 20px;

}

</style>

</head> 

<body>

 <h2> Universal Selector</h2>

 <p> This style is the applied on every paragraph.</p> 

 <p id="para1">Second Paragraph</p>

 <p>and Third Paragraph</p>

 </body> 

</html>

Universal Selector 

output 

Universal Selector tag use


2. ID selector 

This selector is use to select the id attribute of an HTML, element  selecting the specific element And id is always unique within page so it is chosen to select single, unique element. To select element with a specific id, write a hash character, follow by the id of the element

What special about ID styles is that  should be use only once per page. ID selector are great for creating page layout where you want to define each section of  page only once. they are ideal for creating  CSS layout.


ID selector 

Example 

<!DOCTYPE html>

<html>

<head>

<style>

#id1{

color: red;

text-align: center;

}

</style>

</head>

<body>

<p id="id1">ID Selector</p>

<p>This paragraph is not Affected.</p>  

<p> id="id1">This paragraph is Affected.</p>

</body>

</html>

ID selector

 output 


ID selector tag




3. Tag Selector


The selector tag is use to redefine existing HTML tags. Select this option if you want to change the formatting options for an HTML tag, such as the <h1> (heading 1) tag or the <ul> (unordered list) tag. In many cases is  redefining existing HTML tag with CSS has advantages over creating new styles.


Tag Selector 

Example 

<!DOCTYPE html>

<html>

<head>

<style>

P{

text-align: center;

color: red;

}

h1{

color:blue;

text-align:center;

}

</style>

</head>

<body>

<h1> Tag Selector</h1>

<p>Every paragraph will affect by the style.</p>

<p>Welcome</p> 

<h1> Every Heading Element<br> will be affected  </h1>

</body>

</html>

Tag Selector 

output 


Tag attributes use html



4. Class Selector 


It is used to define any HTML element which has the class attribute's. The element having that class will be formatted / style according to the given rule. It can be defined by using "" (full stop) symbol along with the class name.

Syntax:

class_name

{

style properties

}

Class Selector

 Example 

<!DOCTYPE html>

<html>

<head>

<title>Class Selector</title>

 <style type="text/css">

P.abc {

color:red;

text-align: center;

}

</style>

</head>

<body>

<h1 class="abc">This is Heading </h1> <p class="abc">First Paragraph</p>

<p class="abc">Second Paragraph</p>

</body> 

</html>

Class Selector

 output 



Class Selector

class selector is selects elements with  specific class attribute. To select element with a specific class, write a period (.) character, follow by the name of the class. You can also specify that only specific HTML element should be affect by a class.

Class Selector 

Example 

<!DOCTYPE html>

<html>

<head>

<style>

.intro {

  background-color: yellow;

}

</style>

</head>

<body>

<h1> class selector</h1>

<div class="intro">

<p>My name is Donald.</p>

  <p>I live in Americap.</p>

</div>

<p>My best friend is Mickey.</p>

<p class="intro">My best friend is Mickey.</p>

</body>

</html>


Class Selector

 output 

Class Selector tag use

5. Attribute Selectors

HTML element could be styled based on the presence  an attribute use the Attribute selector.  example below declaration add border to any element with disabled attribute.


Attribute Selectors

 Example 

<!DOCTYPE html>

<html>

<head>

<style>

a{

  background-color: yellow;

}

</style>

</head>

<body>

<h2>CSS attribute Selector</h2>

<p>This links with  target attribute gets a yellow background:</p>

<a href="https://www.w3schools.com">w3schools.com</a>

<a href="http://www.google.com" target="_blank">Google.com</a>

<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>

</body>

</html>

Attribute Selectors

 output 


Attribute Selectors Tag

Related Post:-

html paragraph tag

html form