CSS deep understanding of Width:auto usage example sharing

Source: Internet
Author: User
This article mainly introduces the CSS deep understanding of the use of Width:auto information, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.

Objective

The man who read my last article may think I'm a css2, what's so good about it? Then I refer to the "CSS World" This book, together with you to review the specific points of understanding the impact of our code.

First, we need to understand that the width default is auto, so you don't have to write code to control its widths automatically oh.

Common 4 kinds of width performance

Take full advantage of available space

The default block elements are all 100% parent element widths, as you all know, but many people write extra widths of 100% for block elements.

Shrink and wrap

Common is floating, inline block elements, absolute positioning. We call this characteristic a wrap.

Shrink to minimum

This is easiest to appear in the Table-layout for auto table, we do not control the table cell width, when each column can not be placed, the text will be truncated, however, mobile phone number, English words, numbers, etc. can not be broken, it may lead to some just text columns, each word is a line display, Called Min-content.

Exceeds container width

The general elements do not go beyond the container display, except in the following two cases, especially the first is the problem that is frequently encountered in the development of the primary front end.

    1. Content appears in English or numeric, no line break display

    2. Style White-space:nowrap is set, not wrapped.

For the above two problems, you can make the following corrections respectively.

    1. Word-break:break-all

    2. White-space:normal

Other features

External dimensions and fluid characteristics

Normal flow width

The block element defaults to a fluid attribute that inherits the width of the parent element and does not exceed the parent element width. However, some people still write code like this:


a{display:block;width:100%;}

Or such code, you give the navigation of a tag set spacing width of what, in fact, the label becomes block level, will be automatically calculated according to their own width, superfluous.


. nav{width:240px}.nav-a{display:block;width:200px;margin:0 10px;padding:9px 10px;}

Formatting width

The formatted width indicates that the model is now absolutely positioned, including absolute and fixed positions, except that the reference points are different. By default, the feature is inclusive, which determines the width of the box, but when the (non-replacement Element) Left/right is set at the same time, its width is calculated relative to the nearest positional property rather than the static ancestor element. Its width is-left-right the width of the parent element, while the other attributes remain unchanged. This is a great use in our actual layout, such as the layout of the width-to-width combination of the CSS utility technology I share.


. par{   width:1000px;   position:relative;   }   The child element width is 700px   . son{   Position:absolute;   left:100px;   right:200px;}

Internal dimensions and fluid characteristics

Wrap Sex

Inclusion refers to when the element is a non-block element, its width is determined by the content, it is only responsible for expanding as needed, and because the external is definitely a block element, so it does not exceed the container characteristics.

The actual function can be used without scripting text less horizontal center, more text, on the left to display.


. Container{text-align:center;}. Content{display:inline-block;text-align:left;}

Preferred minimum width

This simple understanding is that the actual width of the element depends on the smallest unit of content, which is higher than width:0. For example, you set the width is 0, but the content has a Chinese character, there will be a Chinese character size; A word will show the size of a word.

This practical use can be done in a variety of simple graphics, such as concave and convex shape, and then the content is set to White can be.


. Ao{width:0;display:inline-block;}. Ao:before{color: #fff; content: ' Love you love '; outline:2px solid #000;}

Maximum width

The maximum width is the maximum width that the element can have, and in general we use it to limit the number of words or content in particular. This is not a lot of real-world scenarios.

Here we only extend the two scrolling effects, one is the original page or Dom scrolling, the other is the iscroll that set the internal elements and the location of the container to show, the effect is better.

Related recommendations;

How to use margin 0 auto in HTML

HTML5 Sets or returns the properties of the audio and video playback after loading autoplay

A detailed description of the implementation of the AutoLoad method in Laravel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.