How To Change Web Page Layout Dimensions Html
How to set div width to fit content using CSS ?
There are 3 means to solve this problem which are listed beneath:
- By default case
- Using inline-block belongings
- Using fit-content property in width and height
Default Case: HTML div is by default fit to content inside it. The example goes similar this:
Case 1:
html
<!DOCTYPE html>
<
html
lang = "en" dir = "ltr">
<
head
>
<
meta
charset = "utf-8">
<
title
>GeeksforGeeks Example</
championship
>
<
style
media = "screen">
trunk {
background: orange;
overflow: hidden;
color: white;
}
.GeeksForGeeks {
text-marshal: center;
background: dodgerblue;
position: absolute;
top: 50%;
left: i%;
right: i%;
}
</
style
>
</
head
>
<
body
>
<
h1
style = "color:forestgreen; top:35%;
left: 35%; position:accented; ">
Geeks For Geeks
</
h1
>
<
div
course = "GeeksForGeeks">
Cascading Style Sheets, fondly referred
to as CSS, is a simply designed linguistic communication
intended to simplify the process of
making web pages presentable. CSS allows
you to apply styles to spider web pages. More
importantly, CSS enables you to practice this
contained of the HTML that makes upwardly
each web page.
</
div
>
</
torso
>
</
html
>
Output:
Using inline-block property: Use display: inline-block belongings to prepare a div size co-ordinate to its content.
Example 2:
html
<!DOCTYPE html>
<
html
lang = "en">
<
caput
>
<
meta
charset = "utf-8">
<
championship
>GeeksforGeeks Case</
title
>
<
style
media = "screen">
body {
background: violet;
overflow: auto;
color: white;
}
.GeeksForGeeks {
text-align: center;
groundwork: dodgerblue;
position: absolute;
brandish: inline-block;
left: ane%;
correct: 1%;
summit: 50%;
}
</
style
>
</
head
>
<
trunk
>
<
h1
style="color: forestgreen;
acme: 35%; left: 35%; position: accented;">
Geeks For Geeks
</
h1
>
<
div
class="GeeksForGeeks">
Cascading Mode Sheets, fondly referred
to as CSS, is a merely designed linguistic communication
intended to simplify the process of
making spider web pages presentable. CSS allows
you to apply styles to spider web pages. More than
importantly, CSS enables you lot to do this
independent of the HTML that makes up
each web folio.
</
div
>
</
torso
>
</
html
>
Output:
Using fit-content property in width and pinnacle: In this method, we set the width and tiptop belongings to fit-content value. Instance iii:
html
<!DOCTYPE html>
<
html
lang = "en" dir = "ltr">
<
head
>
<
meta
charset = "utf-8">
<
championship
>Geeks for Geeks Example</
championship
>
<
style
media = "screen">
trunk {
background: tomato;
overflow: subconscious;
color: white;
}
.GeeksForGeeks {
background: crimson;
position: absolute;
width:fit-content;
elevation:fit-content;
left: 0;
meridian: l%;
}
</
style
>
</
head
>
<
body
>
<
h1
style = "colour: lime; top: 35%;
left: 35%; position: accented;">
Geeks For Geeks
</
h1
>
<
div
form = "GeeksForGeeks">
Cascading Style Sheets, fondly referred
to as CSS, is a simply designed linguistic communication
intended to simplify the process of
making web pages presentable. CSS allows
yous to utilise styles to web pages. More
importantly, CSS enables you to exercise this
independent of the HTML that makes upward
each web page.
</
div
>
</
body
>
</
html
>
Output:
CSS is the foundation of webpages, is used for webpage evolution past styling websites and spider web apps. Yous can learn CSS from the ground upward by following this CSS Tutorial and CSS Examples.
Source: https://www.geeksforgeeks.org/how-to-set-div-width-to-fit-content-using-css/
Posted by: thorntonxvier1937.blogspot.com
0 Response to "How To Change Web Page Layout Dimensions Html"
Post a Comment