SlideShare a Scribd company logo
1 of 31
|| Jai Sri Gurudev||
Sri Adichunchanagiri Shikshana Trust (R)
SJB INSTITUTE OF TECHNOLOGY
(Affiliated to Visvesvaraya Technological University, Belagavi& Approved by AICTE, New Delhi.)
No. 67, BGS Health & Education City, Dr. Vishnuvardhan Road Kengeri, Bengaluru – 560 060
Subject: Web Technology and Its Applications(18CS63)
By
CHETAN R, Assistant Professor
Semester / Section: 6B
Department of Information Science & Engineering
Aca. Year: EVEN SEM /2020-21
1
FLOATING ELEMENTS
Dept. of ISE, SJBIT
2
5/24/2023 Dept. of ISE, SJBIT 3
Floating Elements
 <!DOCTYPE html>
 <html>
 <head>
 <style>
 div {
 float: left;
 padding: 15px;
 }
 .div1 {
 background: pink;
 }
 .div2 {
 background: yellow;
5/24/2023 Dept. of ISE, SJBIT 4
Floating Elements
 }
 .div3 {
 background: green;
 }
 </style>
 </head>
 <body>
 <h2>Float Next To Each Other</h2>
 <p>In this example, the three divs will float next to each other.</p>
 <div class="div1">Div 1</div>
 <div class="div2">Div 2</div>
 <div class="div3">Div 3</div>
 </body>
 </html>
5/24/2023 Dept. of ISE, SJBIT 5
Floating Elements
 Float Next To Each Other
 In this example, the three divs will float next to each
other.
 Div 1
 Div 2
 Div 3
5/24/2023 Dept. of ISE, SJBIT 6
The CSS float property (reference)
6
img.headericon {
float: right; width: 130px;
} CSS
 removed from normal document flow; underlying text
wraps around as necessary
Ghostbusters is a 1984 American science fiction comedy
film written by co-stars Dan Aykroyd and Harold Ramis
about three eccentric New York City
parapsychologists-turned-ghost capturers.
output
property description
float
side to hover on; can be left, right, or none
(default)
5/24/2023 Dept. of ISE, SJBIT 7
5/24/2023 Dept. of ISE, SJBIT 7
Floating elements diagram
7
5/24/2023 Dept. of ISE, SJBIT 8
Common float bug: missing width
 often floating block elements must have a width
property value
 Let’s try “floating”
8
5/24/2023 Dept. of ISE, SJBIT 9
The clear property
CS380
9 p { background-color: fuchsia; }
h2 { clear: right; background-color: yellow; }
CSS
output
Super Mario Fan Site!
Mario is a fictional character in his video game series.
Serving as Nintendo's mascot and the main protagonist of
the series, Mario has appeared in over 200 video games
since his creation
5/24/2023 Dept. of ISE, SJBIT 10
The clear property (cont.)
property description
clear
disallows floating elements from
overlapping this element;
can be left, right, or none (default)
10
5/24/2023 Dept. of ISE, SJBIT 11
5/24/2023 Dept. of ISE, SJBIT 11
Clear diagram
11
div#sidebar { float: right; }
p { clear: right; } CSS
5/24/2023 Dept. of ISE, SJBIT 12
Common error: container too
short
12
<p><img src="images/mario.png" alt=“super mario" />
Mario is a fictional character in his video game
series.....</p> HTML
Mario is a fictional character in his video game series.
Serving as Nintendo's mascot and the main protagonist
of the series, Mario has appeared in over 200 video
games since his creation.
p { border: 2px dashed black; }
img { float: right; } CSS
5/24/2023 Dept. of ISE, SJBIT 13
The overflow property
Mario is a fictional character in his video game series.
Serving as Nintendo's mascot and the main protagonist
of the series, Mario has appeared in over 200 video
games since his creation.
output
p { border: 2px dashed black;
overflow: hidden; } CSS
CS380
5/24/2023 Dept. of ISE, SJBIT 14
The overflow property (cont.)
14
property description
overflow
specifies what to do if an element's
content is too large;
can be auto, visible, hidden, or scroll
5/24/2023 Dept. of ISE, SJBIT 15
Multi-column layouts
15
<div>
<p>first paragraph</p>
<p>second paragraph</p>
<p>third paragraph</p>
Some other text that is important
</div> HTML
Some other text that is important
output
p { float: right; width: 25%; margin: 0.5em;
border: 2px solid black; }
div { border: 3px dotted green; overflow: hidden; }
CSS
second paragraph first paragraph
third paragraph
Sizing and Positioning
16
5/24/2023 Dept. of ISE, SJBIT 17
The position property (examples)
17
div#ad {
position: fixed;
right: 10%;
top: 45%;
} CSS
property value description
position
static default position
relative
offset from its normal static
position
absolute
a fixed position within its
containing element
fixed
a fixed position within the
browser window
top, bottom,
left, right
positions of box's corners
5/24/2023 Dept. of ISE, SJBIT 18
Absolute positioning
18
#sidebar {
position: absolute;
left: 400px;
top: 50px;
} CSS
 removed from normal flow
 positioned relative to the block
