How To Stretch An Image Horizontally With CSS
Có thể bạn quan tâm
One way to breathe new digital life into an image is to alter its width. You could do that using an image editor, but CSS can often get the job done faster. Learn how to add a CSS reference to an image and you can stretch it horizontally to any width you like. Cascading Style Sheets give you the ability to try out new looks for your business Web pages quickly, as you can apply them to elements throughout your site instantly, using nothing but a few lines of simple code.
- Open an HTML document that has an image and find the document's section. Paste the code shown below inside that section.This code creates a CSS class named stretchX. The width parameter's value, 400px, tells browsers to make any element that references the class 400 pixels wide. It also creates a class named stretchXY that has width and height values.
- Move to your document's section and locate an img tag that defines an image. It will look similar to the example shown below:
- Add "class="stretchX" after the word "img" so that your img tag looks similar to the one below:
- Save your document and view it in a browser. The image's width will be 400 pixels wide because that's the value defined in the stretchX CSS class. Return to your document and change 400 to any other value to make the image stretch to that width.
More For You
Formatting an Image in a Text Post on Tumblr
Formatting an Image in a Text Post on Tumblr. A dazzling ocean sunset, a basket of kittens...How to Make Images Have Borders in Blogger
How to Make Images Have Borders in Blogger. You can adjust the layout of your Blogger...How to Make a Navigation Bar Extend to the Bottom of the Page in CSS
How to Make a Navigation Bar Extend to the Bottom of the Page in CSS. Left navigation bars...How to Customize WordPress Widgets for Rounded Corners
How to Customize WordPress Widgets for Rounded Corners. Rounded corners are seen in Web...How to Take an Image from My Computer & Transfer It to a Word Document
How to Take an Image from My Computer & Transfer It to a Word Document. Microsoft Word...References
- W3Schools.com: CSS Width Property
- New Perspectives on Adobe Dreamweaver CS5, Comprehensive; Kelly Hart, Mitch Geller
Advertisement
Article continues below this ad
Resources
- HTMLGoodies: Cascading Style Sheets, HTMLGoodies CSS Tutorials and Resources
- Bloomberg Businessweek: The 10 Commandments of Web Design
Tips
- You can also replace 200px with a percentage value such as 300% in the CSS class. This allows you to stretch an image by a percent instead of by a pixel amount.
- If your img tag already contains a class reference, append your class name after the existing class name that appears in the attribute definition. For example, if the current img tag begins with
- Replace the img tag's reference to "stretchX" with "stretchXY" if you'd like to change the image's width and height. If you do this, adjust the width and height values in the stretchXY class to achieve the desired image width and height on your Web page.
- Experiment with image stretching on company logos or other images that contain text. You may discover a new appealing look that works better than the existing one.
- Any time you increase an image's dimensions using CSS, the image's quality decreases. This may not be noticeable with small increases, but it can become a problem if you make your images too large. Examine your resized images carefully before placing them on the Web.
After majoring in physics, Kevin Lee began writing professionally in 1989 when, as a software developer, he also created technical articles for the Johnson Space Center. Today this urban Texas cowboy continues to crank out high-quality software as well as non-technical articles covering a multitude of diverse topics ranging from gaming to current affairs.
Từ khóa » Html Background Image Stretch Horizontally
-
CSS - Background Image Stretch Horizontally And Repeat Vertically?
-
How To Stretch And Scale An Image In The Background With CSS
-
HTML Stretch Background Image
-
Stretch Background Image In Header Only Horizontally, It Does Not ...
-
How To Stretch And Scale Background Image Using CSS?
-
How To Stretch A Background Image To Fit A Web Page - ThoughtCo
-
How To Stretch A Background Image In CSS So That It Doesn't Repeat ...
-
Background-size - CSS-Tricks
-
Resizing Background Images With Background-size - CSS
-
CSS Background-repeat Property - W3Schools
-
CSS Object-fit Property - W3Schools
-
How To Stretch A Background Image Horizontally Css?
-
Background-size - CSS: Cascading Style Sheets - MDN Web Docs
-
Perfect Full Page Background Image - CSS-Tricks