Home Web Front-end CSS Tutorial Common browser compatibility issues in html and css

Common browser compatibility issues in html and css

Nov 16, 2017 pm 05:01 PM
css html Browser

We will definitely use css in html development, but sometimes development is not as smooth as we thought. For example, common browser compatibility issues in html and css, then for this browser compatibility In this section, we will teach you how to solve the problem.

1. Centering problem

The content in the div is centered by IE by default, and left-aligned by FF by default. You can try adding code:

margin: 0 auto;
Copy after login

2. Height problem

For two divs arranged one above the other or nested, the height of the div above is set. If the actual content in the div is greater than the set height, the two divs will overlap in FF; but In IE, the div below will automatically make space for the div above. So in order to avoid overlapping layers, the height must be controlled appropriately, or you may simply not write the height and let it adjust automatically. A better method is height:100%. ;But when the first-level elements in this div are all floated, you need to add an empty div with a sunken bottom at the end of the div block and before closing. The corresponding CSS is:

float_bottom {clear:both;height:0px;font-size:0px;padding:0;margin:0;border:0;line-height:0px;overflow:hidden;}
Copy after login

3. clear: both;

If you don’t want to be affected by float, just write clear: both;

4. Double distance generated by IE floating margin

01#box {
 float:left;
width:100px;
 margin:0 0 0 100px; //这种情况之下IE会产生200px的距离
display:inline; //使浮动忽略
}
Copy after login

5. Padding problem

After FF sets padding, div will increase height and width, but IE will not (* standard XHTML1.0 definition dtd seems to be consistent) height control Appropriate, or try to use height:100%; use padding to reduce the width. But according to actual experience, generally the padding of FF and IE will not be much different. The actual width of the div = width + padding, so write the full width and padding, width of the div. Define padding as the actual desired width.

6. Problems with padding and marign on the y-axis when divs are nested

The distance from the child div to the parent div on the y-axis in FF is parent padding + child marign

In IE, the distance between the child div on the y-axis and the parent div is the larger of the parent padding and the child margin

In FF, when the parent padding=0 and border=0 on the y-axis, the child div The distance to the parent div is 0, and the child margin acts outside the parent div

7. Foolish solution techniques for padding, margin, height, width

Note that this is a technique , not a method:

Write the standard header

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=” 
高尽量用padding,慎用margin,height尽量补上100%,父级height有定值子级height不用100%,子级全为浮动时底部补个空clear:both的div宽尽量用margin,慎用padding,width算准实际要的减去padding
Copy after login

8. List class

1. The ul tag has a padding value by default in FF, but in In IE, only margin has a value

First define ul {margin:0;padding:0;}

2. Indentation problem of ul and ol lists When eliminating the indentation of ul, ol and other lists , the style should be written as: {list-style:none;margin:0px;padding:0px;}

9. Display class (display:block,inline)

1. Two elements, display:block and inline

display:block; //Inline elements can be simulated as block elements

display:inline; //Achieve the effect of being arranged in the same line

display:table; //for FF, simulate the effect of table

display:block block element, the characteristics of the element are:

Always start on a new line; Height, line height, and top and bottom margins are all controllable; the width defaults to 100% of its container, unless a width is set

,

,

,
,

Statement of this Website
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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel8 optimization points Laravel8 optimization points Apr 18, 2025 pm 12:24 PM

Laravel 8 provides the following options for performance optimization: Cache configuration: Use Redis to cache drivers, cache facades, cache views, and page snippets. Database optimization: establish indexing, use query scope, and use Eloquent relationships. JavaScript and CSS optimization: Use version control, merge and shrink assets, use CDN. Code optimization: Use Composer installation package, use Laravel helper functions, and follow PSR standards. Monitoring and analysis: Use Laravel Scout, use Telescope, monitor application metrics.

How to simplify CMS development with Composer: Practical application of the Lebenlabs/SimpleCMS library How to simplify CMS development with Composer: Practical application of the Lebenlabs/SimpleCMS library Apr 18, 2025 am 09:45 AM

When developing a new content management system (CMS), I encountered a common but difficult problem: how to quickly build a fully functional CMS without adding too much complexity. There are many ready-made CMS solutions available on the market, but they are often too large and complex to configure and can be a burden for small projects. After some exploration, I discovered the lebenlabs/simplecms library, which provides a simple and efficient solution through Composer.

Using React with HTML: Rendering Components and Data Using React with HTML: Rendering Components and Data Apr 19, 2025 am 12:19 AM

Using HTML to render components and data in React can be achieved through the following steps: Using JSX syntax: React uses JSX syntax to embed HTML structures into JavaScript code, and operates the DOM after compilation. Components are combined with HTML: React components pass data through props and dynamically generate HTML content, such as. Data flow management: React's data flow is one-way, passed from the parent component to the child component, ensuring that the data flow is controllable, such as App components passing name to Greeting. Basic usage example: Use map function to render a list, you need to add a key attribute, such as rendering a fruit list. Advanced usage example: Use the useState hook to manage state and implement dynamics

Which 2025 currency exchanges are more secure? Which 2025 currency exchanges are more secure? Apr 20, 2025 pm 06:09 PM

The top ten safe and reliable exchanges in the 2025 cryptocurrency circle include: 1. Binance, 2. OKX, 3. Gate.io (Sesame Open), 4. Coinbase, 5. Kraken, 6. Huobi Global, 7. Gemini, 8. Crypto.com, 9. Bitfinex, 10. KuCoin. These exchanges are rated as safe and reliable based on compliance, technical strength and user feedback.

What is the reason why the browser does not respond after the WebSocket server returns 401? How to solve it? What is the reason why the browser does not respond after the WebSocket server returns 401? How to solve it? Apr 19, 2025 pm 02:21 PM

The browser's unresponsive method after the WebSocket server returns 401. When using Netty to develop a WebSocket server, you often encounter the need to verify the token. �...

How to learn iaravel How to learn iaravel Apr 18, 2025 pm 12:21 PM

The steps to learn Laravel are: Have basic knowledge of PHP. Install the Laravel framework. Learn about Laravel architecture. Learn basic syntax: route, controller, view, model. Build a small application practice framework for use. See the official documentation for detailed guidance. Join the community to exchange experiences and seek help. Stay updated and pay attention to new features.

Why can't JavaScript directly obtain hardware information on the user's computer? Why can't JavaScript directly obtain hardware information on the user's computer? Apr 19, 2025 pm 08:15 PM

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

See all articles