element containing them
 actual position determined by
top, bottom, left, right
 should often specify a width
property as well
CS380
5/24/2023 Dept. of ISE, SJBIT 19
Relative positioning
19
#area2 { position: relative; }
CSS
 absolute-positioned elements are
normally positioned at an offset
from the corner of the overall web
page
 to make the absolute element to
position itself relative to some other
element's corner, wrap the absolute
element in an element whose position
is relative
CS380
5/24/2023 Dept. of ISE, SJBIT 20
Fixed positioning
20
#area2 { position: relative; }
CSS
 removed from normal flow
 positioned relative to the browser
window even when the user scrolls
the window, element will remain in
the same place
CS380
5/24/2023 Dept. of ISE, SJBIT 21
Alignment vs. float vs. position
1. If possible, lay out an element by aligning its content
 horizontal alignment: text-align
 set this on a block element; it aligns the content within it (not the
block element itself)
 vertical alignment: vertical-align
 set this on an inline element, and it aligns it vertically within its
containing element
2. If alignment won't work, try floating the element
3. If floating won't work, try positioning the element
 absolute/fixed positioning are a last resort and should not
be overused
21
5/24/2023 Dept. of ISE, SJBIT 22
Details about inline boxes
 Size properties (width, height, min-
width, etc.) are ignored for inline boxes
 margin-top and margin-bottom are
ignored,
 but margin-left and margin-right are
not ignored
CS380
22
5/24/2023 Dept. of ISE, SJBIT 23
Details about inline boxes
 the containing block box's text-align
property controls horizontal position of inline
boxes within it
 text-align does not align block boxes within the
page
 each inline box's vertical-align property
aligns it vertically within its block box
CS380
23
5/24/2023 Dept. of ISE, SJBIT 24
The vertical-align property
property description
vertical-align
specifies where an inline element should be
aligned vertically, with respect to other
content on the same line within its block
element's box
CS380
24
 can be top, middle, bottom, baseline (default),
sub,
super, text-top, text-bottom, or a length value or
%
 baseline means aligned with bottom of non-hanging
5/24/2023 Dept. of ISE, SJBIT 25
vertical-align example
25
<p style="background-color: yellow;">
<span style="vertical-align: top; border: 1px solid
red;">
Don't be sad! Turn that frown
<img src="images/sad.jpg" alt="sad" /> upside down!
<img style="vertical-align: bottom“
src="images/smiley.jpg" alt="smile" />
Smiling burns calories, you know.
<img style="vertical-align: middle"
src="images/puppy.jpg" alt="puppy" /> Anyway, look at this
cute puppy; isn't he adorable! So cheer up, and have a
nice day. The End.
</span>
</p> HTML
CS380
5/24/2023 Dept. of ISE, SJBIT 26
vertical-align example (cont.)
CS380
5/24/2023 Dept. of ISE, SJBIT 27
Common bug: space under
image
27
<p style="background-color: red; padding: 0px; margin:
0px">
<img src="images/smiley.png" alt="smile" />
</p> HTML
 red space under the image, despite padding and margin of 0
 this is because the image is vertically aligned to the baseline of the paragraph (not
the same as the bottom)
 setting vertical-align to bottom fixes the problem (so does setting line-height to 0px)
