”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 掌握 React 应用程序的 Docker

掌握 React 应用程序的 Docker

发布于2024-11-01
浏览:203

Mastering Docker for React Applications

In the modern world of software development, the ability to deploy applications quickly and consistently across multiple environments is crucial. Docker has revolutionized how developers manage application dependencies and configurations, allowing them to package applications into containers that are portable and consistent regardless of the environment in which they are running.

In this blog post, we'll dive deep into how to master Docker for React applications. We will explore how to build, containerize, and deploy React applications using Docker while covering advanced techniques that will make your application scalable and robust.

Why Docker for React?

For consistent application execution on every machine, Docker offers a lightweight virtualization environment. The "it works on my machine" issue is resolved by building Docker containers for your React application, which guarantee the same environment across development, staging, and production systems. Your code, dependencies, and environment settings may all be included in an image that Docker can execute on any system that has Docker installed.

Using Docker with React brings several benefits:

Consistency: The same code runs in the same environment, eliminating issues related to differing environments.

Portability: Docker containers can run on any system that supports Docker, whether it's your local development machine, a staging server, or production.

Scalability: Docker makes it easier to scale applications by distributing container instances across multiple environments.

Isolation: Dependencies and environment variables are isolated within a container, so your system is clean of global installations that could cause conflicts.

Now, let’s start by getting our environment ready and walking through the steps of creating and Dockerizing a React app.

Getting Started: Setting Up the Environment

Before diving into Dockerizing a React app, let’s ensure your environment is properly set up.

Install Node.js and npm: If you haven’t already, install Node.js and npm on your machine. You can download them from Node.js official site.

Install Docker: Docker needs to be installed and running on your system. If Docker isn’t installed, head over to Docker's official website to download Docker Desktop for your platform. Make sure Docker is running properly by executing:
bash docker --version

Once Docker and Node.js are set up, you’re ready to start creating your React app.

Step 1: Creating a New React Application

Let’s start by creating a simple React app using the create-react-app command, which is a popular way to scaffold React applications quickly.

In your terminal, run the following command to create a new React project:

npx create-react-app dockerized-react-app
cd dockerized-react-app

This will create a folder named dockerized-react-app with all the required files to start developing your React app.

Run the app locally to ensure everything works:

npm start

This will start the development server on http://localhost:3000/. You should see the default React app interface in your browser.

Step 2: Writing a Dockerfile for the React App

Now that we have a basic React application up and running, it’s time to Dockerize it.

A Dockerfile is a text file that contains instructions on how to build a Docker image for your application. In the root of your project (where the package.json file is located), create a new file called Dockerfile:

touch Dockerfile

In this file, we will define the steps for building a Docker image of our React app.

Here’s an example of a basic Dockerfile:

# Step 1: Specify the base image
FROM node:14

# Step 2: Set the working directory
WORKDIR /app

# Step 3: Copy package.json and install dependencies
COPY package.json ./
RUN npm install

# Step 4: Copy the rest of the application code
COPY . .

# Step 5: Build the React app for production
RUN npm run build

# Step 6: Use an nginx server to serve the built app
FROM nginx:alpine
COPY --from=0 /app/build /usr/share/nginx/html

# Step 7: Expose port 80 to the outside world
EXPOSE 80

# Step 8: Start nginx
CMD ["nginx", "-g", "daemon off;"]

Let’s break down the Dockerfile step by step:

Base Image: We start with the official Node.js image, which contains Node.js and npm. This image will allow us to build the React application. We are using Node version 14, but you can modify it based on your needs.

Set the Working Directory: Inside the container, we create a working directory /app where all the project files will be stored.

Copy and Install Dependencies: We copy the package.json file into the container and install the app dependencies by running npm install.

Copy the Application Code: After installing dependencies, we copy the rest of the application files into the container.

Build the Application: We run npm run build to create an optimized production build of the React app.

Use Nginx to Serve the App: Once the app is built, we switch to the official Nginx image (a web server) to serve our React app. We copy the production build files into Nginx's default directory.

Expose Port 80: The app will be served on port 80, which is the default HTTP port.

Start Nginx: Finally, we run Nginx in the foreground using nginx -g "daemon off;".

Step 3: Building and Running the Docker Image

Now that the Dockerfile is set up, we can build the Docker image and run it as a container.

