search
HomeWeb Front-endHTML TutorialCSS layout?? Left fixed width, right adaptive width and equal height layout_html/css_WEB-ITnose

Method 1:

Not much else to say, just upload the code directly, or refer to the online DEMO. All the DEMOs below have HTML and CSS codes. Interested students can read it by themselves. .

HTML Markup

		<div id="container">			<div id="wrapper">				<div id="sidebar">Left Sidebar</div>				<div id="main">Main Content</div>			</div>		</div>	

CSS Code

		<style type="text/css">			* { margin: 0; padding: 0; }			html { height: auto; }			body { margin: 0; padding: 0; }			#container { background: #ffe3a6; }			#wrapper { display: inline-block; border-left: 200px solid #d4c376;/*==此值等于左边栏的宽度值==*/ position: relative; vertical-align: bottom; }			#sidebar { float: left; width: 200px; margin-left: -200px;/*==此值等于左边栏的宽度值==*/ position: relative; }			#main { float: left; }				#maing,			#sidebar{ min-height: 200px; height: auto !important; height: 200px; }		</style>	

View the online DEMO.

Method 2

HTML Markup

		<div id="container">			<div id="left" class="aside">Left Sidebar</div>			<div id="content" class="section">Main Content</div>		</div>	

CSS Code

		<style type="text/css">			 	*{margin: 0;padding: 0;}			 	#container { overflow: hidden; }			 	#left { background: #ccc; float: left; width: 200px; margin-bottom: -99999px; padding-bottom: 99999px; }			 	#content { background: #eee; margin-left: 200px;/*==此值等于左边栏的宽度值==*/ margin-bottom: -99999px; padding-bottom: 99999px; }			 	#left,			 	#content { min-height: 200px; height: auto !important; height: 200px; }		</style>	

View the online DEMO.

Method 3:

HTML Markup

		<div id="container">			<div id="content">Main Content</div>			<div id="sidebar">Left Sidebar</div>		</div>	

CSS Code

			*{margin: 0;padding: 0;}		 	#container{		 		background-color:#0ff;		 		overflow:hidden;		 		padding-left:220px; /* 宽度大小等与边栏宽度大小*/		 	}		 	* html #container{		 		height:1%; /* So IE plays nice */		 	}		 	#content{		 		background-color:#0ff;		 		width:100%;		 		border-left:220px solid #f00;/* 宽度大小等与边栏宽度大小*/		 		margin-left:-220px;/* 宽度大小等与边栏宽度大小*/		 		float:right;		 	}		 	#sidebar{		 		background-color:#f00;		 		width:220px;		 		float:right;		 		margin-left:-220px;/* 宽度大小等与边栏宽度大小*/		 	}		 	#content,		 	#sidebar {		 		min-height: 200px;		 		height: auto !important;		 		height: 200px;		 	}	

View the online DEMO effect.

Method 4:

HTML Markup

		<div id="container2">			<div id="container1">					<div id="col1">Left Sidebar</div>					<div id="col2">Main Content</div>		 	</div>		</div>	

CSS Code

		*{padding: 0;margin:0;}		#container2 {		  	float: left;		  	width: 100%;		  	background: orange;		  	position: relative;		  	overflow: hidden;		  }		  #container1 {		  	float: left;		  	width: 100%;		  	background: green;		  	position: relative;		  	left: 220px;/* 宽度大小等与边栏宽度大小*/		  }     		  #col2 {		  	position: relative;		  	margin-right: 220px;/* 宽度大小等与边栏宽度大小*/		  }     		  #col1 {		  	width: 220px;		  	float: left;		  	position: relative;		  	margin-left: -220px;/* 宽度大小等与边栏宽度大小*/		  }	   			#col1,#col2 {				min-height: 200px;				height: auto !important;				height: 200px;			}	

View the online DEMO.

Method 5:

HTML Markup

		<div id="container1">			<div id="container">				<div id="left">Left Sidebar</div>				<div id="content">					<div id="contentInner">Main Content</div>				</div>			</div>		</div>	

CSS Code

		*{padding: 0;margin: 0;}		#container1 {			float: left;			width: 100%;			overflow: hidden;			position: relative;			background-color: #dbddbb;		}		#container {			background-color: orange;			width: 100%;			float: left;			position: relative;			left: 220px;/* 宽度大小等与边栏宽度大小*/		}		#left {						float: left;			margin-right: -100%;			margin-left: -220px;/* 宽度大小等与边栏宽度大小*/			width: 220px;		}		#content {			float: left;			width: 100%;			margin-left: -220px;/* 宽度大小等与边栏宽度大小*/		}		#contentInner {						margin-left: 220px;/* 宽度大小等与边栏宽度大小*/			overflow: hidden;		}				#left,		#content {				min-height: 200px;				height: auto !important;				height: 200px;		}	

View the online DEMO.

In response to the above interview question requirements, I used a total of five different methods to implement them. After testing, they can all run in various browsers. Finally, I have a few points to make in particular:

All of the above In the DEMO, pay attention to the directional coordination and the values ​​should be unified. If you want to try to use the width value required for your own layout, please modify it according to the relevant code links; In all the above DEMOs, the spacing between them is not set. If You want to have a certain spacing between them. There are two ways to achieve this. One is to modify the relevant parameters based on the above DEMO. The other is to add the "div" tag to the corresponding one and set its "padding". value, this is safer and will not break your layout because we have a column here that uses adaptive width. In some browsers, when the browser screen is stretched to a certain size, it gives us the feeling that it is adaptive. The content of the width column seems to be hidden. In your actual project, it is best to add a "min-width" setting to "body".
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.