5/24/2023 Dept. of ISE, SJBIT 28
The display property
28
h2 { display: inline; background-color: yellow; }
CSS
 values: none, inline, block, run-in, compact, ...
 use sparingly, because it can radically alter the page layout
output
property description
display
sets the type of CSS box model an
element is displayed with
5/24/2023 Dept. of ISE, SJBIT 29
The display property (cont.)
29
p.secret {
visibility: hidden;
} CSS
 hidden elements will still take up space onscreen, but
will not be shown
 to make it not take up any space, set display to none instead
 can be used to show/hide dynamic HTML content on the
page in response to events
output
CS380
5/24/2023 Dept. of ISE, SJBIT 30
The display property
30
#topmenu li {
display: inline;
border: 2px solid gray;
margin-right: 1em;
} CSS
output
<ul id="topmenu">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul> HTML
5/24/2023 Dept. of ISE, SJBIT 31
References
3
 http://www.w3schools.com/CSS

More Related Content

Similar to Lecture17-Floating Elements.pptx

CSE-4078 - Lecture - Week 3sasdgaga.pptx
CSE-4078 - Lecture - Week 3sasdgaga.pptxCSE-4078 - Lecture - Week 3sasdgaga.pptx
CSE-4078 - Lecture - Week 3sasdgaga.pptx
zaidAhmad84
 

Similar to Lecture17-Floating Elements.pptx (20)

CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Grids of Tomorrow: CSS Grid Layout
Grids of Tomorrow: CSS Grid LayoutGrids of Tomorrow: CSS Grid Layout
Grids of Tomorrow: CSS Grid Layout
 
An Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real World
 
New CSS Meets the Real World
New CSS Meets the Real WorldNew CSS Meets the Real World
New CSS Meets the Real World
 
CSS Layout
CSS LayoutCSS Layout
CSS Layout
 
Html5
Html5Html5
Html5
 
INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2
 
An Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real WorldAn Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real World
 
CSE-4078 - Lecture - Week 3sasdgaga.pptx
CSE-4078 - Lecture - Week 3sasdgaga.pptxCSE-4078 - Lecture - Week 3sasdgaga.pptx
CSE-4078 - Lecture - Week 3sasdgaga.pptx
 
Css layout
Css layoutCss layout
Css layout
 
Web Layout
Web LayoutWeb Layout
Web Layout
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
 
2b. Web Technology HTML Basics-2
2b. Web Technology HTML Basics-22b. Web Technology HTML Basics-2
2b. Web Technology HTML Basics-2
 
CSS Architecture: Writing Maintainable CSS
CSS Architecture: Writing Maintainable CSSCSS Architecture: Writing Maintainable CSS
CSS Architecture: Writing Maintainable CSS
 
Everything You know about CSS is Wrong
Everything You know about CSS is WrongEverything You know about CSS is Wrong
Everything You know about CSS is Wrong
 
New CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real World
 
CSS Walktrough Internship Course
CSS Walktrough Internship CourseCSS Walktrough Internship Course
CSS Walktrough Internship Course
 
06. Android Basic Widget and Container
06. Android Basic Widget and Container06. Android Basic Widget and Container
06. Android Basic Widget and Container
 
Css3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyCss3 and gwt in perfect harmony
Css3 and gwt in perfect harmony
 

Recently uploaded

Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
IJECEIAES
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
drjose256
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
MaherOthman7
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 

Recently uploaded (20)

Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 