To build the Docker image, run the following command in the root of your project (where the Dockerfile is located):

docker build -t react-app-docker .

This command tells Docker to build an image using the current directory (.) and tag it as react-app-docker. The build process will install dependencies and create a production-ready build of the React app.

After the image is built, run it with the following command:

docker run -p 80:80 react-app-docker

This command tells Docker to run the container and map port 80 of the container to port 80 of your local machine. You can now access your React application by visiting http://localhost/ in your browser.

Step 4: Dockerizing for Development

While the previous steps focus on Dockerizing the React app for production, you might also want to use Docker during development to keep your environment consistent.

For development, we will modify the Dockerfile to enable hot reloading of changes to the React app. Here’s an updated version of the Dockerfile for development:

# Use the official Node image as the base
FROM node:14

# Set the working directory
WORKDIR /app

# Install dependencies
COPY package.json ./
RUN npm install

# Copy the application code
COPY . .

# Expose port 3000 for development
EXPOSE 3000

# Start the development server
CMD ["npm", "start"]

This Dockerfile:

Uses the same base image (Node.js) but runs the development server instead of building the app for production.

Exposes port 3000, which is the default port for React's development server.

You can build the development Docker image and run it with the following commands:

docker build -t react-app-dev .
docker run -p 3000:3000 react-app-dev

With this setup, the app will be served at http://localhost:3000/. However, any changes you make to your code won’t be reflected inside the container unless we set up hot reloading.

To enable hot reloading, we need to bind our local file system to the container. Run the container with the following command:

docker run -p 3000:3000 -v $(pwd):/app react-app-dev

The -v $(pwd):/app flag mounts the current directory ($(pwd)) to the /app directory inside the container, ensuring that any changes you make are reflected in the running container. This allows for a seamless development experience while using Docker.

Great! Let’s continue with the next part of "Mastering Docker for React Applications".

Step 5: Managing Environment Variables in Docker

In real-world applications, it’s common to have different environments like development, staging, and production. Each of these environments may require different configuration settings, such as API endpoints, credentials, or feature toggles. To manage these configurations in Docker, we use environment variables.

For a React app, you can manage environment variables by creating a .env file and loading it into the Docker container.

Creating a .env File

Create a .env file in the root of your React project:

touch .env

Add the following environment variables to the .env file:

REACT_APP_API_URL=https://api.example.com
REACT_APP_FEATURE_FLAG=true

In a React application, any environment variable prefixed with REACT_APP_ will automatically be available in the app. You can access these variables using process.env.REACT_APP_*.

Modifying the Dockerfile

To load these environment variables into your Docker container, we’ll modify the Dockerfile.

Here’s an updated Dockerfile that loads environment variables:

# Use the official Node.js image as the base
FROM node:14

# Set the working directory
WORKDIR /app

# Copy the application code
COPY . .

# Install dependencies
RUN npm install

# Build the application
ARG REACT_APP_API_URL
ARG REACT_APP_FEATURE_FLAG
RUN npm run build

# Serve the app with Nginx
FROM nginx:alpine
COPY --from=0 /app/build /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

Building the Docker Image with Environment Variables

When building the Docker image, you can pass the environment variables using the --build-arg option:

docker build --build-arg REACT_APP_API_URL=https://api.example.com --build-arg REACT_APP_FEATURE_FLAG=true -t react-app-docker-env .

This will inject the environment variables into the build process, and your React application will use these variables accordingly.

Alternatively, you can use Docker Compose to manage environment variables (which we will discuss shortly).

Step 6: Multi-Stage Builds for Smaller Images

Docker images can sometimes become quite large, especially if they contain development tools and libraries that are not needed in production. To reduce the size of your Docker images, you can use multi-stage builds.

Multi-stage builds allow you to use multiple FROM statements in your Dockerfile, each specifying a different image. This lets you separate the build environment from the runtime environment, which results in a smaller and more optimized final image.

Here’s how you can update your Dockerfile to use multi-stage builds:

# Stage 1: Build the React app
FROM node:14 AS build

# Set the working directory
WORKDIR /app

# Install dependencies
COPY package.json ./
RUN npm install

# Copy the rest of the app code
COPY . .

# Build the React app
RUN npm run build

# Stage 2: Serve the app with Nginx
FROM nginx:alpine