Lecture17-Floating Elements.pptx

  • 1. || Jai Sri Gurudev|| Sri Adichunchanagiri Shikshana Trust (R) SJB INSTITUTE OF TECHNOLOGY (Affiliated to Visvesvaraya Technological University, Belagavi& Approved by AICTE, New Delhi.) No. 67, BGS Health & Education City, Dr. Vishnuvardhan Road Kengeri, Bengaluru – 560 060 Subject: Web Technology and Its Applications(18CS63) By CHETAN R, Assistant Professor Semester / Section: 6B Department of Information Science & Engineering Aca. Year: EVEN SEM /2020-21 1
  • 3. 5/24/2023 Dept. of ISE, SJBIT 3 Floating Elements  <!DOCTYPE html>  <html>  <head>  <style>  div {  float: left;  padding: 15px;  }  .div1 {  background: pink;  }  .div2 {  background: yellow;
  • 4. 5/24/2023 Dept. of ISE, SJBIT 4 Floating Elements  }  .div3 {  background: green;  }  </style>  </head>  <body>  <h2>Float Next To Each Other</h2>  <p>In this example, the three divs will float next to each other.</p>  <div class="div1">Div 1</div>  <div class="div2">Div 2</div>  <div class="div3">Div 3</div>  </body>  </html>
  • 5. 5/24/2023 Dept. of ISE, SJBIT 5 Floating Elements  Float Next To Each Other  In this example, the three divs will float next to each other.  Div 1  Div 2  Div 3
  • 6. 5/24/2023 Dept. of ISE, SJBIT 6 The CSS float property (reference) 6 img.headericon { float: right; width: 130px; } CSS  removed from normal document flow; underlying text wraps around as necessary Ghostbusters is a 1984 American science fiction comedy film written by co-stars Dan Aykroyd and Harold Ramis about three eccentric New York City parapsychologists-turned-ghost capturers. output property description float side to hover on; can be left, right, or none (default)
  • 7. 5/24/2023 Dept. of ISE, SJBIT 7 5/24/2023 Dept. of ISE, SJBIT 7 Floating elements diagram 7
  • 8. 5/24/2023 Dept. of ISE, SJBIT 8 Common float bug: missing width  often floating block elements must have a width property value  Let’s try “floating” 8
  • 9. 5/24/2023 Dept. of ISE, SJBIT 9 The clear property CS380 9 p { background-color: fuchsia; } h2 { clear: right; background-color: yellow; } CSS output Super Mario Fan Site! Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation
  • 10. 5/24/2023 Dept. of ISE, SJBIT 10 The clear property (cont.) property description clear disallows floating elements from overlapping this element; can be left, right, or none (default) 10
  • 11. 5/24/2023 Dept. of ISE, SJBIT 11 5/24/2023 Dept. of ISE, SJBIT 11 Clear diagram 11 div#sidebar { float: right; } p { clear: right; } CSS
  • 12. 5/24/2023 Dept. of ISE, SJBIT 12 Common error: container too short 12 <p><img src="images/mario.png" alt=“super mario" /> Mario is a fictional character in his video game series.....</p> HTML Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation. p { border: 2px dashed black; } img { float: right; } CSS
  • 13. 5/24/2023 Dept. of ISE, SJBIT 13 The overflow property Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation. output p { border: 2px dashed black; overflow: hidden; } CSS CS380
  • 14. 5/24/2023 Dept. of ISE, SJBIT 14 The overflow property (cont.) 14 property description overflow specifies what to do if an element's content is too large; can be auto, visible, hidden, or scroll
  • 15. 5/24/2023 Dept. of ISE, SJBIT 15 Multi-column layouts 15 <div> <p>first paragraph</p> <p>second paragraph</p> <p>third paragraph</p> Some other text that is important </div> HTML Some other text that is important output p { float: right; width: 25%; margin: 0.5em; border: 2px solid black; } div { border: 3px dotted green; overflow: hidden; } CSS second paragraph first paragraph third paragraph
  • 17. 5/24/2023 Dept. of ISE, SJBIT 17 The position property (examples) 17 div#ad { position: fixed; right: 10%; top: 45%; } CSS property value description position static default position relative offset from its normal static position absolute a fixed position within its containing element fixed a fixed position within the browser window top, bottom, left, right positions of box's corners
  • 18. 5/24/2023 Dept. of ISE, SJBIT 18 Absolute positioning 18 #sidebar { position: absolute; left: 400px; top: 50px; } CSS  removed from normal flow  positioned relative to the block element containing them  actual position determined by top, bottom, left, right  should often specify a width property as well CS380
  • 19. 5/24/2023 Dept. of ISE, SJBIT 19 Relative positioning 19 #area2 { position: relative; } CSS  absolute-positioned elements are normally positioned at an offset from the corner of the overall web page  to make the absolute element to position itself relative to some other element's corner, wrap the absolute element in an element whose position is relative CS380
  • 20. 5/24/2023 Dept. of ISE, SJBIT 20 Fixed positioning 20 #area2 { position: relative; } CSS  removed from normal flow  positioned relative to the browser window even when the user scrolls the window, element will remain in the same place CS380
  • 21. 5/24/2023 Dept. of ISE, SJBIT 21 Alignment vs. float vs. position 1. If possible, lay out an element by aligning its content  horizontal alignment: text-align  set this on a block element; it aligns the content within it (not the block element itself)  vertical alignment: vertical-align  set this on an inline element, and it aligns it vertically within its containing element 2. If alignment won't work, try floating the element 3. If floating won't work, try positioning the element  absolute/fixed positioning are a last resort and should not be overused 21
  • 22. 5/24/2023 Dept. of ISE, SJBIT 22 Details about inline boxes  Size properties (width, height, min- width, etc.) are ignored for inline boxes  margin-top and margin-bottom are ignored,  but margin-left and margin-right are not ignored CS380 22
  • 23. 5/24/2023 Dept. of ISE, SJBIT 23 Details about inline boxes  the containing block box's text-align property controls horizontal position of inline boxes within it  text-align does not align block boxes within the page  each inline box's vertical-align property aligns it vertically within its block box CS380 23
  • 24. 5/24/2023 Dept. of ISE, SJBIT 24 The vertical-align property property description vertical-align specifies where an inline element should be aligned vertically, with respect to other content on the same line within its block element's box CS380 24  can be top, middle, bottom, baseline (default), sub, super, text-top, text-bottom, or a length value or %  baseline means aligned with bottom of non-hanging
  • 25. 5/24/2023 Dept. of ISE, SJBIT 25 vertical-align example 25 <p style="background-color: yellow;"> <span style="vertical-align: top; border: 1px solid red;"> Don't be sad! Turn that frown <img src="images/sad.jpg" alt="sad" /> upside down! <img style="vertical-align: bottom“ src="images/smiley.jpg" alt="smile" /> Smiling burns calories, you know. <img style="vertical-align: middle" src="images/puppy.jpg" alt="puppy" /> Anyway, look at this cute puppy; isn't he adorable! So cheer up, and have a nice day. The End. </span> </p> HTML CS380
  • 26. 5/24/2023 Dept. of ISE, SJBIT 26 vertical-align example (cont.) CS380
  • 27. 5/24/2023 Dept. of ISE, SJBIT 27 Common bug: space under image 27 <p style="background-color: red; padding: 0px; margin: 0px"> <img src="images/smiley.png" alt="smile" /> </p> HTML  red space under the image, despite padding and margin of 0  this is because the image is vertically aligned to the baseline of the paragraph (not the same as the bottom)  setting vertical-align to bottom fixes the problem (so does setting line-height to 0px)
  • 28. 5/24/2023 Dept. of ISE, SJBIT 28 The display property 28 h2 { display: inline; background-color: yellow; } CSS  values: none, inline, block, run-in, compact, ...  use sparingly, because it can radically alter the page layout output property description display sets the type of CSS box model an element is displayed with
  • 29. 5/24/2023 Dept. of ISE, SJBIT 29 The display property (cont.) 29 p.secret { visibility: hidden; } CSS  hidden elements will still take up space onscreen, but will not be shown  to make it not take up any space, set display to none instead  can be used to show/hide dynamic HTML content on the page in response to events output CS380
  • 30. 5/24/2023 Dept. of ISE, SJBIT 30 The display property 30 #topmenu li { display: inline; border: 2px solid gray; margin-right: 1em; } CSS output <ul id="topmenu"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> HTML
  • 31. 5/24/2023 Dept. of ISE, SJBIT 31 References 3  http://www.w3schools.com/CSS

Editor's Notes

  1. if no width is specified, the floating element may occupy 100% of the page width, so no content can wrap around it
  2. We want the p containing the image to extend downward so that its border encloses the entire image
  3. We want the p containing the image to extend downward so that its border encloses the entire image
  4. We want the p containing the image to extend downward so that its border encloses the entire image
  5. We want the p containing the image to extend downward so that its border encloses the entire image
  6. How will the html code look?
  7. How will the html code look?
  8. Find a good example or w3c
  9. Definitely an example here is needed