# Copy the production build from the first stage
COPY --from=build /app/build /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

In this multi-stage Dockerfile, we perform the build step in the first stage (using the Node.js image) and then copy the built files to the Nginx image in the second stage. This ensures that the final image only contains the production build of the React app, resulting in a much smaller image.

You can build and run the Docker image as before:

docker build -t react-app-multistage .
docker run -p 80:80 react-app-multistage

By using multi-stage builds, you reduce the size of your Docker images, which speeds up the deployment and reduces storage usage.

Step 7: Using Docker Compose for Multi-Container Applications

In some cases, your React app may need to communicate with other services, such as a backend API, a database, or a caching layer. Docker Compose is a tool that simplifies the orchestration of multi-container applications, allowing you to define multiple services in a single docker-compose.yml file.

Let’s see how Docker Compose can be used to run both a React app and an API server.

Example: React App Node.js API

Imagine you have a React frontend and a Node.js backend, and you want to Dockerize both and run them together using Docker Compose.

Create a Node.js API: For simplicity, let’s create a basic Node.js API that returns some data.

In the root of your project, create a folder named api and initialize a new Node.js project:

mkdir api
cd api
npm init -y

Install the necessary dependencies:

npm install express

Create a new file called index.js in the api folder with the following code:

const express = require('express');
const app = express();

app.get('/api/data', (req, res) => {
    res.json({ message: "Hello from the Node.js API!" });
});

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});

Dockerize the Node.js API: Now, create a Dockerfile in the api folder for the Node.js API:

# Use the official Node.js image
FROM node:14

# Set the working directory
WORKDIR /app

# Copy the application code
COPY . .

# Install dependencies
RUN npm install

# Expose port 5000
EXPOSE 5000

Start the API server

CMD ["node", "index.js"]

Create a docker-compose.yml File: In the root of your project, create a docker-compose.yml file that defines both the React app and the Node.js API:

version: '3'
services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:80"
    depends_on:
      - backend

  backend:
    build:
      context: ./api
      dockerfile: Dockerfile
    ports:
      - "5000:5000"

In this docker-compose.yml file, we define two services:

frontend: The React app, which is served on port 3000 (mapped to port 80 in the container).

backend: The Node.js API, which is served on port 5000.

Run the Application with Docker Compose: To start both the React app and the Node.js API, run the following command in your project’s root directory:

docker-compose up --build

Docker Compose will build and run both services. The React app will be available at http://localhost:3000/, and the API will be available at http://localhost:5000/api/data.

With Docker Compose, you can easily orchestrate multi-container applications and manage their dependencies.

Step 8: Optimizing Docker for React Development

When working with Docker during development, there are several ways to optimize your workflow to improve speed and efficiency. Some key tips include:

Caching Dependencies

Docker has a built-in caching mechanism that allows you to speed up subsequent builds by caching layers that haven’t changed. One common optimization is to cache your node_modules directory to avoid re-installing dependencies every time you build the Docker image.

Here’s how you can modify your Dockerfile to cache dependencies:

# Install dependencies only if package.json changes
COPY package.json ./
RUN npm install
COPY . .

By copying package.json before copying the rest of the code, Docker can cache the npm install step. This way, if your code changes but package.json remains the same, Docker will skip re-installing the dependencies, speeding up the build process.

Let's continue with the next part of "Mastering Docker for React Applications".

Step 9: Dockerizing a React App for Production

When deploying a React application to production, you want to make sure that the Docker setup is optimized for performance, security, and reliability. In this section, we’ll explore the best practices for Dockerizing a React app for production.

Serving Static Files with Nginx

One of the most common and efficient ways to serve a production React app is by using Nginx as a web server. Nginx is highly performant and is widely used for serving static files in production environments.

Let’s modify the Dockerfile to use Nginx for serving the React app’s static files.

Here’s an optimized production Dockerfile:

# Stage 1: Build the React app
FROM node:14 AS build

# Set the working directory
WORKDIR /app

# Copy the package.json and install dependencies
COPY package.json ./
RUN npm install

# Copy the rest of the application code and build the app
COPY . .
RUN npm run build

# Stage 2: Serve the app with Nginx
FROM nginx:alpine

# Copy the build output to the Nginx HTML directory
COPY --from=build /app/build /usr/share/nginx/html

# Copy a custom Nginx configuration file
COPY nginx.conf /etc/nginx/nginx.conf

# Expose port 80 to serve the app
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

Custom Nginx Configuration

To make sure Nginx is optimized for serving your React app, you can customize the configuration by creating an nginx.conf file.

Here’s an example of a basic Nginx configuration for serving a React app:

server {
    listen 80;

    location / {
        root   /usr/share/nginx/html;
        try_files $uri /index.html;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

This configuration ensures that Nginx serves the index.html file for any URL that isn’t a static file. This is important for client-side routing in React, where the app might handle routes that are not mapped to static files on the server.

Optimizing the Docker Image Size

A smaller Docker image means faster deployments and reduced resource usage. To minimize the size of the final production image, you can take several steps:

Use a minimal base image: In the Dockerfile above, we used nginx:alpine, which is a lightweight version of Nginx based on Alpine Linux.

Use multi-stage builds: We separated the build stage (Node.js) from the runtime stage (Nginx) to ensure that the final image only contains the built files and the Nginx server, without any unnecessary dependencies from the build process.

Remove unnecessary files: Ensure that unnecessary files, such as documentation, test files, or source maps, are not included in the production image. This can be done by excluding these files in the .dockerignore file or adjusting the build process.

Using .dockerignore to Optimize the Build Context

Docker reads the entire project directory during the build process, but not all files are needed in the final image. By creating a .dockerignore file, you can prevent certain files or directories from being copied to the Docker image.

Create a .dockerignore file in the root of your project:

touch .dockerignore

Here’s an example of a .dockerignore file:

node_modules
.git
.env
Dockerfile
docker-compose.yml
README.md

This ensures that unnecessary files, such as node_modules and .git, are not included in the Docker image, making the build faster and the final image smaller.

Step 10: Running Dockerized React Applications in Production

Once your Docker image is optimized and ready for production, the next step is deploying it. There are several platforms and services where you can run your Dockerized React application in production. Let’s explore some popular options.

Option 1: Running on AWS Elastic Container Service (ECS)

AWS ECS is a fully managed container orchestration service that supports Docker. You can use ECS to deploy your React application in a production environment with auto-scaling, load balancing, and security features.

Here are the basic steps to deploy a Dockerized React app on AWS ECS:

Push the Docker image to Amazon ECR (Elastic Container Registry).

Create an ECS cluster and configure a service to run the Docker container.

Set up an Application Load Balancer (ALB) to route traffic to the ECS service.

Configure auto-scaling to handle traffic spikes.

For more details on deploying Dockerized applications to ECS, you can follow this guide: Deploying Docker on ECS.

Option 2: Running on Google Kubernetes Engine (GKE)

Google Kubernetes Engine (GKE) is another popular platform for running Dockerized applications. GKE provides a fully managed Kubernetes environment to deploy, scale, and manage containerized applications.

To deploy a Dockerized React app on GKE, follow these steps:

Build and push the Docker image to Google Container Registry (GCR).

Create a Kubernetes cluster on GKE.

Deploy the React app as a Kubernetes deployment and expose it using a service.

Set up ingress to handle HTTP requests and route traffic to your application.

For more information on deploying Dockerized apps on GKE, check out this guide: Deploying Docker on GKE.

Option 3: Running on DigitalOcean’s App Platform

DigitalOcean’s App Platform is a platform-as-a-service (PaaS) that allows you to deploy containerized applications with minimal configuration. The App Platform automatically builds and deploys your Dockerized application and handles scaling, load balancing, and updates.

To deploy your Dockerized React app on DigitalOcean’s App Platform:

Push your code to a GitHub repository.

Create a new app on DigitalOcean’s App Platform.

Link your GitHub repository, and the App Platform will automatically detect your Dockerfile and build the Docker image.

Deploy the app, and DigitalOcean will handle scaling and updates.

For more details on deploying Dockerized applications on DigitalOcean, see their official guide: Deploying Docker on DigitalOcean.

Step 11: Best Practices for Dockerizing React Applications

As you build and deploy Dockerized React applications, there are several best practices to keep in mind to ensure that your Docker setup is reliable, secure, and performant.

  1. Use Multi-Stage Builds

As discussed earlier, multi-stage builds allow you to create smaller and more efficient Docker images by separating the build process from the final runtime environment. This reduces the size of the final image and eliminates unnecessary dependencies.

  1. Keep Your Dockerfile Simple

A clean and simple Dockerfile is easier to maintain and troubleshoot. Avoid adding unnecessary layers, and group related commands into fewer layers to improve performance. For example, you can combine multiple RUN commands into a single command to reduce the number of image layers.

  1. Cache Dependencies

Use Docker’s caching mechanisms to speed up builds. For example, by copying package.json before the rest of the code, Docker can cache the npm install step, so it doesn’t need to reinstall dependencies every time the code changes.

  1. Optimize for Production

Ensure that your Dockerfile is optimized for production by:

Using a minimal base image (such as nginx:alpine).

Serving static files with a web server like Nginx.

Removing development tools and dependencies from the final production image.

Ensuring that environment variables are properly managed.

  1. Use Docker Compose for Development

Docker Compose simplifies the process of running multi-container applications during development. By defining your services in a docker-compose.yml file, you can easily spin up your entire development environment with a single command. Docker Compose also allows you to manage environment variables and dependencies between services.

  1. Monitor and Secure Your Containers

When running Docker containers in production, it’s important to monitor their performance and ensure that they are secure. Some best practices include:

Using a tool like Prometheus or Grafana to monitor container metrics.

Scanning your Docker images for vulnerabilities using tools like Docker Scout or Trivy.

Ensuring that your Docker containers run with the least privilege necessary (using non-root users).

  1. Regularly Update Docker Images

Make sure to regularly update your Docker images to include the latest security patches and performance improvements. Outdated base images can introduce security vulnerabilities, so it’s important to keep them up to date.

Conclusion

Dockerizing React applications provides numerous benefits, including consistent development environments, simplified deployment pipelines, and easier scalability. In this guide, we’ve covered the essential steps to Dockerize a React application, from building a simple Docker image to deploying it on production platforms like AWS ECS, GKE, and DigitalOcean.

By following the best practices outlined in this guide, you can ensure that your Dockerized React applications are optimized for performance, security, and maintainability.

With Docker, you can take full advantage of containerization to streamline your development and deployment workflows, making your React applications more portable and reliable in various environments.

版本声明 本文转载于:https://dev.to/nilebits/mastering-docker-for-react-applications-j3d?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • Java字符串非空且非null的有效检查方法
    Java字符串非空且非null的有效检查方法
    检查字符串是否不是null而不是空的 if(str!= null && str.isementy())二手: if(str!= null && str.length()== 0) option 3:trim()。isement(Isement() trim whitespace whitesp...
    编程 发布于2025-05-15
  • 如何在Java字符串中有效替换多个子字符串?
    如何在Java字符串中有效替换多个子字符串?
    在java 中有效地替换多个substring,需要在需要替换一个字符串中的多个substring的情况下,很容易求助于重复应用字符串的刺激力量。 However, this can be inefficient for large strings or when working with nu...
    编程 发布于2025-05-15
  • PHP阵列键值异常:了解07和08的好奇情况
    PHP阵列键值异常:了解07和08的好奇情况
    PHP数组键值问题,使用07&08 在给定数月的数组中,键值07和08呈现令人困惑的行为时,就会出现一个不寻常的问题。运行print_r($月份)返回意外结果:键“ 07”丢失,而键“ 08”分配给了9月的值。此问题源于PHP对领先零的解释。当一个数字带有0(例如07或08)的前缀时,PHP将...
    编程 发布于2025-05-15
  • Java中假唤醒真的会发生吗?
    Java中假唤醒真的会发生吗?
    在Java中的浪费唤醒:真实性或神话?在Java同步中伪装唤醒的概念已经是讨论的主题。尽管存在这种行为的潜力,但问题仍然存在:它们实际上是在实践中发生的吗? Linux的唤醒机制根据Wikipedia关于伪造唤醒的文章,linux实现了pthread_cond_wait()功能的Linux实现,利用...
    编程 发布于2025-05-15
  • 用户本地时间格式及时区偏移显示指南
    用户本地时间格式及时区偏移显示指南
    在用户的语言环境格式中显示日期/时间,并使用时间偏移在向最终用户展示日期和时间时,以其localzone and格式显示它们至关重要。这确保了不同地理位置的清晰度和无缝用户体验。以下是使用JavaScript实现此目的的方法。方法:推荐方法是处理客户端的Javascript中的日期/时间格式化和时...
    编程 发布于2025-05-15
  • 如何使用组在MySQL中旋转数据?
    如何使用组在MySQL中旋转数据?
    在关系数据库中使用mySQL组使用mySQL组进行查询结果,在关系数据库中使用MySQL组,转移数据的数据是指重新排列的行和列的重排以增强数据可视化。在这里,我们面对一个共同的挑战:使用组的组将数据从基于行的基于列的转换为基于列。 Let's consider the following ...
    编程 发布于2025-05-15
  • Java为何无法创建泛型数组?
    Java为何无法创建泛型数组?
    通用阵列创建错误 arrayList [2]; JAVA报告了“通用数组创建”错误。为什么不允许这样做?答案:Create an Auxiliary Class:public static ArrayList<myObject>[] a = new ArrayList<myO...
    编程 发布于2025-05-15
  • 解决Spring Security 4.1及以上版本CORS问题指南
    解决Spring Security 4.1及以上版本CORS问题指南
    弹簧安全性cors filter:故障排除常见问题 在将Spring Security集成到现有项目中时,您可能会遇到与CORS相关的错误,如果像“访问Control-allo-allow-Origin”之类的标头,则无法设置在响应中。为了解决此问题,您可以实现自定义过滤器,例如代码段中的MyFi...
    编程 发布于2025-05-15
  • C++中如何将独占指针作为函数或构造函数参数传递?
    C++中如何将独占指针作为函数或构造函数参数传递?
    在构造函数和函数中将唯一的指数管理为参数 unique pointers( unique_ptr [2启示。通过值: base(std :: simelor_ptr n) :next(std :: move(n)){} 此方法将唯一指针的所有权转移到函数/对象。指针的内容被移至功能中,在操作...
    编程 发布于2025-05-15
  • 哪种在JavaScript中声明多个变量的方法更可维护?
    哪种在JavaScript中声明多个变量的方法更可维护?
    在JavaScript中声明多个变量:探索两个方法在JavaScript中,开发人员经常遇到需要声明多个变量的需要。对此的两种常见方法是:在单独的行上声明每个变量: 当涉及性能时,这两种方法本质上都是等效的。但是,可维护性可能会有所不同。 第一个方法被认为更易于维护。每个声明都是其自己的语句,使其...
    编程 发布于2025-05-15
  • 如何在Java中正确显示“ DD/MM/YYYY HH:MM:SS.SS”格式的当前日期和时间?
    如何在Java中正确显示“ DD/MM/YYYY HH:MM:SS.SS”格式的当前日期和时间?
    如何在“ dd/mm/yyyy hh:mm:mm:ss.ss”格式“ gormat 解决方案:的,请访问量很大,并应为procectiquiestate的,并在整个代码上正确格式不多: java.text.simpledateformat; 导入java.util.calendar; 导入java...
    编程 发布于2025-05-15
  • 在PHP中如何高效检测空数组?
    在PHP中如何高效检测空数组?
    在PHP 中检查一个空数组可以通过各种方法在PHP中确定一个空数组。如果需要验证任何数组元素的存在,则PHP的松散键入允许对数组本身进行直接评估:一种更严格的方法涉及使用count()函数: if(count(count($ playerList)=== 0){ //列表为空。 } 对...
    编程 发布于2025-05-15
  • 将图片浮动到底部右侧并环绕文字的技巧
    将图片浮动到底部右侧并环绕文字的技巧
    在Web设计中围绕在Web设计中,有时可以将图像浮动到页面右下角,从而使文本围绕它缠绕。这可以在有效地展示图像的同时创建一个吸引人的视觉效果。 css位置在右下角,使用css float and clear properties: img { 浮点:对; ...
    编程 发布于2025-05-15
  • 如何简化PHP中的JSON解析以获取多维阵列?
    如何简化PHP中的JSON解析以获取多维阵列?
    php 试图在PHP中解析JSON数据的JSON可能具有挑战性,尤其是在处理多维数组时。 To simplify the process, it's recommended to parse the JSON as an array rather than an object.To do...
    编程 发布于2025-05-15

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3